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


当前回答

有点离题了,但你可以看看这个推文编码,它使用了不到140个字符的as3代码:

http://gskinner.com/playpen/tweetcoding_0/

^_^

其他回答

我认为油脂猴子是学生开始学习的好地方。在userscripts.org上有成千上万的示例脚本,是非常好的阅读材料,其中一些非常小。Greasemonkey脚本会影响网页,而学生们即使不会操纵网页,也会对这些网页很熟悉。Greasemonkey本身提供了一种非常简单的方法来在测试时编辑和启用/禁用脚本。

例如,下面是"谷歌Two Columns"脚本:

result2 = '<table width="100%" align="center" cellpadding="10" style="font-size:12px">';
gEntry = document.evaluate("//li[@class='g'] | //div[@class='g'] | //li[@class='g w0'] | //li[@class='g s w0']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (var i = 0; i < gEntry.snapshotLength; i++) {
  if (i==0) { var sDiv = gEntry.snapshotItem(i).parentNode.parentNode; }
  if(i%2 == 0) { result2 += '<tr><td width="50%" valign="top">'+gEntry.snapshotItem(i).innerHTML+'</td>'; }
  if(i%2 == 1) { result2 += '<td width="50%" valign="top">'+gEntry.snapshotItem(i).innerHTML+'</td></tr>'; }
}
sDiv.innerHTML = result2+'</table>';

if (document.getElementById('mbEnd') !== null) { document.getElementById('mbEnd').style.display = 'none'; }

我没有这方面的代码,但是它可以在10行或更少的时间内被抽象出来。使鼠标画一个方框。不管你怎么移动它。当你点击(左)框消失,当你点击(右)框改变颜色。

学生们想要一些实用的东西,一些他们可以修改和定制的东西,一些表明这“不是典型的无聊课程”的东西。

Xen的mini-os内核现在可以做到这一点,但它需要额外的抽象来满足您的需求。

您还可以尝试绘制一个manderbolt (julia)集,同时从环境噪声获得二次平面的参数(如果机器有麦克风和声卡)..他们的声音会产生分形。同样,要在10行(在他们编辑的实际函数中)完成这一点很棘手,但并非不可能。

在现实世界中,您将使用现有的库。所以我认为,在main()(或任何你使用的语言)中使用10行代码更实用。我们让存在的东西为我们工作,而写不存在或不为我们工作的东西。你不妨一开始就介绍这个概念。

同时,行吗?Int main(void){无符号Int i;(我= 0;I < 10;我+ +);返回0;也许,10次函数调用将是一个更现实的目标?这不是一场模糊的代码竞赛。

好运!

处理总是很有趣的,它创造的东西对所有类型的人都印象深刻。例如,布朗树:

int xf = (int) random(width);
int yf = (int) random(height);
int x = (int) random(width);
int y = (int) random(height);

background(0xFF);
while(x != xf || y != yf) {
  set(x,y,color(0,0,0));
  x = max(0, min(x + -1 + (int) random(3), width - 1) );
  y = max(0, min(y + -1 + (int) random(3), height - 1) );
}

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

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

Public Sub Main()   
    Clipboard.SetText Command$   
End Sub  

这是我的10线蜘蛛。从技术上讲,它是11,包括perl shell声明,但我希望这是可以原谅的!

我想让它识别某些文件类型和支持相对路径,但跑出了行!

运行:

perl spider.pl http://yahoo.com/search?q=test

请注意,谷歌不允许没有用户代理的LWP Simple,因此搜索谷歌将不起作用。也容不下那个!总之,代码在哪里:

#!/usr/bin/perl -w
use LWP::Simple;
my @queue = ($ARGV[0]);
my %visited = ();
while (my $url = pop(@queue)) {
    next if $visited{$url};
    $visited{$url} = 1;
    my $html = get($url) or next;
    print "Spidering $url\n";
    push(@queue, $html =~ m/(http:\/\/[^'"]*)/g);
}