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


当前回答

你可以让你的学生去codeplex IronPython silverlight示例站点,其中包括一个< 10行的修改画布和与鼠标交互的演示。你可以在这里找到silverlight的例子

仅仅看到在web浏览器中编写的代码,然后执行修改一个小的WPF可能会让一些人陶醉。

其他回答

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

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

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


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

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

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

您可以使用用AutoIt编写的脚本,它模糊了使用传统应用程序和编程之间的界限。

例如,一个脚本,打开记事本,让他们自己的电脑侮辱他们,并通过一个消息框,然后不留任何痕迹的行动:

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("You smell of human.")
Sleep(10000)
MsgBox(0, "Humans smell bad", "Yuck!")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!n")

如何展示你可以在任何网页浏览器中输入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)

这是一个非常基本的基于文本的c#程序,模拟老虎机的旋转动作。它不包括不同的中奖几率或现金奖励,但这对学生来说是一个很好的练习。

抱歉,超过10行。

string[] symbols = new[] { "#", "?", "~" }; // The symbols on the reel
Random rand = new Random();

do
{
    string a="",b="",c="";

    for( int i = 0; i < 20; i++ )
    {
        Thread.Sleep( 50 + 25 * i ); // slow down more the longer the loop runs

        if( i < 10 )
            a = symbols[rand.Next( 0, symbols.Length )];

        if( i < 15 )
            b = symbols[rand.Next( 0, symbols.Length )];

        c = symbols[rand.Next( 0, symbols.Length )];

        Console.Clear();
        Console.WriteLine( "Spin: " + a + b + c );
    }

    if( a == b && b == c )
        Console.WriteLine( "You win. Press enter to play again or type \"exit\" to exit" );
    else
        Console.WriteLine( "You lose. Press enter to play again or type \"exit\" to exit" );
}
while( Console.ReadLine() != "exit" );

小书签怎么样?它将向他们展示如何操作他们每天使用的东西(互联网),而不需要任何开发工具。