Ask HN: What programming language should I teach my little brother?

41 points by atestu ↗ HN
My brother is 13 and asked me to teach him "how to code". I really don't know what programming language would be the best to start at this age.

First I thought of C because it will also teach him how the Linux he runs was made. But… I hate C. I personnally learned programming with OCaml and Pascal. I still love OCaml (pattern matching FTW), but it didn't really teach me anything about Unix…

I'm looking for a language that would be easy to learn, with a beautiful syntax, and that would gently introduce a 13 year old to the amazing world of Unix/Linux.

Any ideas?

118 comments

[ 3.8 ms ] story [ 106 ms ] thread
ruby! he will be a rockstar by 16 and we will all thank you
ruby! he will be a rockstar by 16 and we will all thank you
Call me old school, but I would start off with Basic. If he was younger I would recommend Logo. Once he's hooked I would get him into C or pascal.

I can't recommend enough getting him a "Basic Stamp" kit. Seeing how software can control hardware is magical. Then work him up into "Arduino" world in C.

This is not a bad idea. Interfacing with hardware can be really fun, but basic enough that they can be creative.

"Hey, see if you can make those 8 LEDs do like the KITT car!"

BASIC will scar him. You might as well go with ruby or python, you get the same facility and start off with an extensible paradigm.
Why?

I thought BASIC is very good to teach basic programming concept such as Loops, line-by-line execution, etc. Really, for a beginner, one must have that kind of mindset.

1)LET s =10 imparts no further understanding than s=10.

2) Numbering lines for programs is nonsensical.

3) Gotos are bad practice.

4) Most programs consist of more than 1 file.

5) Hello world is just as easy in any other (more useful) language.

Can't think of any more off the head right now, time to eat.

Those are very imperative concepts and while imperative programming is good for some things, a language that teaches and allows for higher-level programming is probably a good idea. Languages like Python and Ruby allow functional and object-oriented programming which are becoming more and more common.
It's tradition.

Didn't we all start with basic, even if just for a little bit?

Yes, and I wish it upon no youth to suffer such a perversion of what programming is again. Better to start them off in m68k assembly, at least they will learn something useful in terms of how a computer works.
Arduino has a nice simplified C language and a friendly and simple IDE. I recommend skipping the Basic Stamp.

Other than that, bare-metal programming on microcontrollers has the advantage that the boy can get a mental picture of the entire machine in his head; not so easy with an SDK of hundreds of megabytes for a modern high-level language.

Ruby.

It's the most human-readable language out there. I personally think that it's a lot easier to get started with the basic concepts of programming like while loops, if statements, etc. It is a lot easier to do those things when you don't have to think about including random libraries and putting everything in specifically named functions (ie. main() or static-something-or-another in JAVA) and what-not.

It's the fastest way to get started.

I would recommend Python or if the Unix/Linux component isn't as important, JavaScript.

JavaScript would allow your brother to share his creations with friends and learning the amazing (and at times frustrating world) world of the web.

I would say Python also. But why do you care about the Unix/Linux component? Better to focus on non-OS specific stuff.

After Python, you could also try teaching him Scala.

Python is a good choice because it is clean, easy to learn, and has a large choice of libraries like pygame. It is important to choose a language that encourages good programming practices. For that reason PHP and Basic are bad choices. Some of the worst code in the world is written in PHP or Basic. I would also stay away from languages like perl.

Avoid languages like C++ or Java because there is so much to learn before you can produce a simple Hello World. There is no reason to learn OOP to do a simple task.

I think JavaScript would be a reasonable second language. He should learn programming firs before having to deal with browsers, the DOM model, and OOP.

I think many of you have completely forgotten what sucked you into hacking.

Here's how to get a kid hooked on programming:

  1. Programming should be fun.
  2. Programming should be fun.
  3. Programming should be fun.
Who really cares if a child isn't using "good programming practices"? When I started writing code, it was downright shameful.

But in time, my internal desire to advance my art led me to nuking my globals and having some kind of naming standard. Eventually I fell in love with elegant languages.

Give the kid a fire. Let him decide if he wants to improve himself over time.

When I started, I just wanted to make games. Not learn Greek. Kids just don't care about Python or Ruby's elegance.

