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


当前回答

使用Tcl,你有一个简单的文本编辑器,其中有一个保存按钮,大约12行代码(但没有打开,那将需要另外8行代码)。它适用于所有标准平台:

pack [frame .toolbar] -side top -fill x
pack [button .save -text save -command save] -in .toolbar -side left
pack [scrollbar .vsb -orient vertical -command [list .text yview]] -side right -fill y
pack [text .text -wrap word -yscrollcommand [list .vsb set]] -side left -fill both -expand true
proc save {} {
    set filename [tk_getSaveFile]
    if {$filename ne ""} {
        set f [open $filename w]
        puts $f [.text get 1.0 end-1c]
        close $f
    }
}

我知道我们的目标是10行,所以如果你想要的是10行或更少,一个简单的文本编辑器没有加载或保存只有两行。这还不算太寒酸。

pack [scrollbar .vsb -orient vertical -command [list .text yview]] -side left -fill y
pack [text .text -wrap word -yscrollcommand [list .vsb set]] -side left -fill both -expand true

在您选择的平台上执行带有“wish文件名”的上述代码块中的任何一个。Wish安装在大多数*nix和mac上,但你必须手动安装windows。

更进一步,两行脚本也可以用python编写,尽管需要8行,但仍然低于10行的目标:

from Tkinter import *
root=Tk()
text = Text(wrap="word")
sb = Scrollbar(orient="vertical", command=text.yview)
text.configure(yscrollcommand=sb.set)
sb.pack(side="right", fill="y")
text.pack(side="left", fill="both", expand=True)
root.mainloop()

其他回答

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

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

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

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

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

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

好运!

摆弄饼干。

它的饼干!孩子们非常喜欢饼干!

找一个依赖cookie的网站。 使用firefox插件编辑cookie。 ???? 学习! !

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

这是迄今为止我见过的最酷的东西……如果分解一下,其实很简单:

http://blogs.msdn.com/lukeh/archive/2007/04/03/a-ray-tracer-in-c-3-0.aspx

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

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

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