我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用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行来解决,因为它很可能是一个简单的问题。然后告诉他们,花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)
}

其他回答

我记得我发现简单的循环很神奇。每次我学习一门新语言,我通常会把这样的东西放在一起:

<?php
$numberOfBottles = 99;
print("<h1>$numberOfBottles Bottles of Beer on the Wall</h1>");
print("$numberOfBottles bottles of beer on the wall,<br />");
print("$numberOfBottles bottles of beer!<br />");
print("Take one down, pass it around,<br />");
for($numberOfBottles--; $numberOfBottles>1; $numberOfBottles--)
{
    print("$numberOfBottles bottles of beer on the wall!<br />");
    print("<br />");
    print("$numberOfBottles  bottles of beer on the wall,<br />");
    print("$numberOfBottles  bottles of beer!<br />");
    print("Take one down, pass it around,<br />");
}
print("One last bottle of beer on the wall!");
?>

也许一些while或foreach循环的变化也会很容易。

微软有Small Basic,一个为“孩子”设计的IDE。

pic = Flickr.GetRandomPicture("beach")
Desktop.SetWallpaper(pic)

它是专门用来展示编程有多酷的。

在WPF中,你可以用几行XAML代码写一个功能完整的缩略图视图:

<ListBox ItemsSource={Binding MyItems}
         ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Image Source={Binding FullPath} Width="50" />
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

这里假设您有一个MyItems集合,其中包含指向图像文件的FullPath属性。

魔术来自ItemTemplate,它将每个列表框项转换为图像,ItemsPanelTemplate将默认的垂直堆栈面板更改为换行面板。

我记得当我第一次开始编码循环总是让我印象深刻。您编写5 - 10行代码(或更少),然后打印出数百行(或无论您指定多少行)。(我首先学的是PHP和Java)。

for( int i = 0; i < 200; i++ )
{
   System.out.println( i );
}

我敢肯定它会变成超过10行代码,但你有没有考虑过一个基于表单的应用程序,按下按钮就可以改变背景的颜色或改变文本的大小?这将向他们展示交互程序是如何工作的。这也会告诉他们,作为程序员,他们可以完全控制计算机(程序)所做的事情。

希望这会引导他们对其他可以改变的事情提出建议,然后对其他他们可能想做的事情提出建议。