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


当前回答

大多数答案都使用某种API,这在某种程度上打破了10行代码的要求。每个API调用可能包含数百行代码。最初的问题说要使用“简单代码”。这对我来说意味着没有API调用。仅仅使用“简单代码”的定义,我们能得出什么样的答案呢?

其他回答

试着让你的学生编一个神奇的8号球。一个基本的回答“是”或“否”的8球程序可能只需要不到10行代码,并且它可以以任何方式递增:

First, make it simple: input something like "s" for shake into a CLI; 8ball answers "yes" or "no" Next, input a question, display the question along with the answer Then expand the possible answers.... Loads of options, the students who are quick to catch on can have some fun ("Look, the computer says dirty words!!"), while you help the others Implement a timer, so you can't ask the same question again right away, in case you don't like the answer Group possible answers into variants of "yes", "no" and "hazy" or something; first RNG decides type of answer, second RNG decides the specific answer Reconfigure the timer; you can ask again right away if the answer is hazy Make a frame of *'s around the text And so on....

一个神奇的8球是大多数人都能联系到的东西,它只使用最简单的工具介绍了基本的字符串,浮点数/整数,IO, CLI,布尔和RNG。它很简单,(有点)有趣,而且很容易扩展。根据您的方法,您可以使用类8ball()、类YesAnswer()等立即使编程面向对象。

祝你好运;-)

我发现最喜欢的(在GWBASIC中)是:

10 input "What is your name ";N$
20 i = int(rnd * 2)
30 if i = 0 print "Hello ";N$;". You are a <fill in insult number 1>"
40 if i = 1 print "Hello ";N$;". You are a <fill in insult number 2>"

我发现初学的学生有一些观念需要修正。

电脑不会读心术。 计算机一次只做一件事,即使它们做得如此之快,它们似乎一次就做完了。 计算机只是愚蠢的机器,只会做被告知的事情。 计算机只能识别特定的东西,而这些东西就像积木一样。 一个关键的概念是,变量是包含一个值的东西,它的名称与该值不同。 你编辑程序的时间和它运行的时间之间的区别。

祝你在课堂上好运。我相信你会做得很好的。

附言:我相信你明白,除了材料和技能,你还在教授一种态度,这也是同样重要的。

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

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) );
}

你可能会考虑像Robocode这样的东西,其中大量的代码被抽象出来,你基本上只是告诉机器人做什么。一个简单的10行函数可以让机器人做很多事情,并且有一个非常直观和易于遵循的结果。

也许Robocode本身并不适合这项任务,但这种东西是一种将编写的代码与计算机上的可视操作联系起来的好方法,而且当你需要给出示例时,它很有趣。

public class MyFirstJuniorRobot extends JuniorRobot {
 public void run() {
  setColors(green, black, blue);
  // Seesaw forever
  while (true) {
   ahead(100); // Move ahead 100
   turnGunRight(360); // Spin gun around
   back(100); // Move back 100
   turnGunRight(360); // Spin gun around
  }
 }
 public void onScannedRobot() {
  turnGunTo(scannedAngle);
  fire(1);
 }
 public void onHitByBullet() {
  turnAheadLeft(100, 90 - hitByBulletBearing);
 }
}

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

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

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