我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用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。你还有什么其他的想法吗?


当前回答

JavaScript的处理呢?我不知道如何处理,但是代码对于它能做的事情来说总是显得相当小,它是非常可视化的,你可以在浏览器中运行它。 http://processingjs.org/exhibition

其他回答

我认为现在做计算机教育者很难。我是。我们面临着一场日益严峻的艰苦战斗。我们的学生是非常成熟的用户,要给他们留下深刻印象需要付出很多努力。他们有这么多工具,可以做惊人的事情。

用10行代码写一个简单的计算器?为什么?我有一张TI-86。

一个脚本,应用特殊效果的图像?这就是Photoshop的作用。Photoshop可以让你在10行里做的任何事情都相形见绌。

把一张CD光盘转换成MP3怎么样?我已经从bt下载了5万首歌了。它们已经是MP3格式了。我在iPhone上玩。谁会买cd呢?

为了向精明的用户介绍编程,你必须找到以下内容:

A)适用于他们觉得有趣和酷的东西,还有 B)做一些他们已经不能做的事情。

假设你的学生已经可以使用最昂贵的软件。他们中的许多人确实有完整版的Adobe CS5.5(零售价:2,600美元;实际价格:免费),可以轻松获得任何通常会打破你的部门预算的应用程序。

但他们中的绝大多数人都不知道这些“电脑东西”究竟是如何工作的。

他们是一群极具创造力的人:他们喜欢创造东西。他们只是想做一些朋友做不到的事情。他们想要一些可以炫耀的东西。

以下是我发现的一些与我的学生产生共鸣的事情:

HTML and CSS. From those they learn how MySpace themes work and can customize them. Mashups. They've all seen them, but don't know how to create them. Check out Yahoo! Pipes. There are lots of teachable moments, such as RSS, XML, text filtering, mapping, and visualization. The completed mashup widgets can be embedded in web pages. Artwork. Look at Context-Free Art. Recursion and randomization are key to making beautiful pictures. Storytelling. With an easy-to-use 3D programming environment like Alice, it's easy to create high-quality, engaging stories using nothing more than drag-and-drop.

这些都不涉及传统意义上的编程。但他们确实利用了强大的库。我认为它们是一种不同的编程。

斐波那契数列是学习递归的一个很酷的例子。 它表明递归写起来很简单,但执行起来代价很高。 负分项的情况可以在后面介绍。

int fiboNumber(int index)
{
  if (index <= 1)
  {
    return index;
  }
  return fiboNumber(index - 1) + fiboNumber(index - 2);
}
10 PRINT "HELLO"
20 GOTO 10

但那时我还只是个孩子。这也是为什么它是最酷的事情。我不认为你能从第一次编写计算机程序中获得同样的快感。即使只是简单地向控制台无限地输出“HELLO”。

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

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

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


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

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

我会向一个新程序员展示以下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解析器),但其他一切都需要时间和经验。

下面是一个用a - prolog语言编写的程序,它可以计算图的N种颜色(“c”表示颜色,“v”表示顶点,“e”表示边)。

c(1..n).                                           
1 {color(X,I) : c(I)} 1 :- v(X).             
:- color(X,I), color(Y,I), e(X,Y), c(I).

On a side note, the way I got my students excited last semester was to tell them a story. It went something along the lines of: "Picture a triangle. It's a purely mathematical object, no real triangles exists. We can reason about them, discover their properties, and then apply those properties towards real world solutions. An algorithm is also a purely mathematical object. Programming is a form of magic however. We can take a mathematical object, describe it a language, and lo and behold it can manipulate the physical world. Programming is a unique discipline that bridges these two worlds."