我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用Haskell用15行写一个Mandelbrot集,但是很难理解。

我的目标是启发学生编程很酷。

我们知道编程很酷,因为你可以创造任何你想象到的东西——它是最终的创意出口。我想激励这些初学者,让他们尽可能多地克服早期学习的困难。

Now, my reasons are selfish. I'm teaching an Intro to Computing course to a group of 60 half-engineering, half business majors; all freshmen. They are the students who came from underprivileged High schools. From my past experience, the group is generally split as follows: a few rock-stars, some who try very hard and kind of get it, the few who try very hard and barely get it, and the few who don't care. I want to reach as many of these groups as effectively as I can. Here's an example of how I'd use a computer program to teach:

Here's an example of what I'm looking for: a 1-line VBS script to get your computer to talk to you: CreateObject("sapi.spvoice").Speak InputBox("Enter your text","Talk it") I could use this to demonstrate order of operations. I'd show the code, let them play with it, then explain that There's a lot going on in that line, but the computer can make sense of it, because it knows the rules. Then I'd show them something like this: 4(5*5) / 10 + 9(.25 + .75) And you can see that first I need to do is (5*5). Then I can multiply for 4. And now I've created the Object. Dividing by 10 is the same as calling Speak - I can't Speak before I have an object, and I can't divide before I have 100. Then on the other side I first create an InputBox with some instructions for how to display it. When I hit enter on the input box it evaluates or "returns" whatever I entered. (Hint: 'oooooo' makes a funny sound) So when I say Speak, the right side is what to Speak. And I get that from the InputBox. So when you do several things on a line, like: x = 14 + y; You need to be aware of the order of things. First we add 14 and y. Then we put the result (what it evaluates to, or returns) into x.

这就是我的目标,有一堆很酷的例子来演示,并在他们玩得开心的时候教他们。我在我室友身上尝试了这个例子,虽然我可能不会把它作为第一课,但她喜欢它,并学到了一些东西。

一些很酷的数学程序,可以做出漂亮的图形或容易理解的形状,这是很好的想法,我将研究这些。这里有一些复杂的actionscript示例,但这有点太高级了,我不能教flash。你还有什么其他的想法吗?


当前回答

It has been fun reading the answers to this question. Once you've achieved the 'wow' factor from the students, illustrate the daisy-chaining affect of the results of one becoming the input of another. Learning how input and output works will illustrate the idea of building blocks and how software grows from lots of little things solving specific problems to larger applications solving bigger problems. If a few 10 line programs can be cool, how cool would it be to then put a bunch of them together? That is non-linear cool.

其他回答

It has been fun reading the answers to this question. Once you've achieved the 'wow' factor from the students, illustrate the daisy-chaining affect of the results of one becoming the input of another. Learning how input and output works will illustrate the idea of building blocks and how software grows from lots of little things solving specific problems to larger applications solving bigger problems. If a few 10 line programs can be cool, how cool would it be to then put a bunch of them together? That is non-linear cool.

在您的地址栏(在您的浏览器中)输入此代码并按Enter。然后你就可以编辑网页的所有内容了!

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

这是我知道的最酷的“一句俏皮话”=)

当史蒂夫·沃兹尼亚克(Steve Wozniak)制作第一台Apple II时,他喜欢用Apple Basic来展示一款Breakout游戏,他当场就输入了这个游戏。我想大概有10行;我希望我能把它粘贴在这里。你也可以在Processing这样的系统中这样做。

所以有一天,我觉得我受够了。我要学钢琴。看到像埃尔顿·约翰这样精通键盘的人,我确信这就是我想做的。

事实上,学钢琴是非常令人失望的。即使在完成了八年级的钢琴课程后,我仍然没有印象到,我弹钢琴的心理形象与我最初享受这项活动的想象有多么不同。

然而,我最喜欢的是我仅有的三年级音乐理论基础。我学到了音乐的构造。我终于能够从表演书面音乐的世界中走出来,开始创作自己的音乐。随后,我可以开始玩我想玩的东西了。


不要试图让新程序员眼花缭乱,尤其是年轻程序员。“少于十行简单代码”的整个概念似乎引起了一种“给我展示一些聪明的东西”的情绪。

你可以向新程序员展示一些聪明的东西。然后你可以教这个程序员如何复制这种“性能”。但这并不是他们迷上编程的原因。教他们一些基础知识,让他们自己合成十行聪明的代码。

我会向一个新程序员展示以下Python代码:

input = open("input.txt", "r")
output = open("output.txt", "w")

for line in input:
    edited_line = line
    edited_line = edited_line.replace("EDTA", "ethylenediaminetetraacetic acid")
    edited_line = edited_line.replace("ATP", "adenosine triphosphate")
    output.write(edited_line)

我意识到我不需要将line赋值给edited_line。然而,这只是为了让事情更清楚,并表明我没有编辑原始文档。

在不到十行里,我已经详尽地描述了一份文件。当然,还要确保向新程序员显示所有可用的字符串方法。更重要的是,我展示了我可以做的三件基本有趣的事情:变量赋值、循环、文件IO和使用标准库。

我想您会同意这段代码并不令人眼花缭乱。事实上,这有点无聊。不,实际上,很无聊。但是将代码展示给一个新的程序员,看看这个程序员是否能够在一周内(如果不是当天的话)将脚本的每个部分重新用于更有趣的内容。当然,您可能不喜欢(可能使用这个脚本来创建一个简单的HTML解析器),但其他一切都需要时间和经验。

试着让你的学生编一个神奇的8号球。一个基本的回答“是”或“否”的8球程序可能只需要不到10行代码,并且它可以以任何方式递增:

First, make it simple: input something like "s" for shake into a CLI; 8ball answers "yes" or "no" Next, input a question, display the question along with the answer Then expand the possible answers.... Loads of options, the students who are quick to catch on can have some fun ("Look, the computer says dirty words!!"), while you help the others Implement a timer, so you can't ask the same question again right away, in case you don't like the answer Group possible answers into variants of "yes", "no" and "hazy" or something; first RNG decides type of answer, second RNG decides the specific answer Reconfigure the timer; you can ask again right away if the answer is hazy Make a frame of *'s around the text And so on....

一个神奇的8球是大多数人都能联系到的东西,它只使用最简单的工具介绍了基本的字符串,浮点数/整数,IO, CLI,布尔和RNG。它很简单,(有点)有趣,而且很容易扩展。根据您的方法,您可以使用类8ball()、类YesAnswer()等立即使编程面向对象。

祝你好运;-)