Monday, November 9, 2009

Why has this got so much harder to do?

Behold, in its full glory, a program that I ran on my ZX Spectrum nearly 30 years ago:

10 FOR n=0 TO 255
20 PLOT n,88+80*SIN (n/128*PI)
30 NEXT n

It plots the mathematical function sin over a full turn. This little program was an inspiration to me. It was followed quickly by a program to plot cos, which looks very similar. The next one plotted points of the form (cos t, sin t) with t between -pi and pi, which looks like a circle.

It's no exaggeration to say that this program turned me on to mathematics.

At school at about the same time, we'd been going over sin and cos and tan, which were names for the ratios of the sides of right-angled triangles. I'd never seen anything so boring and pointless. There were all sorts of stupid rules for remembering which was which, and when some were supposed to be positive and negative. It was the dullest thing in the world.

And then suddenly it wasn't. SIN and COS were things I could use to draw circles on my computer screen. If I plotted (2*sin, cos), I could make ovals. It was all marvellous. It was obvious what SIN and COS were. They were the distances across and up from the centre of the circle as you were going round it.

Once you knew that, all the blether at school didn't just make sense, it was obvious. I couldn't understand why it had seemed hard. I still didn't see what it was for. But I was very interested in drawing things on my computer. And circles were a big part of that.

A bit later on, for a game, I used my computer to draw a cannonball as it flew. I figured that it would start off going right and up at a certain speed. After a tiny bit, it would have moved, but the speed it was moving up would have gone down a bit. I wrote a program to draw what happened as time went on. It turned out that it made a sort of arc shape like the underside of a bridge.

And a bit later, I worked out how it would change if instead of the cannonball always falling downwards, it always fell towards a certain point on the screen.

A bit later I was watching the moon go round the earth as the earth went round the sun.

When, about five years later, we got to projectiles and ballistics in A level maths, I already knew all the answers.

And when it came to orbital mechanics during my degree, I had a pretty good intuitive grasp.

And it turned out that sin and cos were pretty useful too.




The reason that I mention this is that 27 years ago, a twelve year old child with a new toy and a shiny orange paperback that told him how to use it could draw the graph of sin, and then play with the program to get more interesting programs.

Whereas now, in 2009, a forty year old professional computer programmer sitting in front of a box at least 1000 times more powerful with a screen one hundred times the size that can display millions of colours is having to google for how to do it. (I am trying to write a simulation of an imaginary diffusion equation.)

And answers are not easy to come by. One of the things that google offered up by way of answer was the ZX Spectrum manual. And childhood memories came flooding back.

And I wonder how the hell a modern twelve year old is supposed to write his orrery.







--------------------------------------------------------------------------------
Footnotes

P.S. I posted this on hacker news and it got some interesting responses:
http://news.ycombinator.com/item?id=930752


P.P.S. So I posted it on reddit too, where one answer was (in python)

>>> import turtle
>>> turtle.forward(100)