Reinforcing good practice shouldn't need to negatively impact having fun; some would argue that Python's strict enforcement of syntax and structure means one less thing for the kid to worry about deciding for himself, thereby reducing the complexity of learning. When you're just starting out, having some (meaningful) rules in place can be a good thing.
I would suspect a good IDE might be better than a headful of little things a kid has to remember. ("Hey buddy, see how you missed the ; here, better add that!")
Javascript is interesting but it has many quirks and powerful features. I'd say start with Python first, since you can start off with just the language. I actually enjoy writing in Python myself because I feel that it pushes me to stick to coding standards. Also, Python's class-based OOP might make more sense at first to Javascript's prototype system.

Good Javascript programming requires coding differently than you would in Python and C, you have to understand and use strange but cool features like closures and prototypal objects.

Closures aren't that weird, and JavaScript makes them a lot more easy to understand than Python...
Since making stuff should be fun, I'd recommend Python with the Facebook API. It's really easy to learn and allows him to show off to his friends.
I think the ability to "show" something is important for probably 90% of people - that doesn't mean they won't become deeply interested in programming in general, its just that they view it as a means to an end, and I think people underestimate how hard it is for beginners to make something that "works" in a cross platform way, enough to inspire them to keep going anyway.

In some ways I almost think javascript in a browser is enough, you have firebug and its shell, and you can immediately show hacking around etc..

Of course, there are some who the mathematical pleasure is really what they are after, in which case I would think haskell - and it has the bonus of a very simple syntax that really doesn't look like a "programming language" - at least what most people think.

Or go with the PyGame API.
Indeed. Pygame is pretty simple and with only a bit of knowledge one can use it to produce awesome visuals.
And they have good tutorials and documentation.
I'll second python, even though I learned the C route.

I'm a stubborn bastard, only reason I kept going.

Go with Python. I taught my 7-year old nephew Python in an hour, but failed to teach him javascript. There's just too much to type and explain.

Also, it's easier to explain to someone if you have an interpreter going and they can see the results.

Yes, I second that the interpreter is easy to show people basic things. The cocos2d stuff with the interpreter are really informative.
I also recommend Javascript. Go through a tutorial manual (yes, because that is how he will learn without you) and then learn stuff about canvas or use an api like jquery.

There is a lot of explanation for any language, but with javascript there is a compiler/runtime on every computer.

Don't teach him one programming language, because if he wants to be a hacker, he'll need exposure to many.

Ruby or Python is good for a start, because it's easy to debug and you can do simple, cool things with them pretty quickly. Then introduce him to Lisp or Scheme, and finally OCaml or Haskell so he's exposed to good static typing. Save C for later (by the time he's ready for it, he'll be picking languages rather than asking you for advice).

As a teenager, I tried various "real" coding languages - C++, Java, VB (ugh) - but I was never able to get engaged in them. All I wanted to do was build something cool quickly, and none of these languages allowed that without a significant time investment. Then, I tried out PHP. Within a few days, I was building random tools left and right, and having a great time doing it. So, to get him interested, I recommend you choose a language that lets him get results fast.
PHP's how I got into programming too. It's a relatively easy language to learn as it doesn't worry too much about typing and it's syntax leaves a nice bridge to C which could be just what you need.
This is good advice.

I personally thought VB6 did a good job of letting you build something quickly in its day, in spite of its other faults.

Same here, I started with QBasic and VB but never really accomplished anything in them. PHP is when I really started to "do stuff."

These days though, I would recommend teaching him Python or Ruby.

Second on the idea that it should be quick and easy to make useful stuff, but I have to disagree on PHP. Most of the example code out there is terrible, out of date or both. It's very easy to make a mess in PHP.

Python seems to be the teaching language of choice these days, and it lets you do useful stuff without getting in the way. It's certainly not the only language to learn, but I'm inclined to say it should be the first.

Yeah, PHP isn't an excellent language but it does do one thing and do it well. Just 99% of examples or scripts you find are absolutley horrible. Seriously, I've seen blog posts on PHP from IBM which contain bad programming practices.
Let's keep rehashing how a language creates terrible code and how none of it has anything to do with the guy sitting in the chair pushing buttons.

Seriously, can we just nuke this argument?

