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


当前回答

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

int fiboNumber(int index)
{
  if (index <= 1)
  {
    return index;
  }
  return fiboNumber(index - 1) + fiboNumber(index - 2);
}

其他回答

不管你有什么想法,作为补充,我说你应该告诉他们如何做一些基本的数学。将其呈现为

现在你可能认为这很简单或者 复杂……但你有没有去过 被数学作业困住了?”

然后从别人的书中拿出一个例子。大多数数学问题可以用10行来解决,因为它很可能是一个简单的问题。然后告诉他们,花10分钟来解决这个问题,可能会让他们得到一个A。这段时间很长,但你可能会遇到一些想花很少或根本不花时间做作业的人。

这主要是因为我希望我在化学时就能想到写一个软件程序……所有的测验和作业都是100分…

编辑: 回应Peter的评论:

比如3a2的导数是什么。所以你可以只显示一个简单的函数,他们可以从命令行调用:

public int SimpleDerivative(int r, int exponent){
    r = r * exponent
    exponent =- 1
    return (String "{0}a^{1}" where {0} = r, {1} = exponent)
}

如何展示你可以在任何网页浏览器中输入JavaScript到地址栏,然后让代码执行?

编辑:去一个有很多图片的页面,在地址栏试试这个:

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++ }setInterval('A()',5); void(0)

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

用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.

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

如果你教的是工程师,这段Prolog可能会引起他们的注意:

d(x,x,1).
d(C,x,0):-number(C).
d(C*x,x,C):-number(C).
d(-U, X, -DU) :- d(U, X, DU).
d( U + V, x, RU + RV ):-d(U,x,RU), d(V,x,RV).
d( U - V, x, RU - RV ):-d(U,x,RU), d(V,x,RV).
d(U * V,x, U * DV + V * DU):- d(U,x,DU), d(V,x,DV).
d(U^N, x, N*U^(N-1)*DU) :- integer(N), d(U, x, DU).

只要写下规则,你就有了一个程序,可以用8行代码完成第一学期的所有微积分。

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

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

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