And this led me to:
http://us.pycon.org/2009/conference/schedule/event/65/
and (I hate to link to a ppt, but it's great)
http://us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-PyCon2009.ppt
Which answers my rhetorical question about as well as it could be answered!

52 comments:

  1. I completely agree with you!!
    Have just remembered my childhood - first ZX Spectrum 48k, then 256k model (Scorpion with shadow debugger).
    Tapes, assembler and lastly floppy disks!!!
    So, it was really nice time of our childhood... :)

    ReplyDelete
  2. We definitively have to do more to make programming accessible to kids.

    Anyone knows how to get BASIC or LOGO running on a Nintendo Wii?

    ReplyDelete
  3. I had the exact same experience with SIN, COS, Basic, and math teachers.

    Also, It's sad that we have to resort to something as complex as GNUPlot now, to do something that took 3 lines of code 30 years ago.

    ReplyDelete
  4. Oh man, check out hackety hack or processing. Seems to me the important part is getting this kind of information into the hands of people who are "accidental teachers," as _why puts it. In other words, people who's own excitement rubs of on the young people around them.

    ReplyDelete
  5. hm, i don't agree. it depends on the language.. if you start with something like basic, python or specialized language+IDE packages like processing then programming is easier than it ever was.

    there are always teams of 8-12 year olds in pyweek.

    ReplyDelete
  6. Nice post. I remember growing up I was playing on the Internet and found a 10 chapter book online for QBASIC. I printed it out and had it scattered all over the floor, and in no time at all I was writing code that actually did things. I had never written code before and I was in elementary school (9 or 10?).

    Eventually this led to html, javascript, php, VB, C#, etc. Dad wasn't real thrilled when he realized I used all of the printer ink to do this, but I'd say it was a pretty good return on his investment.

    ReplyDelete
  7. +1 to checking out Processing.org. When it inspired me to re-learn trig, I had the same experience: "wow, this is useful, and fun! It was NEVER like this in school!"

    ReplyDelete
  8. I agree that the barrier to entry in some CS disciplines are higher now than they were before (I'm of the QBASIC generation too). But in other ways there are no barriers at all (remember doing GUIs in QBASIC? Now think about Cocoa, Cappucino, Swing, Qt, ExtJS, ad infinitum).

    ReplyDelete
  9. There is 3 good alternatives to kids these days:
    eToys, or smalltalk for children (idea by alan kay)

    sugar on a stick (and olpc): A whole system made for children and you can edit the source to all programs (in Python) and see them run with your modifications (that can be easily shared or reverted).

    Python + Turtle module: A good alternative if you want your kids to have a good path with the same language to produce more interesting stuff (like real programs).

    Although I really like Python I think every programmer should learn more than one language so the eToys is probably what I would show to a very young kid. Python + turtle module is a good alternative to older kids or someone who don't know programming and that will go very fast from zero knowledge to making useful complete programs.

    ReplyDelete
  10. Somebody tackled this a few years ago. This is an interesting read, I think.

    http://davidbau.com/archives/2005/07/27/a_programming_question.html

    The author uses Python to teach his son of 6 a thing or two :-)

    ReplyDelete
  11. If you want more recent experience, I've had pretty much the same kind of experience with maths, and I'm 16 year old (not forty ;p)
    A friend of mine showed me the editor for Warcraft 3. I started making maps and tinkering with the editor to the point I got to learn it's custom scripting language (it's called JASS)... I remember doing exact the same thing manipulating game objects to form pretty partterns, sike sine or cosine graphs.

    It really sparkled me an interest in maths and got me to learn other programming languages, like C and Java. It was really worth it... when I were introduced electrostatics, the first thing I did when I got home was to make a program to plot point-like charges, electric potential fields, etc.

    I really think that pŕogramming is a really really powerful educational instrument that isn't being used anywhere. It messes with everything from logics, creativity, maths, you name it. And for who's been into it, you know: it's just awesome.

    ReplyDelete
  12. Check out http://scratch.mit.edu/

    This is when Eclipse IDE conjoins with SourceForge and YouTube.

    An interactive programming environment for kids who can then upload and share programs.

    The site has 500,000 programs built by about 88,000 contributors.

    ReplyDelete
  13. It's not just children, even adults otherwise employed in technical positions, cannot compile programs or think critically about how and why a computer does any given thing. All most technical people know is how to get programs to do things, how microsoft does stuff. We have a highly paid contractor here who's answer to almost every non-trivial user problem is to reinstall the O/S.

    It's good to be a geek, but we are in a shrinking minority, indeed our very existence is but a quirk of fate, we got into something at it's popular inception and that gave us a head start & in many cases a career.

    I don't mean this to be bleak, but unless we actively teach "the joys of finding things out" to our children & spouses, then what hope is there for those that come after us, if all they have is google.

    No, that's not a typo.

    ReplyDelete
  14. Microsoft Small Basic

    http://msdn.microsoft.com/en-us/devlabs/cc950524.aspx

    (Which is where you end up if you go to http://smallbasic.com/ )

    ReplyDelete
  15. For me it was the other way around; I realized once I took trig how I could use that on the computer to create rotating vector graphics. But the interaction between coding toys using math and taking math definitely helped me learn the subject.

    ReplyDelete
  16. Code has given me the ability to do a large amount of my physics and math homework; watching a function actually approach a limit gives you a much greater understanding than hearing a teacher "whamp whamp whaaa" on about it, for sure. I only wish I used computers less; it's rough to take the tests by hand when you code all your problems in Lisp at home. :P

    ReplyDelete
  17. Another thought: maybe this is why they require programmable graphing calculators in most math classes these days. Perhaps not at a young enough age, and then there's the problem that there is no programming required to graph an equation like sin(x), so you don't gain a greater understanding of its meaning that way.

    ReplyDelete
  18. @Ret, @Marshall
    I'm glad there's still a way in. You guys are going to enjoy yourselves!

    @labelreader
    graph(sin(x)) *is* programming, as long as you're allowed to compose the primitives. That's probably good enough.

    ReplyDelete
  19. I don't agree that programming has gotten harder, I think it has become easier. What is harder now is finding material to learn programming that is simple for kids but also still "real" programming (not just game creation kits).

    I wrote a freely available book called "Invent Your Own Computer Games with Python" and released it under a Creative Commons license. It's available at http://inventwithpython.com

    I think Python makes a great (even superior) replacement for BASIC. Adding in Pygame, and it is much easier and fun to learn programming.

    ReplyDelete
  20. It's pretty painless to do in Scheme, too. Especially PLT Scheme. Import some teach packs, write a one line function and you're done.

    ReplyDelete
  21. Oh, memories!

    What you have just described was my same experience. Only difference, I had a ZX-81 and the graphics were a lot uglier. Then I get an Atari 800XL. I played with SIN and COS, and I made simulation of gravity (for one reason I still can understand all my planets ended in a collision with the sun or they ran away).

    ReplyDelete
  22. dude

    http://www.ngbasic.com

    sweeeet

    ReplyDelete
  23. http://phrogram.com

    Program Sin
    Method Main()
    Define n As Integer
    For n=0 To 255
    PutPixel(n, 88+80*SIN (n * PI / 128))
    Next
    End Method
    End Program

    ReplyDelete
  24. When I started programming on a commodore 64, my dad hacked SAM for me. (software automated mouth). and I wrote some "talking" game shows for it. Know why I did it?

    There was one tv in the house with only 5 channels. 3 big networks, a horrible uhf channel and pbs. It didn't matter anyway, my parents were watching it.

    Point is, kids might write a program if thats all they had to do. Burn your televisions and we might have a chance to raise a productive next generation.

    ReplyDelete
  25. Change .ppt link to a google viewer link?

    https://docs.google.com/viewer?pli=1

    ReplyDelete
  26. What about "Alice"? My kids are literally making games and movies and learning object oriented programming at the same time. It's still out there it's just not as "basic" as it used to be.

    ReplyDelete
  27. Wow. I could have written the exact same thing, with one exception: s/ZX Spectrum/Amstrad CPC/g.

    ReplyDelete
  28. nodebox! that's what I used to teach my wife what it really means to program. Very similar to processing, but in python.

    ReplyDelete
  29. Final word in awesome programming:

    COLOBOT

    http://www.ceebot.com/colobot

    ReplyDelete
  30. i know exactly what you mean! btw im 39 as well

    ReplyDelete
  31. The issue is mostly the growing complexity of the O/S. Back in the ZX80 (my) days; the computer was it's program; even the early PC would boot to basic if DOS wasn't present.
    In order to put stuff on the screen, a multitasking OS has to let you-- so the language has to provide the environment for you to do this-- you don't have complete control of the machine. It tends to make things more complex; setting up graphics contexts and so on.
    And there's so many different ways to do it that none have the same base as the old C-64, and BASIC.
    Learning to program the zx80, i used a book of basic games written for another machine (the trs-80?). Had to work out alternatives for all sorts of things-- but the essential language was the same.
    Lack of options makes things easier.

    There's a nice article somewhere about how when programming was really hard, everyone wrote their own O/S. Now it's easy, no one does.

    ReplyDelete
  32. I think more and more kids start programming these days. I'm a little over half your age, but my start was similar (drawing 4 circles and a rectangle that looked like a truck on a HC with Z80).
    Now, 12 year old kids do stuff I couldn't even imagine at that time.

    ReplyDelete
  33. For me; Ive found Scratch is easy to introduce kids into programming. Im using it at a Youth Centre computer lab to get kids involved in writing their own little web based games. After that, Im hoping to use Arduino to get them a little more interested in the code side of things. From there on, python would probably be a good stepping stone.

    ReplyDelete
  34. "And I wonder how the hell a modern twelve year old is supposed to write his orrery."

    On a graphing calculator, which has computing power comparable to the ZX Spectrum. That's how I and many others my age began programming, at least. For a while, since graphing calculators were all but required for high school math courses, this even made simplistic platforms even more accessible. But the dawn of Texas Instrument's latest calculator family (TI Nspire) stymies all of that, as its BASIC provides little functionality beyond text-displaying.

    I believe that efforts to invite young people to the world of programming should focus on small platforms like these.

    ReplyDelete
  35. Well, this field has matured quite a bit and isn't as accessible to hobbyists. Much like radio was in the 1900s. You think you got it bad, try being interested in electronics!

    ReplyDelete
  36. I had a very similar experience using Apple's Grapher on my Mac. Don't worry, plenty of kids still falling into programming.

    ReplyDelete
  37. Here is a slightly modified version of your program which will work in "SmallBASIC" - http://smallbasic.sourceforge.net

    10 FOR n=0 TO 255
    20 PLOT n,88+80 use SIN (n/128*PI)
    30 NEXT n

    ReplyDelete
  38. I learned quite recently comparatively. I had a box running Windows XP. My dad installed a C Compiler when I asked, after I found a "how stuff works" Article on it.

    That was back in about 2003. I'm currently studying towards a masters in mathematics with computer science.

    ReplyDelete
  39. I grew up in the basic era as well... it's not so much about the LoC for things like this as much as it is the lines of text in beginner books. In those days there were pamphlets and sub-100 page paperbacks on programming in basic. Where half of the book was taken up by code listings. It seems these days that everything has gotten overly long and therefore too hard to start on.

    I don't doubt that there are short intro texts (offline and on) that can get kids started with something that ships with a Mac (like python or ruby), but 'back in the day' short texts were the norm not the exception.

    Also, where is today's Byte magazine or Compute! for example? ...
    I don't have any answers or any young minds (under college age) to influence, so... who knows?!

    ReplyDelete
  40. Very similar experience here. I learnt trig in about grade 4, to solve a programming problem. I had written a worm/snake game, and wanted the worms to be able to move in any direction - not just the 4 cardinal directions. Ever since then, sin has always been strongly associated with computing a y coordinate from an angle. y_new = y_old + sin(angle) * speed, and all that.

    ReplyDelete
  41. I'd just like to say that I'm 17, and I grew up with an almost identical experience--but using my TI-83 calculator. I made some really fun stuff on there, and even (tried) making some stuff using assembly for it. I learned a lot, and it's what really got me into video game development. It also taught me Sin and Cos exactly the same way it did for you, heheh.

    ReplyDelete
  42. I think the biggest difference is the transparency of the technology. Modern software is so "user friendly" that you have no intuition for what's actually happening at the machine level. But this is all relative. Talk to someone who grew up on the Altair - they'll probably reminisce about the time when learning computers meant learning a thing or two about logic gates and transistors. The thing is, computers weren't as common when I was a kid, but I begged my parents to get one and then I learned to program on it. If kids are interested they'll find something similar. The first thing that comes to mind (and something I would have killed for as a kid) is the Arduino.

    ReplyDelete
  43. I know everyone hates MS, but :
    http://msdn.microsoft.com/en-us/beginner/default.aspx

    ReplyDelete
  44. Kids should be given the lazy foo and nehe tutorials when they turn 12. I wish they had been around when I was that age.

    ReplyDelete
  45. You can do this very simple in the R programming language:

    x = seq( from = 0, to = 255, by = 1 )
    y = 88 + 80*sin( n / 128 * pi )
    plot( x, y, type = "l" )

    R is a wonderful tool for visualizing data, and I wish that I had known about it in high school and college.

    ReplyDelete
  46. An amlost identical experience for me! But imo this is why most kids (who would otherwise) dont program - COD2 etc.

    (/me wishes hed never bought the console)

    ReplyDelete
  47. I absolutely disagree. That contrived example was easy to make on the particular platform you were at. There are other contrived examples that are trivial today and were impossible back then.

    Saying that programming was easier 20 years ago is like saying building airplanes was easier 100 years because you could build something Write-brothers-level and today a 474 is so complex.

    You can do something similar with canvas in HTML:


    ctx = document.getElementById('screen').getContext('2d');
    for (i=0; i < 2000; i++) ctx.fillRect(50*Math.cos(i/100) + 100, 50*Math.sin(i/100) + 100, 1, 1);


    or you can do stuff as simple as that but much more impressive in E-Toys.

    The learning tools for programming today are amazing, and the tools for building useful applications are amazing as well (I can crack applications in a week that would have taken months in 1995). There are two differences though: the tools for learning and working are not exactly the same (like in any other profession) and the average computer doesn't bring any of those (like any other device we buy, a car or a toaster; neither explains you how it works inside or allows you to build new ones).

    In the days of ZX Spectrum (and by the way, a clon of that was my first computer) most children were alone struggling to make programs work with very little information. Today there's a lot of support on-line and a lot of information.

    ReplyDelete
  48. I'd argue it's got easier - try Scratch - http://scratch.mit.edu/ - for example this "sine wave graphic constructor" http://scratch.mit.edu/projects/starkiller2/99493 ( needs java plugin )

    ReplyDelete
  49. //Processing 1.0 code
    size(255,180);
    for(float n = 0; n<256; n=n+1 ){
    point(n,88+80*sin(n/128*PI));
    };
    //But I know what you mean
    //I like freebasic for writing simple fast stuff
    //that I would otherwise wind up using C for

    ReplyDelete
  50. @Daniel: My Curly Logo does, technically, run on the Wii. In the Opera browser. But it's not exactly ready for Prime Time.

    It is however, as simple to access as I could possibly make it in this day and age: got to a web page; start programming. No installation, no download, yadda yadda.

    ReplyDelete
  51. Very True. Kids should have access to easy programming tools without complexities of setting IDE etc., We have comeup with new format "iPUB" for interactive programming books at http://roorky.com. Readers can execute code snippets straighaway from the book as well as edit them.

    Let us know what you guys think about the idea and product.

    PK
    http://roorky.com
    Interactive Programming Books

    ReplyDelete

Followers