I'm not sure that this "please think of the children" argument -- the one which asserts that the sight of PHP will forever warp the minds of children and risk turning them into script kiddies, or Blub programmers, or crack addicts -- can be nuked. It's really old. People were apparently using it when I was thirteen -- except that the guilty party back then was not PHP, which was more than a decade in the future, but BASIC. And I obviously didn't know about the controversy at the time, because I was too busy using hunt-and-peck typing to rekey my BASIC apps over and over again. (At the time my school's brand-new Commodore 64s didn't have tape drives, let alone floppies.)

And the kids were alright back then, and they are alright now. Applesoft BASIC makes PHP 5 look like Haskell (we're talking about a language with nothing but global scope, here), but the generation that built the Web grew up using it and it didn't hurt anyone. The smart kids just moved on to better things as they became aware of them.

Teach the kid something fun. For a thirteen year old, that's very likely to be Javascript, Actionscript (i.e. Flash), or PHP, though I certainly might give Shoes or Hackety Hack a try, or maybe this Scratch thing: http://scratch.mit.edu. Try several of these and see if any of them stick. But don't get hung up on the details. The guy is thirteen. There will be plenty of time for him to learn how ugly, fragile, insecure, opaque, and unmaintainable his code is. Try to let him have some fun and get hooked before he's forced to learn the truth. He won't sit still for it, otherwise.

As an occasional reader of The Daily WTF, I don't think it's fair to say that this sort of thing never hurt anyone.

Every language that has been around for a while has its own culture and traditions. The culture of PHP is a better reason to avoid it than the language itself. I spent a lot of time un-learning habits I picked up from languages like PHP and BASIC. I suspect I would know a lot more now if I had started with Smalltalk[0] and not had to waste as much time un-learning bad habits.

[0] Python wasn't around then

There's nothing wrong with PHP 5. As long as he's learning about all the latest stuff, it's a perfect language. It features functional aspects to get him started and then he can graduate to OOP concepts. Since he's learning from scratch, stuff like objects and public/protected/private members might be a little farther down the line. PHP lets you get the basics of variables, arrays, functions, etc. out of the way without having to switch languages or set up some construct you have to ignore until later, when you're more adept at the language.
Perhaps also you can stress which are languages that need APIs to do GUI and other useful stuff and which have the APIs built in.
It's easier to code and deploy using PHP than Python for web-app.

It's easier to code and deply GUI app in VB (and .NET environment).

For a beginner to start coding web-app in Python would be like a non-geek trying out Linux with just command-line.

It's even easier to get started with JavaScript.
Then don't do web-apps. There's nothing wrong with starting doing GUI apps with PyGame or something
(comment deleted)
Since you know OCaml how about teaching him Haskell followed by C? The former should be pretty accessible to a 13 year old and he’ll have a lot of time to wrestle with some of the more difficult concepts like Monads (although I think exposure to them at an early age will make them easier to grok since he doesn’t have to unlearn a bunch of other stuff). I highly recommend Real World Haskell (http://book.realworldhaskell.org/read/) if you do decide to go that route.

Apologies for a (related) tangent but I'm in a very similar situation (except that my little brother is 31). He has more artistic inclinations but in the past he's demonstrated an aptitude for mathematics and is generally good at problem solving. I've been teaching him some basic set theory and number theory in preparation for some actually programming.

My first thought is to teach him one high level language like Lisp followed by a low level language like C. On the other hand, JavaScript (+ HTML) has some of the best of both of those worlds with the added benefit of affording immediate gratification. Any thoughts?

*Admittedly, my bro is a bit more motivated by financial considerations but I do think he will come to appreciate the beauty of programming if it is presented the right way.

Haskell as a first language... I've seen it work, but the learner was a physicist working on his PhD. "Finally a language that makes sense", he said.

For a 13-year-old who has probably not been exposed to much mathematical rigor at school, I would not recommend Haskell, though. Haskell makes it hard to write a program that, as ugly and unmaintainable as it may be, somehow mostly works (e.g. you have to plan ahead which parts of the program may perform I/O).

Therefore, I'd go with an imperative language and reserve Haskell for the day when he asks "is that all there is?".

Those are good points. However, I don't think Haskell is that much harder than something like SQL once you really understand what's going on. Although it's not much more than an informed hypothesis, I do think that a precocious 13 year old could do well with it... but I would definitely teach an imperative language too.
For your brother, I would teach him C before Lisp.

C is mandatory, every programmer knows C, it teaches you about memory management, syscalls… it teaches you how you computer works. Once he gets it, he can start having some fun with the sexiness of Lisp, and he will make less mistake because he knows what's happening behind the scenes. Plus… it's really hard to learn C when you already know Lisp exists. I mean… first you ride a bike, and then a motorcycle.

For my brother, I don't think Haskell is such a good idea. Sure, it's a great language, but maybe too mathematical for his age (he just learned the Thales theorem…).

Thanks for the reply. You mentioned that OCaml was one of your first languages and I guess I assumed that you learned it at a similar age which is not necessarily the case... but that's why I suggested Haskell. Also, I can appreciate that teaching Haskell to a 13 year old can seem a daunting task (for the teacher) but I really do think that under the right tutelage I smart kid could get it (you can get a lot of mileage by just treating it as sort of a SQL dialect). It's also pretty well integrated with at least one Linux distro as far as systems programming goes (http://urchin.earth.li/pipermail/debian-haskell/2006-May/000...).

Good luck with whatever you decide though, he's fortunate to have a brother that's taking the job seriously :)

Why are Monads considered difficult?
They are difficult because the concept is very unfamiliar and abstract. It's also not very easy to see the motivation at first.
Perhaps I am too tainted.

Monads can be motivated as a generalization of a lot of stuff that follows similar rules (the Monad laws). E.g. Lists, Haskell's Maybe (representing success/failure), sequential computation.

As a Haskell beginner it's not so easy to see the generalization between State, Maybe, IO, and especially Lists.

This is exactly the problem.

I realize I'm sounding here like I've been seduced, but I truly don't understand why you would want to teach any first language other than Python.
Do you understand that ruby is similar to python, and some people consider the differences to be advantages?

Also, there are arguments that Lisp is better than everything else. Especially when the goal is to learn something (rather than get a product out the door, which makes it more important to have existing libraries, and to be able to hire people who know the language).

python or ruby are good choices. They can be used to do UNIX scripting, and each one has some really cool modules to do graphic stuff. I'm learning ruby just now, so that i can do GUI programming with shoes, and im using _why's guide: http://poignantguide.net/ruby/index.html

I don't know which one is better for a 13 year old, just pick the one you know better.

Seconding Ruby, just for _why's guide. I've never read anything that makes me so immediately enthusiastic about coding, and it still has that effect when I reread it. I wish I'd known about that as a kid.
I've always liked Chris Pine's tutorial (http://pine.fm/LearnToProgram/), because you can go through them with someone who's paying attention in about two hours. I do love _why for self-teaching, though.

My biggest recommendation, though, is that once the kid has any sort of "foundational" programming language under his belt, you write a Scheme interpreter together, in that language, and then show him that the interpreter you just wrote can run Scheme files that already exist (possibly ones you pre-prepared.) That's the best way, I've found, to burn into someone's head that there's no one-true-language, and to get their mind started experimenting with "what if the language was different in way X? Could I code that?" trains of thought.

I'd also recommend Ruby and suggest you take a look at Shoes (http://shoooes.net/) which makes it very easy to code GUI-apps with all sorts of fun-stuff in them like animations, downloading data from the web, videos.

The most important part in teaching a 13 year old programming is to let him have fun and a give him a sense of achievement. The rest will come.

Also consider Hackety Hack from _why. It is very involving, giving step-by-step instructions and crystal-clear explanations (like TryRuby).

http://hacketyhack.net/reality/

Somebody downvoted this entire thread; no clue why. I've never tried Hackety Hack, but it looks like a really interesting tutorial set. Thanks for the tip!
I played with it a while ago. Not too shabby. Seems perfect for a 13 year old. It's fun and it makes it easy to make something happen.
(comment deleted)
I agree! The poignant guide is perfect for having fun in the reading about it part.

And Ruby has a number of other benefits:

* Easy web frameworks if he wants to get into that (Rails, Merb, Sinatra, Camping, etc)

* Definitely fulfills the "beautiful syntax" part

* shoes for really easy GUI apps (that are portable, so he can show it off to his lame windows-using friends)

* Built-in powerful regexps for that pattern matching you expressed love for

* It's generally something that you'll run from command line, helping with the learning about Linux part

* Lots of cool libraries out there

* Object-Oriented, which at least for me was a very easy thing for me to grasp (especially compared to functional, which I'm currently trying to learn)

* Awesome

Whatever language you choose: write a lot of (small?) shell scripts. This is very unix-y and also easy. The composing of those scripts using unix-pipes also will give him a little bit experience with things like modularity.

Also, I'd choose a language I like and that I'm familiar with. I think OCaml would definitely be a good start. Strongly typed and strict, lots of possibilities for abstraction, it's all pretty cool. Or teach him (and yourself) Haskell using RWH or something.

If you go for an imperative language then Ruby or Python would probably be a good idea. Those languages are really a lot like English and have a lot of momentum. If you go for Ruby, take a look at http://hackety.org/, I think it's awesome for young programmers.

I've given this question lots of thought over the years. I really started loving programming when I found Garry Kitchen's GameMaker. It wasn't very elegant, but it was damn fun.

I'd push him toward PHP.

The goal isn't to make him a great programmer with an amazing language. The goal is to get him doing fun stuff fast, so that he sticks around.

When things are fun, kids stick around.

I'm guessing that many readers here got hooked on a language, not because it was a functional language, but because you could accomplish things quickly.

Introduce him to PHP and work with him on coming up with a very specific project he wants to hammer out. Then you can sit down and walk him through the various phases of putting it together.

I would suggest a language like newlisp (http://newlisp.org), that has enough libraries to do unix scripting. Also, you should consider teaching him awk because it has simple semantics and it will be simpler for him to switch to C later.

Btw, why do you hate C ?

I really hate the syntax, and I may be lazy but I'm sick of memory leaks and stuff. I don't want to spend my time tweaking my program so that it won't take to much resources, etc…

I prefer languages that offers a certain abstraction, languages that allow me to concentrate on the algorithmic part of the program, the core of the application.

i second the newlisp :D

then js+jquery with firebug console as repl

Python and probably a lot of shell scripting. I like zsh a lot.
Ruby.

Give the Why's Poignant Guide and you can't go wrong. Plus he'll love the cartoons, even if he doesn't get the strangely subtle adult humor.

Scratch (http://scratch.mit.edu/) is a good way to learn the basics of putting programs together. It's done visually and it may feel like just a toy, but you can do some pretty cool things, it has a very shallow learning curve, and it can intuitively guide you to learning some important concepts which then have applicability to traditional programming.
My 9 year old son is pretty facile with Scratch, and my 7 year old daughter loves playing with it. I second this recommendation for younger kids.
Logo isn't too bad. It's open source, scheme derived, and very easy to make games (beginners like immediate feedback). http://education.mit.edu/starlogo/

At 13, he may be too old for it, but Logo was one of my first languages back in elementary school, and I remember being very excited that I could write my own galaxian clone in just a day or so.

Otherwise, I would stay away from JavaScript and Ruby (I like them, but they are hard for beginners) and stick with Python.

I recommend NetLogo. It is simple to learn, LISP-inspired, and makes it trivially easy to do all sorts of graphical work. It runs on the JVM.

(I took a class in which we used NetLogo to run agent-based economics simulations. Lots of fun, although the LISPer in you will start to hate it after a while.)

Whatever you teach him, teach him something that you love. You will infect him with your enthusiasm and that matters an order of magnitude more than which language.

Heck, there are plenty of situations where exactly this happened, and the programming language was COBOL or Assembly!

ActionScript was the first programming language I learned. I found some tutorials on how to make games and little by little learned by changing the source code. Being able to create graphics was very rewarding and the popularity of flash made it easy to show my friends what I had done. The feedback loop was very important in keeping me interested in programming.

Project sprouts (http://www.projectsprouts.com) makes it easy to get started in ActionScript and is also a good introduction to writing support scripts in Ruby.

perl, javascript, haskell.

perl: practicality + fanatically helpful community, and it's in unix's dna javascript: nice skill, something you can make money in if you're good, immediate gratification on web pages haskell (or lisp): get some theory in there. i'd vote haskell because of the community

smalltalk, absolutely.
This is how I would go too. And if/when he really likes it and wants to move on, LISP.
(comment deleted)