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


当前回答

就像……

10 rem twelve times table

20 For x = 1 to 12

30  For y = 1 to 12

40     print using"####";x*y;

50  next y

60  print 

70 next x

80 end

其他回答

我认为任何可以做一些有用的事情的shell脚本都是向人们展示编程力量的好方法。在我看来,能够在一个小脚本上花费10-20分钟来自动化另一项任务并节省无数小时是非常令人印象深刻的。

例如,我曾经写过一个简单的Perl脚本,将一个目录中的mp3文件转换为另一种格式,然后将它们刻录到cd上。你用mp3目录的路径调用这个脚本,它就刻录了cd。至少当时我印象深刻。

我给有学习障碍的11-12岁学生上过课。我们使用Hypercard,他们发现他们可以记录物体(图像,盒子等)的位置,因为他们移动它,并播放它(动画)。虽然这不是编码,但他们想做的是:删除其中一个动作,而不重新记录它。我告诉他们,他们必须去查看代码并修改它。

你可以看出谁有计算机/编程的诀窍,当他们更喜欢用代码来做的时候,因为他们有更多的控制权。

在Excel中做一个复杂的宏,然后学习代码在做什么,这可能是通往VBA的门户。

根据年龄群体或兴趣水平的不同,直接进入代码可能很难,但最终是重要的。

我被演讲《Easy AI with Python》(视频和PDF)中展示的一些东西所震撼。例如,教计算机如何玩“Mastermind”游戏,解决八个皇后,字母(那些像“9567 + 1085 == 10652”这样的谜题,以及推断数据中的关系。所有代码都在10行以内(可能包含20或30行“幕后”代码)。

我最近在一篇文章“我写过的最短、最有用的程序”中提到了这一点。

总结:我在1996年写了一个3行VB6应用程序,现在我每天都在使用。一旦exe被放入“发送到”文件夹。它可以让你在资源管理器中右键单击一个文件,并将该文件的完整路径发送到剪贴板。

Public Sub Main()   
    Clipboard.SetText Command$   
End Sub  
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Sub JohnDenverAnniesSong(): Const E4# = 329.6276: Dim Note&, Frequencies$, Durations$: Frequencies = "iiihfihfffhidadddfhihfffhihiiihfihffihfdadddfhihffhiki": Durations = "aabbbfjaabbbbnaabbbfjaabcapaabbbfjaabbbbnaabbbfjaabcap": For Note = 1 To Len(Frequencies): Beep CLng(E4 * 2 ^ ((AscW(Mid$(Frequencies, Note, 1)) - 96) / 12)), CLng((Asc(Mid$(Durations, Note, 1)) - 96) * 200 - 10): Sleep 10: DoEvents: Next: End Sub

转储到Excel中运行:D