I'm looking for the coolest thing you can do in a few lines of simple code. I'm sure you can write a Mandelbrot set in Haskell in 15 lines but it's difficult to follow.
我在寻找你能用几行简单代码做的最酷的事情。我相信你可以在Haskell中写一个15行的曼德尔布罗特,但它很难遵循。
My goal is to inspire students that programming is cool.
我的目标是启发学生们编程是很酷的。
We know that programming is cool because you can create anything you imagine - it's the ultimate creative outlet. I want to inspire these beginners and get them over as many early-learning humps as I can.
我们知道编程很酷,因为你可以创造出任何你想要的东西——它是终极的创意输出。我想激励这些初学者,让他们尽可能多地在早期学习。
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:
现在,我的理由是自私的。我正在给一个60个半工程专业的学生讲授计算课程的入门课程;所有的大一新生。他们是来自贫困的高中的学生。从我过去的经验来看,这群人大致上是这样划分的:一些摇滚明星,一些非常努力的人,有些人很努力,很少有人尝试,很少有人不关心。我希望尽可能多地接触到这些团体。下面是一个我如何使用计算机程序来教学的例子:
Here's an example of what I'm looking for: a 1-line VBS script to get your computer to talk to you:
这里有一个我正在寻找的例子:1行VBS脚本,让你的电脑与你对话:
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.
你们可以看到,我首先要做的是(5*5)然后再乘以4。现在我创建了这个对象。除以10就等于说,在我有一个物体之前,我不能说,在我有100之前,我不能除以。然后在另一边,我首先创建一个InputBox,其中包含一些如何显示它的说明。当我点击进入输入框时,它会对输入的内容进行评估或“返回”。(提示:“oooooo”发出一种奇怪的声音)所以当我说“说话”时,右边是说话的地方。我从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.
你需要知道事物的顺序。首先我们添加14和y,然后将结果(它的计算值或返回值)放入x。
That's my goal, to have a bunch of these cool examples to demonstrate and teach the class while they have fun. I tried this example on my roommate and while I may not use this as the first lesson, she liked it and learned something.
这是我的目标,有一堆这些很酷的例子来展示和教授课堂,同时他们也很开心。我在我的室友身上试过这个例子,虽然我可能不把它当做第一课,但她喜欢它,并且学到了一些东西。
Some cool mathematica programs that make beautiful graphs or shapes that are easy to understand would be good ideas and I'm going to look into those. Here are some complicated actionscript examples but that's a bit too advanced and I can't teach flash. What other ideas do you have?
一些很酷的mathematica程序可以做出漂亮的图形或形状,很容易理解,这是很好的主意,我将深入研究这些。这里有一些复杂的actionscript例子,但是有点太高级了,我不能教flash。你还有其他的想法吗?
87 个解决方案
#1
78
I got a great response from my kids with a quick VB script to manipulate a Microsoft Agent character. For those that aren't familiar with MS Agent, it's a series of animated onscreen characters that can be manipulated via a COM interface. You can download the code and characters at the Microsoft Agent download page.
我的孩子们用一个快速的VB脚本来操作一个微软的代理程序,我得到了一个很好的回应。对于那些不熟悉MS代理的人来说,它是一系列可以通过COM接口进行操作的动画屏幕字符。您可以在Microsoft代理下载页面下载代码和字符。
The folllowing few lines will make the Merlin character appear on screen, fly around, knock on the screen to get your attention, and say hello.
下面几行文字将会让梅林角色出现在屏幕上,四处飞,敲击屏幕吸引你的注意,并向你问好。
agentName = "Merlin"
agentPath = "c:\windows\msagent\chars\" & agentName & ".acs"
Set agent = CreateObject("Agent.Control.2")
agent.Connected = TRUE
agent.Characters.Load agentName, agentPath
Set character = agent.Characters.Character(agentName)
character.Show
character.MoveTo 500, 400
character.Play "GetAttention"
character.Speak "Hello, how are you?"
Wscript.Sleep 15000
character.Stop
character.Play "Hide"
There are a great many other commands you can use. Check http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx for more information.
您可以使用许多其他命令。查看http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx获取更多信息。
EDIT 2011-09-02 I recently discovered that Microsoft Agent is not natively installed on Windows 7. However it is offered as a separate download here. I have not tested this so cannot verify whether it operates.
编辑2011-09-02我最近发现微软的代理并不是本地安装在Windows 7上的。不过,这里提供了一个单独的下载。我没有测试过,所以无法验证它是否运行。
#2
339
Enter this code in your address bar (in your browser) and press enter. Then you can edit all the content of the webpage!
在您的地址栏(在您的浏览器中)输入此代码并按Enter。然后你可以编辑网页的所有内容!
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
That is the coolest "one-liner" I know =)
这是我所知道的最酷的“一行”
#3
201
When I first wrote this.
当我第一次写这个的时候。
10 PRINT "What is your name?"
20 INPUT A$
30 PRINT "Hello " A$
40 GOTO 30
It blew people away! The computer remembered their name!
人们吹!电脑记住了他们的名字!
EDIT: Just to add to this. If you can convince a new programmer this is the coolest thing they can do, they will become the good programmers. These days, you can do almost anything you want with one line of code to run a library somebody else wrote. I personally get absolutely no satisfaction from doing that and see little benefit in teaching it.
编辑:只是为了增加这个。如果你能说服一个新的程序员,这是他们能做的最酷的事情,他们将成为优秀的程序员。这些天,你可以用一行代码做任何你想做的事情,来运行一个别人写的库。我个人对这样做一点都不满意,而且在教学上也没有什么好处。
#4
180
PHP - the Sierpinski gasket a.k.a the Triforce
OK, it's 15 lines of code but the result is awesome! That's the kind of stuff that made me freak out when I was a child. This is from the PHP manual:
好的,这是15行代码,但是结果太棒了!这就是我小时候让我抓狂的事情。这是来自PHP手册:
$x = 200;
$y = 200;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);
$red = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $red);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
#5
105
Microsoft has Small Basic, an IDE for "kids".
微软有一个小的Basic,一个用于“kids”的IDE。
pic = Flickr.GetRandomPicture("beach")
Desktop.SetWallpaper(pic)
It is specifically designed to show how cool programming is.
它是专门设计用来显示编程是多么的酷。
#6
83
I tend to think that people are impressed with stuff that they can relate to or is relevant to their lives. I'd try and base my 10 lines of code around something that they know and understand. Take, for example, Twitter and its API. Why not use this API to build something that's cool. The following 10 lines of code will return the "public timeline" from Twitter and display it in a console application...
我倾向于认为,人们对他们能感兴趣的东西或与他们生活相关的东西印象深刻。我试着把我的10行代码建立在他们知道和理解的东西周围。以Twitter及其API为例。为什么不使用这个API来构建一些很酷的东西呢?下面的10行代码将从Twitter返回“公共时间线”,并在一个控制台应用程序中显示它……
using (var xmlr = XmlReader.Create("http://twitter.com/statuses/public_timeline.rss"))
{
SyndicationFeed
.Load(xmlr)
.GetRss20Formatter()
.Feed
.Items
.ToList()
.ForEach( x => Console.WriteLine(x.Title.Text));
}
My code sample might not be the best for your students. It's written in C# and uses .NET 3.5. So if you're going to teach them PHP, Java, or C++ this won't be useful. However, my point is that by associating your 10 lines of code with something "cool, interesting, and relevant to the students your sample also becomes cool, interesting, and relevant.
我的代码样本可能不是对你的学生最好的。它是用c#编写的,使用。net 3.5。所以如果你要教他们PHP, Java,或者c++,这是没用的。然而,我的观点是,通过将你的10行代码与一些“酷、有趣、与学生相关的东西”联系起来,你的样本也会变得很酷、有趣和相关。
Good luck!
好运!
[Yes, I know that I've missed out a few lines of using statements and the Main method, but I'm guessing that the 10 lines didn't need to be literally 10 lines]
[是的,我知道我遗漏了一些使用语句和主要方法的行,但我猜10行不需要字面上的10行]
#7
80
This is a Python telnet server that will ask for the users name and say hello to them. This looks cool because you are communicating with your program from a different computer over the network.
这是一个Python telnet服务器,它将请求用户名并向他们问好。这看起来很酷,因为您正在通过网络与来自不同计算机的程序进行通信。
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.bind(("", 3333))
s.listen(5)
while 1:
(c, a) = s.accept()
c.send("What is your name? ")
name = c.recv(100)
c.send("Hello "+name)
c.close()
#8
69
I think it's tough to be a computer educator these days. I am. We face an increasingly steep uphill battle. Our students are incredibly sophisticated users and it takes a lot to impress them. They have so many tools accessible to them that do amazing things.
我认为现在要成为一个计算机教育者是很困难的。我是。我们面临着一场日益严峻的艰苦战斗。我们的学生都是非常老练的用户,要给他们留下深刻印象需要付出很多。他们有很多工具可以让他们做一些令人惊奇的事情。
A simple calculator in 10 lines of code? Why? I've got a TI-86 for that.
10行代码中的一个简单的计算器?为什么?我有一个TI-86。
A script that applies special effects to an image? That's what Photoshop is for. And Photoshop blows away anything you can do in 10 lines.
对图像应用特殊效果的脚本?这就是Photoshop的功能。用Photoshop把你能做的10行都吹掉。
How about ripping a CD and converting the file to MP3? Uhh, I already have 50,000 songs I got from BitTorrent. They're already in MP3 format. I play them on my iPhone. Who buys CDs anyway?
撕下CD,把文件转换成MP3怎么样?我已经有了5万首来自BitTorrent的歌曲。它们已经是MP3格式了。我在iPhone上播放。购买CDs呢?
To introduce savvy users to programming, you're going to have to find something that's:
要介绍精明的用户编程,你必须找到一些东西:
a) applicable to something they find interesting and cool, and b) does something they can't already do.
a)适用于他们觉得有趣和酷的东西,b)做一些他们不可能已经做的事情。
Assume your students already have access to the most expensive software. Many of them do have the full version of Adobe CS5.5 (retail price: $2,600; actual price: free) and can easily get any application that would normally break your department's budget.
假设你的学生已经可以使用最昂贵的软件了。他们中的许多人都有完整版的Adobe CS5.5(零售价:2600美元;实际价格:免费)并且很容易得到任何通常会破坏你部门预算的申请。
But the vast majority of them have no idea how any of this "computer stuff" actually works.
但绝大多数人都不知道这些“电脑玩意儿”到底是怎么回事。
They are an incredibly creative bunch: they like to create things. They just want to be able to do or make something that their friends can't. They want something to brag about.
他们是非常有创造力的一群人:他们喜欢创造事物。他们只是希望能够做或做一些他们的朋友做不到的事情。他们想要一些值得夸耀的东西。
Here are some things that I've found to resonate with my students:
以下是一些我发现能引起学生共鸣的事情:
- HTML and CSS. From those they learn how MySpace themes work and can customize them.
- HTML和CSS。从这些人那里,他们了解了MySpace的主题是如何工作的,并可以定制它们。
- Mashups. They've all seen them, but don't know how to create them. Check out Yahoo! Pipes. There are lots of teachable moments, such as RSS, XML, text filtering, mapping, and visualization. The completed mashup widgets can be embedded in web pages.
- mashup。他们都见过,但不知道如何创造。看看雅虎管道。有很多可教的时刻,比如RSS、XML、文本过滤、映射和可视化。完成的mashup小部件可以嵌入到web页面中。
- Artwork. Look at Context-Free Art. Recursion and randomization are key to making beautiful pictures.
- 艺术品。看看上下文无关的艺术。递归和随机化是制作漂亮图片的关键。
- Storytelling. With an easy-to-use 3D programming environment like Alice, it's easy to create high-quality, engaging stories using nothing more than drag-and-drop.
- 讲故事。使用像Alice这样易于使用的3D编程环境,很容易创建高质量、引人入胜的故事,只用拖放操作。
None of these involve any programming in the traditional sense. But they do leverage powerful libraries. I think of them as a different kind of programming.
这些都不涉及传统意义上的编程。但它们确实利用了强大的库。我认为它们是一种不同的编程。
#9
63
I've found a big favorite (in GWBASIC) is:
我发现一个很大的爱好(在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>"
I've found beginning students have a few conceptions that need to be fixed.
我发现初学者有一些观念需要修正。
- Computers don't read your mind.
- 电脑不会读取你的想法。
- Computers only do one thing at a time, even if they do it so fast they seem to do it all at once.
- 计算机一次只做一件事,即使它们做得如此之快,它们似乎一下子就完成了。
- Computers are just stupid machines and only do what they are told.
- 电脑只是一种愚蠢的机器,只做他们被告知的事情。
- Computers only recognize certain things and these are like building blocks.
- 计算机只识别某些东西,这些东西就像积木一样。
- A key concept is that a variable is something that contains a value and its name is different from that value.
- 一个关键的概念是,变量是包含值的,它的名称与该值不同。
- The distinction between the time at which you edit the program and the time at which it runs.
- 在你编辑程序的时间和它运行的时间之间的区别。
Good luck with your class. I'm sure you'll do well.
祝你们上课好运。我相信你会做得很好的。
P.S. I'm sure you understand that, along with material and skill, you're also teaching an attitude, and that is just as important.
附注:我相信你会明白,除了材料和技巧,你还在传授一种态度,这一点同样重要。
#10
62
This C-code is maybe be obfuscated, but I found it very powerful
这个c代码可能有点模糊,但我觉得它很强大。
#include <unistd.h>
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
And here is the result... In only 3 lines... A kind of fractal Hello World
...
这就是结果。只有三行……一种分形Hello World…
WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! !dWW!ddddllllrrrrrrrooooooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
Worrrrrrrllllllddd!oooWWWoloWWWWoodr drrWdlllrrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wlddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
olddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Worrrrrrrllllllddd!oooWWWoloWWWWoodr droWdlllrrrrrrrr
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! WdWW!ddddllllrrrrrrrooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
#11
45
How about showing that you can take any web browser and enter JavaScript into the address bar and get code to execute?
如何显示您可以使用任何web浏览器并将JavaScript输入到地址栏并获得执行代码呢?
EDIT: Go to a page with lots of images and try this in the address bar:
编辑:到一个有很多图片的页面,在地址栏试试这个:
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)
#12
37
You could make an application that picks a random number. And you have to guess it. If you are wrong it says: higher or lower. And if you guessed it, a nice message.
你可以让一个应用程序选择一个随机数。你必须猜一猜。如果你错了,它会说:高或低。如果你猜对了,这是一个很好的信息。
It's cool to play for the students.
为学生们演奏很酷。
Simple Python version without proper error checking:
简单的Python版本,没有正确的错误检查:
import random
while input('Want to play higher/lower? ').lower().startswith('y'):
n = random.randint(1, 100)
g = int(input('Guess: '))
while g != n:
print(' %ser!' % (g > n and 'low' or 'high'))
g = int(input('Guess: '))
print(' Correct! Congratulations!')
Erik suggests that the computer should guess the number. This can be done within 10 lines of code as well (though now the lack of proper error checking is even more serious: valid numbers outside the range cause an infinite loop):
埃里克建议电脑应该猜出号码。这可以在10行代码中完成(尽管现在缺少正确的错误检查更加严重:在范围之外的有效数字导致了无限循环):
while input('Want to let the pc play higher/lower? ').lower().startswith('y'):
n = int(input('Give a number between 1 and 100: '))
lo, hi, guess, tries = 1, 100, 50, 1
while guess != n:
tries += 1
lo, hi = (guess + 1, hi) if guess < n else (lo, guess - 1)
guess = (lo + hi) // 2
print('Computer guessed number in %d tries' % tries)
#13
26
Back in computer class in high school, myself and a couple of friends taught the class how to program with Delphi. The class was mostly focused on programming with Pascal, so Delphi was a good next step. We demonstrated the event driven nature of Delphi and its RAD capabilities. At the end of the lesson we showed the class a sample application and asked them to reproduce it. The application asked "Are you drunk?" with two buttons Yes and No. ...I think you know what is coming next...the No button changed locations on mouse over and was almost impossible to click.
在高中的计算机课上,我和几个朋友教他们如何用Delphi编程。课程主要集中在Pascal编程上,所以Delphi是一个很好的下一步。我们演示了Delphi的事件驱动特性及其RAD功能。在课程的最后,我们展示了一个示例应用程序,并要求他们复制它。应用程序问“你喝醉了吗?”有两个按钮,是和不是。我想你知道接下来会发生什么……没有按钮改变了鼠标的位置,几乎不可能点击。
The students and teacher got a good kick out of it.
学生和老师从中得到了很大的乐趣。
The program only required a few lines of user-written code with a simple equation to calculate where to move the button. I don't think any of the other students figured it out, but a few were close.
这个程序只需要几行用户编写的代码和一个简单的公式来计算按钮的移动位置。我认为其他的学生都没想出来,但有几个学生很接近。
#14
23
When I first figured out the bash forkbomb, I thought it was really sweet. So simple, yet neat in what it can do:
当我第一次发现bash forkbomb时,我觉得它真的很甜。如此简单,但却能做到:
:(){ :|:& };:
#15
22
This is cheating, and not even remotely simple, but I once wrote a shoot'em up in 20 lines of C++, using the Allegro graphics library. No real criteria for what a line was, but it was a bit ago, and it was made purely for fun. It even had crude sound effects.
这是欺骗,甚至不是很简单,但我曾经用20行c++编写了一个shoot'em,使用Allegro图形库。没有真正的标准来衡量一条线是什么,但它是在一点之前,它纯粹是为了好玩。它甚至有粗糙的声音效果。
Here's what it looked like:
这是它的样子:
20 Lines http://img227.imageshack.us/img227/8770/20linesxx0.png
20行http://img227.imageshack.us/img227/8770/20linesxx0.png
And here's the code (should compile):
下面是代码(应该编译):
bool inside(int x, int y, int x2, int y2) { return (x>x2&&x<x2+20&&y>y2&&y<y2+10); }
int main() {
BITMAP* buffer;
float px,shotx,shoty,monstars[8],first,rnd,pressed,points = 0, maxp = 0;
unsigned char midi[5] = {0xC0,127,0x90,25,0x54}, plgfx[] = {0,0,0,10,3,10,3,5,6,5,6,10,8,12,10,10,10,5,13,5,13,10,16,10,16,0,13,0,13,2,3,2,3,0,0,0}, mongfx[] = {0,0, 10,5, 20,0, 17,8, 15,6, 10,16, 5,6, 3,8, 0,0};
allegro_init(), set_color_depth(32), set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,240,0,0), install_timer(), install_keyboard(), install_mouse(), buffer = create_bitmap(320,240),srand(time(NULL)),install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT,""),clear_to_color(buffer,makecol32(100,100,255));
while ((pressed=(!key[KEY_Z]&&pressed)?0:pressed)?1:1&&(((shoty=key[KEY_Z]&&shoty<0&&pressed==0?(pressed=1?200:200):first==0?-1:shoty)==200?shotx=px+9:0)==9999?1:1) && 1+(px += key[KEY_LEFT]?-0.1:0 + key[KEY_RIGHT]?0.1:0) && 1+int(px=(px<0?0:(px>228?228:px))) && !key[KEY_ESC]) {
rectfill(buffer,0,0,244,240,makecol32(0,0,0));
for(int i=0;i<8;i++) if (inside(shotx,shoty,i*32,monstars[i])) midi_out(midi,5);
for (int i=0; i<8; monstars[i] += first++>8?(monstars[i]==-100?0:0.02):-100, points = monstars[i]>240?points-1:points, monstars[i]=monstars[i]>240?-100:monstars[i], points = inside(shotx,shoty,i*32,monstars[i])?points+1:points, (monstars[i] = inside(shotx,shoty,i*32,monstars[i])?shoty=-1?-100:-100:monstars[i]), maxp = maxp>points?maxp:points, i++) for (int j=1; j<9; j++) line(buffer,i*32+mongfx[j*2 - 2],monstars[i]+mongfx[j*2-1],i*32+mongfx[j*2],monstars[i]+mongfx[j*2+1],makecol32(255,0,0));
if (int(first)%2000 == 0 && int(rnd=float(rand()%8))) monstars[int(rnd)] = monstars[int(rnd)]==-100?-20:monstars[int(rnd)]; // randomowe pojawianie potworkow
if (shoty>0) rectfill(buffer,shotx,shoty-=0.1,shotx+2,shoty+2,makecol32(0,255,255)); // rysowanie strzalu
for (int i=1; i<18; i++) line(buffer,px+plgfx[i*2 - 2],200-plgfx[i*2-1],px+plgfx[i*2],200-plgfx[i*2+1],makecol32(255,255,0));
textprintf_ex(buffer,font,250,10,makecol32(255,255,255),makecol32(100,100,255),"$: %i ",int(points)*10);
textprintf_ex(buffer,font,250,20,makecol32(255,255,255),makecol32(100,100,255),"$$ %i ",int(maxp)*10);
blit(buffer, screen, 0, 0, 0, 0, 320,240);
}
} END_OF_MAIN()
#16
21
In this day and age, JavaScript is an excellent way to show how you can program using some really basic tools e.g. notepad.
在这个时代,JavaScript是一个很好的方式来展示你如何使用一些真正的基本工具,例如记事本。
jQuery effects are great starting point for anyone wanting to wow their friends!
jQuery的效果是任何想要让朋友们惊叹的起点!
In this one, just click the white space of the page.
在这个页面中,只需点击页面的空白。
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document.body).click(function () {
if ($("#pic").is(":hidden")) {
$("#pic").slideDown("slow");
} else {
$("#pic").slideUp();
}
});
</script>
</head>
<body><img id="pic" src="http://www.smidgy.com/smidgy/images/2007/07/26/lol_cat_icanhascheezburger.jpg"/>
</body>
</html>
#17
20
One thing you might consider is something like Robocode, in which a lot of coding is abstracted away and you basically just tell a robot what to do. A simple 10-line function can make the robot do a great deal, and has a very visual and easy-to-follow result.
你可能会考虑到像Robocode这样的东西,在这个过程中,大量的编码被抽象出来,你基本上只是告诉机器人该做什么。一个简单的10行功能可以让机器人做很多事情,并且有一个非常直观和易于跟踪的结果。
Perhaps Robocode itself isn't suited to the task, but this kind of thing is a good way to relate written code to visual actions on the computer, plus it's fun to watch for when you need to give examples.
也许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);
}
}
#18
18
So one day, I decided that I'd had enough. I would learn piano. Seeing people like Elton John command such mastery of the keyboard assured me that this was what I wanted to do.
所以有一天,我决定我受够了。我想学钢琴。看到像艾尔顿·约翰这样精通键盘的人向我保证这就是我想做的。
Actually learning piano was a huge letdown. Even after completing eight grades of piano lessons, I was still not impressed with how my mental image of playing piano was so different from my original vision of enjoying the activity.
实际上,学习钢琴是一件非常令人失望的事。甚至在完成了八年级的钢琴课之后,我对弹钢琴的心理印象和我对这一活动的最初的想象不太一样。
However, what I thoroughly enjoyed was my mere three grades of rudiments of music theory. I learned about the construction of music. I was finally able to step from the world of performing written music to writing my own music. Subsequently, I was able to start playing what I wanted to play.
然而,我真正喜欢的是我仅有的三年级的音乐理论基础。我学习了音乐的构造。我终于能够从写音乐的世界中走出来,谱写自己的音乐。后来,我开始玩我想玩的游戏。
Don't try to dazzle new programmers, especially young programmers. The whole notion of "less than ten lines of simple code" seems to elicit a mood of "Show me something clever".
不要试图迷惑新的程序员,尤其是年轻的程序员。“少于十行简单代码”的概念似乎引出了一种“给我展示一些聪明的东西”的心情。
You can show a new programmer something clever. You can then teach that same programmer how to replicate this "performance". But this is not what gets them hooked on programming. Teach them the rudiments, and let them synthesize their own clever ten lines of code.
你可以向一个新程序员展示一些聪明的东西。然后您可以教相同的程序员如何复制这种“性能”。但这并不是让他们沉迷于编程的原因。教给他们基本知识,让他们合成自己的十行代码。
I would show a new programmer the following Python code:
我将向一个新程序员展示以下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)
I realize that I don't need to assign line
to edited_line
. However, that's just to keep things clear, and to show that I'm not editing the original document.
我意识到我不需要给edited_line赋值。但是,这只是为了让事情更清楚,并且显示我没有编辑原始文档。
In less than ten lines, I've verbosified a document. Of course, also be sure to show the new programmer all the string methods that are available. More importantly, I've showed three fundamentally interesting things I can do: variable assignment, a loop, file IO, and use of the standard library.
在不到十行代码中,我已经完成了一个文档。当然,也一定要向新程序员显示所有可用的字符串方法。更重要的是,我已经展示了我可以做的三件非常有趣的事情:变量赋值、循环、文件IO和标准库的使用。
I think you'll agree that this code doesn't dazzle. In fact, it's a little boring. No - actually, it's very boring. But show that code to a new programmer and see if that programmer can't repurpose every part of that script to something much more interesting within the week, if not the day. Sure, it'll be distasteful to you (maybe using this script to make a simple HTML parser), but everything else just takes time and experience.
我想你会同意这段代码不会让你眼花缭乱。事实上,这有点无聊。不——事实上,它很无聊。但是,请将代码展示给一个新的程序员,看看程序员是否不能将脚本的每个部分都重新定位到一个更有趣的星期内,如果不是一天的话。当然,这对您来说是很不舒服的(可能使用这个脚本创建一个简单的HTML解析器),但是其他一切都需要时间和经验。
#19
17
Like most of the other commenters, I started out writing code to solve math problems (or to create graphics for really terrible games that I would design -- things like Indiana Jones versus Zombies).
和大多数其他评论者一样,我开始编写代码来解决数学问题(或者为我设计的非常糟糕的游戏创建图形——比如印第安纳·琼斯和僵尸)。
What really started me (on both math and programming) was going from text based, choose your own adventure style games...to more graphics-based games. I started out coloring graph paper and plotting pixels, until I got into geometry...and discovered how to use equations to plot curves and lines, boxes, etc.
真正让我开始(在数学和编程上)是基于文本的,选择你自己的冒险风格的游戏…基于图形更多游戏。我开始画画纸和画像素,直到我进入几何学…并发现如何用方程来绘制曲线和直线,盒子等。
My point is, I could have really gotten into something like processing ( http://processing.org/ ) where a typical program looks something like this:
我的观点是,我可以真正地进入到处理(http://processing.org/)这样一个典型的程序看起来是这样的:
void setup()
{
size(200, 200);
noStroke();
rectMode(CENTER);
}
void draw()
{
background(51);
fill(255, 204);
rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
fill(255, 204);
int inverseX = width-mouseX;
int inverseY = height-mouseY;
rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
}
To me, this is the "Logo" of the future.
对我来说,这是未来的标志。
There are easy "hello world" examples that can quickly get someone drawing and changing code and seeing how things break and what weird "accidents" can be created...all the way to more advanced interaction and fractal creation...
这里有一些简单的“hello world”例子,可以快速地让人绘制和修改代码,看看事情是如何发生的,还有什么奇怪的“意外”可以被创造出来……一直到更高级的互动和分形创造…
#20
15
You could use a script written with AutoIt, which blurs the line between using a traditional application and programming.
您可以使用用AutoIt编写的脚本,它模糊了使用传统应用程序和编程之间的界限。
E.g. a script which opens notepad and makes their own computer insult them in it and via a message box, and then leaves no trace of its actions:
例如,一个脚本打开记事本,并让他们自己的电脑在它和一个消息框中侮辱他们,然后没有留下任何它的行动的痕迹:
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")
#21
13
I remember when I first started coding loops always impressed me. You write 5 - 10 lines of code (or less) and hundreds (or however many you specify) lines print out. (I learned first in PHP and Java).
我记得当我第一次开始编码循环时,总是给我留下了深刻的印象。您编写5 - 10行代码(或更少)和数百行(或不管您指定的多少)行打印出来。(我首先学习了PHP和Java)。
for( int i = 0; i < 200; i++ )
{
System.out.println( i );
}
#22
13
I think a good place for a student to get started could be Greasemonkey. There are thousands of example scripts on userscripts.org, very good reading material, some of which are very small. Greasemonkey scripts affect web-pages, which the students will already be familiar with using, if not manipulating. Greasemonkey itself offers a very easy way to edit and enable/disable scripts while testing.
我认为一个学生开始学习的好地方可以是Greasemonkey。在userscripts.org上有成千上万的示例脚本,非常好的阅读材料,其中一些非常小。Greasemonkey脚本影响网页,如果不操作的话,学生们已经很熟悉了。Greasemonkey本身提供了一种非常简单的方法来在测试时编辑和启用/禁用脚本。
As an example, here is the "Google Two Columns" script:
例如,这里是“谷歌两列”脚本:
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'; }
#23
10
This is a very rudimentary text-based c# program that simulates the spinning action of a slot machine. It doesn't include different odds of winning or cash payouts, but that could be a nice exercise for the students.
这是一个非常基本的基于文本的c#程序,它模拟了*的旋转动作。它不包括不同的获胜几率或现金支出,但这对学生来说可能是一个很好的练习。
Sorry that it is more than 10 lines.
抱歉,超过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" );
#24
9
With Tcl you have a simple text editor with a save button in about 12 lines of code (but no open, that would take another 8 lines). It works across all standard platforms:
对于Tcl,您有一个简单的文本编辑器,在大约12行代码中有一个save按钮(但没有打开,这将需要另外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
}
}
I realize the goal was 10 lines, so if you want the to stick to 10 lines or less, a simple text editor without load or save is only two lines. That's not too shabby.
我知道目标是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
Execute either of the above blocks of code with "wish filename" on the platform of your choice. Wish comes with most *nix's and the mac but you'll have to install it manually for windows.
在您选择的平台上执行上述代码块中的任意一个“wish filename”。希望有很多*nix和mac,但你必须手动安装windows。
To go a step further, that two line script can also be written in python, though it takes eight lines, still under the 10 line goal:
更进一步,这两行脚本也可以用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()
#25
9
How about a bookmarklet? It would show them how to manipulate something that they use every day (the Internet) without requiring any development tools.
一个书签呢?它将向他们展示如何操作他们每天使用的东西(互联网),而不需要任何开发工具。
#26
8
If you can afford the hardware, using an Arduino board + processing will produce some pretty cool things, though it may be a little advanced for people that may not be interested at all in programming.
如果您能够负担得起硬件,使用Arduino板+处理将会产生一些非常酷的东西,尽管对于那些可能对编程不感兴趣的人来说,它可能有点高级。
#27
8
I wrote about this recently in an article "The Shortest, most useful program I have ever written."
我最近在一篇文章中写道:“这是我写过的最短、最有用的程序。”
Summary: I wrote a 3 line VB6 app back in 1996 that I still use every single day. Once the exe is dropped in the "Send-to" folder. It lets you right click on a file in explorer and send the full path of that file to the clipboard.
总结:我在1996年写了一个3行VB6的应用,我仍然每天使用。一旦exe被丢弃在“发送到”文件夹中。它允许您在浏览器中右键单击文件,并将该文件的完整路径发送到剪贴板。
Public Sub Main()
Clipboard.SetText Command$
End Sub
#28
7
It's interesting that you mention the Mandelbrot set, as creating fractals with GW-BASIC is what sparked my love of programming back in high school (around 1993). Before we started learning about fractals, we wrote boring standard deviation applications and I still planned to go into journalism.
很有趣的是,你提到曼德尔布罗特集,用gwbasic来创建分形,这激发了我在高中时对编程的热爱(1993年左右)。在我们开始学习分形之前,我们编写了无聊的标准偏差应用程序,我仍然打算从事新闻工作。
But once I saw that long, difficult-to-write BASIC program generate "fractal terrain," I was hooked and I never looked back. It changed the way I thought about math, science, computers, and the way I learn.
但是,当我看到那个长而难写的基本程序生成“分形地形”时,我就迷上了它,我再也没有回头。它改变了我对数学、科学、计算机和我学习方式的看法。
I hope you find the program that has the same affect on your students.
我希望你能找到对你的学生有同样影响的项目。
#29
7
wxPython First Steps
import wx
app = wx.App()
wx.Frame(None, -1, 'simple.py').Show()
app.MainLoop()
simple.py frame http://zetcode.com/wxpython/images/simple.jpg
简单。py帧http://zetcode.com/wxpython/images/simple.jpg
#30
6
I'm sure it'd turn into more than 10 lines of code, but have you considered a form based app where pressing the buttons does things like changing the colour of the background or changes the size of the text? This would show them how interactive programs work. It would also show them that they, as programmer, are in complete control of what the computer (program) does.
我确信它会变成10行以上的代码,但是你有没有考虑过一个基于表单的应用程序,按下按钮,比如改变背景颜色或者改变文本的大小?这将向他们展示交互程序是如何工作的。它还将显示,作为程序员,他们完全控制了计算机(程序)所做的工作。
Hopefully it would lead them to make suggestions for other things they could change and then onto other things they might want to do.
希望它能引导他们对其他可能改变的事情提出建议,然后做一些他们可能想做的事情。
#1
78
I got a great response from my kids with a quick VB script to manipulate a Microsoft Agent character. For those that aren't familiar with MS Agent, it's a series of animated onscreen characters that can be manipulated via a COM interface. You can download the code and characters at the Microsoft Agent download page.
我的孩子们用一个快速的VB脚本来操作一个微软的代理程序,我得到了一个很好的回应。对于那些不熟悉MS代理的人来说,它是一系列可以通过COM接口进行操作的动画屏幕字符。您可以在Microsoft代理下载页面下载代码和字符。
The folllowing few lines will make the Merlin character appear on screen, fly around, knock on the screen to get your attention, and say hello.
下面几行文字将会让梅林角色出现在屏幕上,四处飞,敲击屏幕吸引你的注意,并向你问好。
agentName = "Merlin"
agentPath = "c:\windows\msagent\chars\" & agentName & ".acs"
Set agent = CreateObject("Agent.Control.2")
agent.Connected = TRUE
agent.Characters.Load agentName, agentPath
Set character = agent.Characters.Character(agentName)
character.Show
character.MoveTo 500, 400
character.Play "GetAttention"
character.Speak "Hello, how are you?"
Wscript.Sleep 15000
character.Stop
character.Play "Hide"
There are a great many other commands you can use. Check http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx for more information.
您可以使用许多其他命令。查看http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx获取更多信息。
EDIT 2011-09-02 I recently discovered that Microsoft Agent is not natively installed on Windows 7. However it is offered as a separate download here. I have not tested this so cannot verify whether it operates.
编辑2011-09-02我最近发现微软的代理并不是本地安装在Windows 7上的。不过,这里提供了一个单独的下载。我没有测试过,所以无法验证它是否运行。
#2
339
Enter this code in your address bar (in your browser) and press enter. Then you can edit all the content of the webpage!
在您的地址栏(在您的浏览器中)输入此代码并按Enter。然后你可以编辑网页的所有内容!
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
That is the coolest "one-liner" I know =)
这是我所知道的最酷的“一行”
#3
201
When I first wrote this.
当我第一次写这个的时候。
10 PRINT "What is your name?"
20 INPUT A$
30 PRINT "Hello " A$
40 GOTO 30
It blew people away! The computer remembered their name!
人们吹!电脑记住了他们的名字!
EDIT: Just to add to this. If you can convince a new programmer this is the coolest thing they can do, they will become the good programmers. These days, you can do almost anything you want with one line of code to run a library somebody else wrote. I personally get absolutely no satisfaction from doing that and see little benefit in teaching it.
编辑:只是为了增加这个。如果你能说服一个新的程序员,这是他们能做的最酷的事情,他们将成为优秀的程序员。这些天,你可以用一行代码做任何你想做的事情,来运行一个别人写的库。我个人对这样做一点都不满意,而且在教学上也没有什么好处。
#4
180
PHP - the Sierpinski gasket a.k.a the Triforce
OK, it's 15 lines of code but the result is awesome! That's the kind of stuff that made me freak out when I was a child. This is from the PHP manual:
好的,这是15行代码,但是结果太棒了!这就是我小时候让我抓狂的事情。这是来自PHP手册:
$x = 200;
$y = 200;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 190);
$corners[2] = array('x' => 200, 'y' => 190);
$red = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $red);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
#5
105
Microsoft has Small Basic, an IDE for "kids".
微软有一个小的Basic,一个用于“kids”的IDE。
pic = Flickr.GetRandomPicture("beach")
Desktop.SetWallpaper(pic)
It is specifically designed to show how cool programming is.
它是专门设计用来显示编程是多么的酷。
#6
83
I tend to think that people are impressed with stuff that they can relate to or is relevant to their lives. I'd try and base my 10 lines of code around something that they know and understand. Take, for example, Twitter and its API. Why not use this API to build something that's cool. The following 10 lines of code will return the "public timeline" from Twitter and display it in a console application...
我倾向于认为,人们对他们能感兴趣的东西或与他们生活相关的东西印象深刻。我试着把我的10行代码建立在他们知道和理解的东西周围。以Twitter及其API为例。为什么不使用这个API来构建一些很酷的东西呢?下面的10行代码将从Twitter返回“公共时间线”,并在一个控制台应用程序中显示它……
using (var xmlr = XmlReader.Create("http://twitter.com/statuses/public_timeline.rss"))
{
SyndicationFeed
.Load(xmlr)
.GetRss20Formatter()
.Feed
.Items
.ToList()
.ForEach( x => Console.WriteLine(x.Title.Text));
}
My code sample might not be the best for your students. It's written in C# and uses .NET 3.5. So if you're going to teach them PHP, Java, or C++ this won't be useful. However, my point is that by associating your 10 lines of code with something "cool, interesting, and relevant to the students your sample also becomes cool, interesting, and relevant.
我的代码样本可能不是对你的学生最好的。它是用c#编写的,使用。net 3.5。所以如果你要教他们PHP, Java,或者c++,这是没用的。然而,我的观点是,通过将你的10行代码与一些“酷、有趣、与学生相关的东西”联系起来,你的样本也会变得很酷、有趣和相关。
Good luck!
好运!
[Yes, I know that I've missed out a few lines of using statements and the Main method, but I'm guessing that the 10 lines didn't need to be literally 10 lines]
[是的,我知道我遗漏了一些使用语句和主要方法的行,但我猜10行不需要字面上的10行]
#7
80
This is a Python telnet server that will ask for the users name and say hello to them. This looks cool because you are communicating with your program from a different computer over the network.
这是一个Python telnet服务器,它将请求用户名并向他们问好。这看起来很酷,因为您正在通过网络与来自不同计算机的程序进行通信。
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.bind(("", 3333))
s.listen(5)
while 1:
(c, a) = s.accept()
c.send("What is your name? ")
name = c.recv(100)
c.send("Hello "+name)
c.close()
#8
69
I think it's tough to be a computer educator these days. I am. We face an increasingly steep uphill battle. Our students are incredibly sophisticated users and it takes a lot to impress them. They have so many tools accessible to them that do amazing things.
我认为现在要成为一个计算机教育者是很困难的。我是。我们面临着一场日益严峻的艰苦战斗。我们的学生都是非常老练的用户,要给他们留下深刻印象需要付出很多。他们有很多工具可以让他们做一些令人惊奇的事情。
A simple calculator in 10 lines of code? Why? I've got a TI-86 for that.
10行代码中的一个简单的计算器?为什么?我有一个TI-86。
A script that applies special effects to an image? That's what Photoshop is for. And Photoshop blows away anything you can do in 10 lines.
对图像应用特殊效果的脚本?这就是Photoshop的功能。用Photoshop把你能做的10行都吹掉。
How about ripping a CD and converting the file to MP3? Uhh, I already have 50,000 songs I got from BitTorrent. They're already in MP3 format. I play them on my iPhone. Who buys CDs anyway?
撕下CD,把文件转换成MP3怎么样?我已经有了5万首来自BitTorrent的歌曲。它们已经是MP3格式了。我在iPhone上播放。购买CDs呢?
To introduce savvy users to programming, you're going to have to find something that's:
要介绍精明的用户编程,你必须找到一些东西:
a) applicable to something they find interesting and cool, and b) does something they can't already do.
a)适用于他们觉得有趣和酷的东西,b)做一些他们不可能已经做的事情。
Assume your students already have access to the most expensive software. Many of them do have the full version of Adobe CS5.5 (retail price: $2,600; actual price: free) and can easily get any application that would normally break your department's budget.
假设你的学生已经可以使用最昂贵的软件了。他们中的许多人都有完整版的Adobe CS5.5(零售价:2600美元;实际价格:免费)并且很容易得到任何通常会破坏你部门预算的申请。
But the vast majority of them have no idea how any of this "computer stuff" actually works.
但绝大多数人都不知道这些“电脑玩意儿”到底是怎么回事。
They are an incredibly creative bunch: they like to create things. They just want to be able to do or make something that their friends can't. They want something to brag about.
他们是非常有创造力的一群人:他们喜欢创造事物。他们只是希望能够做或做一些他们的朋友做不到的事情。他们想要一些值得夸耀的东西。
Here are some things that I've found to resonate with my students:
以下是一些我发现能引起学生共鸣的事情:
- HTML and CSS. From those they learn how MySpace themes work and can customize them.
- HTML和CSS。从这些人那里,他们了解了MySpace的主题是如何工作的,并可以定制它们。
- Mashups. They've all seen them, but don't know how to create them. Check out Yahoo! Pipes. There are lots of teachable moments, such as RSS, XML, text filtering, mapping, and visualization. The completed mashup widgets can be embedded in web pages.
- mashup。他们都见过,但不知道如何创造。看看雅虎管道。有很多可教的时刻,比如RSS、XML、文本过滤、映射和可视化。完成的mashup小部件可以嵌入到web页面中。
- Artwork. Look at Context-Free Art. Recursion and randomization are key to making beautiful pictures.
- 艺术品。看看上下文无关的艺术。递归和随机化是制作漂亮图片的关键。
- Storytelling. With an easy-to-use 3D programming environment like Alice, it's easy to create high-quality, engaging stories using nothing more than drag-and-drop.
- 讲故事。使用像Alice这样易于使用的3D编程环境,很容易创建高质量、引人入胜的故事,只用拖放操作。
None of these involve any programming in the traditional sense. But they do leverage powerful libraries. I think of them as a different kind of programming.
这些都不涉及传统意义上的编程。但它们确实利用了强大的库。我认为它们是一种不同的编程。
#9
63
I've found a big favorite (in GWBASIC) is:
我发现一个很大的爱好(在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>"
I've found beginning students have a few conceptions that need to be fixed.
我发现初学者有一些观念需要修正。
- Computers don't read your mind.
- 电脑不会读取你的想法。
- Computers only do one thing at a time, even if they do it so fast they seem to do it all at once.
- 计算机一次只做一件事,即使它们做得如此之快,它们似乎一下子就完成了。
- Computers are just stupid machines and only do what they are told.
- 电脑只是一种愚蠢的机器,只做他们被告知的事情。
- Computers only recognize certain things and these are like building blocks.
- 计算机只识别某些东西,这些东西就像积木一样。
- A key concept is that a variable is something that contains a value and its name is different from that value.
- 一个关键的概念是,变量是包含值的,它的名称与该值不同。
- The distinction between the time at which you edit the program and the time at which it runs.
- 在你编辑程序的时间和它运行的时间之间的区别。
Good luck with your class. I'm sure you'll do well.
祝你们上课好运。我相信你会做得很好的。
P.S. I'm sure you understand that, along with material and skill, you're also teaching an attitude, and that is just as important.
附注:我相信你会明白,除了材料和技巧,你还在传授一种态度,这一点同样重要。
#10
62
This C-code is maybe be obfuscated, but I found it very powerful
这个c代码可能有点模糊,但我觉得它很强大。
#include <unistd.h>
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
And here is the result... In only 3 lines... A kind of fractal Hello World
...
这就是结果。只有三行……一种分形Hello World…
WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! !dWW!ddddllllrrrrrrrooooooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
Worrrrrrrllllllddd!oooWWWoloWWWWoodr drrWdlllrrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wlddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
olddddd!!!!!WWordlWrd oW!ddllllrrrrrrr
Wlllllllldddd!!odrrdW o lWddllllrrrrrrr
Wrrllllllllddddd!WWolWr oWoo r!dllllrrrrrrr
Worrrlllllllldddd!WolWrr!!dWWWlrrldr ro!dlllrrrrrrrr
Worrrrrrrllllllddd!oooWWWoloWWWWoodr droWdlllrrrrrrrr
WWorrrrrrrrrrrrllld!!!!!dddd!!!!WWrd ! rlW!ddllrrrrrrrro
WWoorrrrrrrrrrrrrrrlllddddddddd!!!!oolWW lW!ddlrrrrrrrroo
WWWoorrrrrrrrrrrrrrrrrlllllddddddd!!Wdo l! rdo!l!r!dlrrrrrrrrooo
WWWWoorrrrrrrrrrrrrrrrrrrlllllllddddWldolrrlo!Wl r!dlooWWWoW!dllrrrrrrroooo
WWWWooorrrrrrrrrrrrrrrrrrrrllllllllldd!!!!WWWoo WloW!!!ddddllrrrrrrrrooooo
WWWWWoooorrrrrrrrrrrrrrrrrrrrrlllllllllddd!!!o!!! WdWW!ddddllllrrrrrrrooooooo
WWWWWWooooorrrrrrrrrrrrrrrrrrrrrllllllllldddd!WorddddoW!ddllllllrrrrrrooooooooo
WWWWWWWoooooorrrrrrrrrrrrrrrrrrrrrrlllllllldddd!orro!o!dllllllrrrrrrooooooooooo
WWWWWWWWoooooooorrrrrrrrrrrrrrrrrrrrrrllllllldd!oWW!!dllllllrrrrroooooooooooooo
WWWWWWWWWWooooooooorrrrrrrrrrrrrrrrrrrrrrrllllld!!ddllllrrrrrrooooooooooooooooo
WWWWWWWWWWWoooooooooooorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooooooooooooooooooooo
WWWWWWWWWWWWWooooooooooooooooorrrrrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooo
WWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
WWWWWWWWWWWWWWWWWWWWWoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
#11
45
How about showing that you can take any web browser and enter JavaScript into the address bar and get code to execute?
如何显示您可以使用任何web浏览器并将JavaScript输入到地址栏并获得执行代码呢?
EDIT: Go to a page with lots of images and try this in the address bar:
编辑:到一个有很多图片的页面,在地址栏试试这个:
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)
#12
37
You could make an application that picks a random number. And you have to guess it. If you are wrong it says: higher or lower. And if you guessed it, a nice message.
你可以让一个应用程序选择一个随机数。你必须猜一猜。如果你错了,它会说:高或低。如果你猜对了,这是一个很好的信息。
It's cool to play for the students.
为学生们演奏很酷。
Simple Python version without proper error checking:
简单的Python版本,没有正确的错误检查:
import random
while input('Want to play higher/lower? ').lower().startswith('y'):
n = random.randint(1, 100)
g = int(input('Guess: '))
while g != n:
print(' %ser!' % (g > n and 'low' or 'high'))
g = int(input('Guess: '))
print(' Correct! Congratulations!')
Erik suggests that the computer should guess the number. This can be done within 10 lines of code as well (though now the lack of proper error checking is even more serious: valid numbers outside the range cause an infinite loop):
埃里克建议电脑应该猜出号码。这可以在10行代码中完成(尽管现在缺少正确的错误检查更加严重:在范围之外的有效数字导致了无限循环):
while input('Want to let the pc play higher/lower? ').lower().startswith('y'):
n = int(input('Give a number between 1 and 100: '))
lo, hi, guess, tries = 1, 100, 50, 1
while guess != n:
tries += 1
lo, hi = (guess + 1, hi) if guess < n else (lo, guess - 1)
guess = (lo + hi) // 2
print('Computer guessed number in %d tries' % tries)
#13
26
Back in computer class in high school, myself and a couple of friends taught the class how to program with Delphi. The class was mostly focused on programming with Pascal, so Delphi was a good next step. We demonstrated the event driven nature of Delphi and its RAD capabilities. At the end of the lesson we showed the class a sample application and asked them to reproduce it. The application asked "Are you drunk?" with two buttons Yes and No. ...I think you know what is coming next...the No button changed locations on mouse over and was almost impossible to click.
在高中的计算机课上,我和几个朋友教他们如何用Delphi编程。课程主要集中在Pascal编程上,所以Delphi是一个很好的下一步。我们演示了Delphi的事件驱动特性及其RAD功能。在课程的最后,我们展示了一个示例应用程序,并要求他们复制它。应用程序问“你喝醉了吗?”有两个按钮,是和不是。我想你知道接下来会发生什么……没有按钮改变了鼠标的位置,几乎不可能点击。
The students and teacher got a good kick out of it.
学生和老师从中得到了很大的乐趣。
The program only required a few lines of user-written code with a simple equation to calculate where to move the button. I don't think any of the other students figured it out, but a few were close.
这个程序只需要几行用户编写的代码和一个简单的公式来计算按钮的移动位置。我认为其他的学生都没想出来,但有几个学生很接近。
#14
23
When I first figured out the bash forkbomb, I thought it was really sweet. So simple, yet neat in what it can do:
当我第一次发现bash forkbomb时,我觉得它真的很甜。如此简单,但却能做到:
:(){ :|:& };:
#15
22
This is cheating, and not even remotely simple, but I once wrote a shoot'em up in 20 lines of C++, using the Allegro graphics library. No real criteria for what a line was, but it was a bit ago, and it was made purely for fun. It even had crude sound effects.
这是欺骗,甚至不是很简单,但我曾经用20行c++编写了一个shoot'em,使用Allegro图形库。没有真正的标准来衡量一条线是什么,但它是在一点之前,它纯粹是为了好玩。它甚至有粗糙的声音效果。
Here's what it looked like:
这是它的样子:
20 Lines http://img227.imageshack.us/img227/8770/20linesxx0.png
20行http://img227.imageshack.us/img227/8770/20linesxx0.png
And here's the code (should compile):
下面是代码(应该编译):
bool inside(int x, int y, int x2, int y2) { return (x>x2&&x<x2+20&&y>y2&&y<y2+10); }
int main() {
BITMAP* buffer;
float px,shotx,shoty,monstars[8],first,rnd,pressed,points = 0, maxp = 0;
unsigned char midi[5] = {0xC0,127,0x90,25,0x54}, plgfx[] = {0,0,0,10,3,10,3,5,6,5,6,10,8,12,10,10,10,5,13,5,13,10,16,10,16,0,13,0,13,2,3,2,3,0,0,0}, mongfx[] = {0,0, 10,5, 20,0, 17,8, 15,6, 10,16, 5,6, 3,8, 0,0};
allegro_init(), set_color_depth(32), set_gfx_mode(GFX_AUTODETECT_WINDOWED,320,240,0,0), install_timer(), install_keyboard(), install_mouse(), buffer = create_bitmap(320,240),srand(time(NULL)),install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT,""),clear_to_color(buffer,makecol32(100,100,255));
while ((pressed=(!key[KEY_Z]&&pressed)?0:pressed)?1:1&&(((shoty=key[KEY_Z]&&shoty<0&&pressed==0?(pressed=1?200:200):first==0?-1:shoty)==200?shotx=px+9:0)==9999?1:1) && 1+(px += key[KEY_LEFT]?-0.1:0 + key[KEY_RIGHT]?0.1:0) && 1+int(px=(px<0?0:(px>228?228:px))) && !key[KEY_ESC]) {
rectfill(buffer,0,0,244,240,makecol32(0,0,0));
for(int i=0;i<8;i++) if (inside(shotx,shoty,i*32,monstars[i])) midi_out(midi,5);
for (int i=0; i<8; monstars[i] += first++>8?(monstars[i]==-100?0:0.02):-100, points = monstars[i]>240?points-1:points, monstars[i]=monstars[i]>240?-100:monstars[i], points = inside(shotx,shoty,i*32,monstars[i])?points+1:points, (monstars[i] = inside(shotx,shoty,i*32,monstars[i])?shoty=-1?-100:-100:monstars[i]), maxp = maxp>points?maxp:points, i++) for (int j=1; j<9; j++) line(buffer,i*32+mongfx[j*2 - 2],monstars[i]+mongfx[j*2-1],i*32+mongfx[j*2],monstars[i]+mongfx[j*2+1],makecol32(255,0,0));
if (int(first)%2000 == 0 && int(rnd=float(rand()%8))) monstars[int(rnd)] = monstars[int(rnd)]==-100?-20:monstars[int(rnd)]; // randomowe pojawianie potworkow
if (shoty>0) rectfill(buffer,shotx,shoty-=0.1,shotx+2,shoty+2,makecol32(0,255,255)); // rysowanie strzalu
for (int i=1; i<18; i++) line(buffer,px+plgfx[i*2 - 2],200-plgfx[i*2-1],px+plgfx[i*2],200-plgfx[i*2+1],makecol32(255,255,0));
textprintf_ex(buffer,font,250,10,makecol32(255,255,255),makecol32(100,100,255),"$: %i ",int(points)*10);
textprintf_ex(buffer,font,250,20,makecol32(255,255,255),makecol32(100,100,255),"$$ %i ",int(maxp)*10);
blit(buffer, screen, 0, 0, 0, 0, 320,240);
}
} END_OF_MAIN()
#16
21
In this day and age, JavaScript is an excellent way to show how you can program using some really basic tools e.g. notepad.
在这个时代,JavaScript是一个很好的方式来展示你如何使用一些真正的基本工具,例如记事本。
jQuery effects are great starting point for anyone wanting to wow their friends!
jQuery的效果是任何想要让朋友们惊叹的起点!
In this one, just click the white space of the page.
在这个页面中,只需点击页面的空白。
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document.body).click(function () {
if ($("#pic").is(":hidden")) {
$("#pic").slideDown("slow");
} else {
$("#pic").slideUp();
}
});
</script>
</head>
<body><img id="pic" src="http://www.smidgy.com/smidgy/images/2007/07/26/lol_cat_icanhascheezburger.jpg"/>
</body>
</html>
#17
20
One thing you might consider is something like Robocode, in which a lot of coding is abstracted away and you basically just tell a robot what to do. A simple 10-line function can make the robot do a great deal, and has a very visual and easy-to-follow result.
你可能会考虑到像Robocode这样的东西,在这个过程中,大量的编码被抽象出来,你基本上只是告诉机器人该做什么。一个简单的10行功能可以让机器人做很多事情,并且有一个非常直观和易于跟踪的结果。
Perhaps Robocode itself isn't suited to the task, but this kind of thing is a good way to relate written code to visual actions on the computer, plus it's fun to watch for when you need to give examples.
也许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);
}
}
#18
18
So one day, I decided that I'd had enough. I would learn piano. Seeing people like Elton John command such mastery of the keyboard assured me that this was what I wanted to do.
所以有一天,我决定我受够了。我想学钢琴。看到像艾尔顿·约翰这样精通键盘的人向我保证这就是我想做的。
Actually learning piano was a huge letdown. Even after completing eight grades of piano lessons, I was still not impressed with how my mental image of playing piano was so different from my original vision of enjoying the activity.
实际上,学习钢琴是一件非常令人失望的事。甚至在完成了八年级的钢琴课之后,我对弹钢琴的心理印象和我对这一活动的最初的想象不太一样。
However, what I thoroughly enjoyed was my mere three grades of rudiments of music theory. I learned about the construction of music. I was finally able to step from the world of performing written music to writing my own music. Subsequently, I was able to start playing what I wanted to play.
然而,我真正喜欢的是我仅有的三年级的音乐理论基础。我学习了音乐的构造。我终于能够从写音乐的世界中走出来,谱写自己的音乐。后来,我开始玩我想玩的游戏。
Don't try to dazzle new programmers, especially young programmers. The whole notion of "less than ten lines of simple code" seems to elicit a mood of "Show me something clever".
不要试图迷惑新的程序员,尤其是年轻的程序员。“少于十行简单代码”的概念似乎引出了一种“给我展示一些聪明的东西”的心情。
You can show a new programmer something clever. You can then teach that same programmer how to replicate this "performance". But this is not what gets them hooked on programming. Teach them the rudiments, and let them synthesize their own clever ten lines of code.
你可以向一个新程序员展示一些聪明的东西。然后您可以教相同的程序员如何复制这种“性能”。但这并不是让他们沉迷于编程的原因。教给他们基本知识,让他们合成自己的十行代码。
I would show a new programmer the following Python code:
我将向一个新程序员展示以下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)
I realize that I don't need to assign line
to edited_line
. However, that's just to keep things clear, and to show that I'm not editing the original document.
我意识到我不需要给edited_line赋值。但是,这只是为了让事情更清楚,并且显示我没有编辑原始文档。
In less than ten lines, I've verbosified a document. Of course, also be sure to show the new programmer all the string methods that are available. More importantly, I've showed three fundamentally interesting things I can do: variable assignment, a loop, file IO, and use of the standard library.
在不到十行代码中,我已经完成了一个文档。当然,也一定要向新程序员显示所有可用的字符串方法。更重要的是,我已经展示了我可以做的三件非常有趣的事情:变量赋值、循环、文件IO和标准库的使用。
I think you'll agree that this code doesn't dazzle. In fact, it's a little boring. No - actually, it's very boring. But show that code to a new programmer and see if that programmer can't repurpose every part of that script to something much more interesting within the week, if not the day. Sure, it'll be distasteful to you (maybe using this script to make a simple HTML parser), but everything else just takes time and experience.
我想你会同意这段代码不会让你眼花缭乱。事实上,这有点无聊。不——事实上,它很无聊。但是,请将代码展示给一个新的程序员,看看程序员是否不能将脚本的每个部分都重新定位到一个更有趣的星期内,如果不是一天的话。当然,这对您来说是很不舒服的(可能使用这个脚本创建一个简单的HTML解析器),但是其他一切都需要时间和经验。
#19
17
Like most of the other commenters, I started out writing code to solve math problems (or to create graphics for really terrible games that I would design -- things like Indiana Jones versus Zombies).
和大多数其他评论者一样,我开始编写代码来解决数学问题(或者为我设计的非常糟糕的游戏创建图形——比如印第安纳·琼斯和僵尸)。
What really started me (on both math and programming) was going from text based, choose your own adventure style games...to more graphics-based games. I started out coloring graph paper and plotting pixels, until I got into geometry...and discovered how to use equations to plot curves and lines, boxes, etc.
真正让我开始(在数学和编程上)是基于文本的,选择你自己的冒险风格的游戏…基于图形更多游戏。我开始画画纸和画像素,直到我进入几何学…并发现如何用方程来绘制曲线和直线,盒子等。
My point is, I could have really gotten into something like processing ( http://processing.org/ ) where a typical program looks something like this:
我的观点是,我可以真正地进入到处理(http://processing.org/)这样一个典型的程序看起来是这样的:
void setup()
{
size(200, 200);
noStroke();
rectMode(CENTER);
}
void draw()
{
background(51);
fill(255, 204);
rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
fill(255, 204);
int inverseX = width-mouseX;
int inverseY = height-mouseY;
rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
}
To me, this is the "Logo" of the future.
对我来说,这是未来的标志。
There are easy "hello world" examples that can quickly get someone drawing and changing code and seeing how things break and what weird "accidents" can be created...all the way to more advanced interaction and fractal creation...
这里有一些简单的“hello world”例子,可以快速地让人绘制和修改代码,看看事情是如何发生的,还有什么奇怪的“意外”可以被创造出来……一直到更高级的互动和分形创造…
#20
15
You could use a script written with AutoIt, which blurs the line between using a traditional application and programming.
您可以使用用AutoIt编写的脚本,它模糊了使用传统应用程序和编程之间的界限。
E.g. a script which opens notepad and makes their own computer insult them in it and via a message box, and then leaves no trace of its actions:
例如,一个脚本打开记事本,并让他们自己的电脑在它和一个消息框中侮辱他们,然后没有留下任何它的行动的痕迹:
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")
#21
13
I remember when I first started coding loops always impressed me. You write 5 - 10 lines of code (or less) and hundreds (or however many you specify) lines print out. (I learned first in PHP and Java).
我记得当我第一次开始编码循环时,总是给我留下了深刻的印象。您编写5 - 10行代码(或更少)和数百行(或不管您指定的多少)行打印出来。(我首先学习了PHP和Java)。
for( int i = 0; i < 200; i++ )
{
System.out.println( i );
}
#22
13
I think a good place for a student to get started could be Greasemonkey. There are thousands of example scripts on userscripts.org, very good reading material, some of which are very small. Greasemonkey scripts affect web-pages, which the students will already be familiar with using, if not manipulating. Greasemonkey itself offers a very easy way to edit and enable/disable scripts while testing.
我认为一个学生开始学习的好地方可以是Greasemonkey。在userscripts.org上有成千上万的示例脚本,非常好的阅读材料,其中一些非常小。Greasemonkey脚本影响网页,如果不操作的话,学生们已经很熟悉了。Greasemonkey本身提供了一种非常简单的方法来在测试时编辑和启用/禁用脚本。
As an example, here is the "Google Two Columns" script:
例如,这里是“谷歌两列”脚本:
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'; }
#23
10
This is a very rudimentary text-based c# program that simulates the spinning action of a slot machine. It doesn't include different odds of winning or cash payouts, but that could be a nice exercise for the students.
这是一个非常基本的基于文本的c#程序,它模拟了*的旋转动作。它不包括不同的获胜几率或现金支出,但这对学生来说可能是一个很好的练习。
Sorry that it is more than 10 lines.
抱歉,超过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" );
#24
9
With Tcl you have a simple text editor with a save button in about 12 lines of code (but no open, that would take another 8 lines). It works across all standard platforms:
对于Tcl,您有一个简单的文本编辑器,在大约12行代码中有一个save按钮(但没有打开,这将需要另外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
}
}
I realize the goal was 10 lines, so if you want the to stick to 10 lines or less, a simple text editor without load or save is only two lines. That's not too shabby.
我知道目标是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
Execute either of the above blocks of code with "wish filename" on the platform of your choice. Wish comes with most *nix's and the mac but you'll have to install it manually for windows.
在您选择的平台上执行上述代码块中的任意一个“wish filename”。希望有很多*nix和mac,但你必须手动安装windows。
To go a step further, that two line script can also be written in python, though it takes eight lines, still under the 10 line goal:
更进一步,这两行脚本也可以用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()
#25
9
How about a bookmarklet? It would show them how to manipulate something that they use every day (the Internet) without requiring any development tools.
一个书签呢?它将向他们展示如何操作他们每天使用的东西(互联网),而不需要任何开发工具。
#26
8
If you can afford the hardware, using an Arduino board + processing will produce some pretty cool things, though it may be a little advanced for people that may not be interested at all in programming.
如果您能够负担得起硬件,使用Arduino板+处理将会产生一些非常酷的东西,尽管对于那些可能对编程不感兴趣的人来说,它可能有点高级。
#27
8
I wrote about this recently in an article "The Shortest, most useful program I have ever written."
我最近在一篇文章中写道:“这是我写过的最短、最有用的程序。”
Summary: I wrote a 3 line VB6 app back in 1996 that I still use every single day. Once the exe is dropped in the "Send-to" folder. It lets you right click on a file in explorer and send the full path of that file to the clipboard.
总结:我在1996年写了一个3行VB6的应用,我仍然每天使用。一旦exe被丢弃在“发送到”文件夹中。它允许您在浏览器中右键单击文件,并将该文件的完整路径发送到剪贴板。
Public Sub Main()
Clipboard.SetText Command$
End Sub
#28
7
It's interesting that you mention the Mandelbrot set, as creating fractals with GW-BASIC is what sparked my love of programming back in high school (around 1993). Before we started learning about fractals, we wrote boring standard deviation applications and I still planned to go into journalism.
很有趣的是,你提到曼德尔布罗特集,用gwbasic来创建分形,这激发了我在高中时对编程的热爱(1993年左右)。在我们开始学习分形之前,我们编写了无聊的标准偏差应用程序,我仍然打算从事新闻工作。
But once I saw that long, difficult-to-write BASIC program generate "fractal terrain," I was hooked and I never looked back. It changed the way I thought about math, science, computers, and the way I learn.
但是,当我看到那个长而难写的基本程序生成“分形地形”时,我就迷上了它,我再也没有回头。它改变了我对数学、科学、计算机和我学习方式的看法。
I hope you find the program that has the same affect on your students.
我希望你能找到对你的学生有同样影响的项目。
#29
7
wxPython First Steps
import wx
app = wx.App()
wx.Frame(None, -1, 'simple.py').Show()
app.MainLoop()
simple.py frame http://zetcode.com/wxpython/images/simple.jpg
简单。py帧http://zetcode.com/wxpython/images/simple.jpg
#30
6
I'm sure it'd turn into more than 10 lines of code, but have you considered a form based app where pressing the buttons does things like changing the colour of the background or changes the size of the text? This would show them how interactive programs work. It would also show them that they, as programmer, are in complete control of what the computer (program) does.
我确信它会变成10行以上的代码,但是你有没有考虑过一个基于表单的应用程序,按下按钮,比如改变背景颜色或者改变文本的大小?这将向他们展示交互程序是如何工作的。它还将显示,作为程序员,他们完全控制了计算机(程序)所做的工作。
Hopefully it would lead them to make suggestions for other things they could change and then onto other things they might want to do.
希望它能引导他们对其他可能改变的事情提出建议,然后做一些他们可能想做的事情。