2010-07-21

Programming languages for beginners.

People occasionally ask me what programming language to learn as a first language.  There is really no good answer to that question and what I recommend has changed over the years.  Rather than outright recommend a language I thought I'd summarize some of the things I think of when recommending a first language.
  • Instant gratification.  Yes, I know this offends the more scholarly programmers, but I think instant gratification is critical.  Positive feedback is immensely important when you are learning and there is nothing more satisfying than seeing software you have written do "real things".  Writing a program that posts to twitter or blinks an LED is a "real thing".  Writing a program that mutates or transforms a list of objects in some clever way is not.
  • Understanding what the program does is vital.  I often see people recommend languages that depend heavily on a deep understanding of more demanding subjects.   If the newcomer can't describe why a program works: effort has been wasted. "You'll get it later" is not a good way to learn.
  • Languages that require a lot of ceremonial fluff distract from what the student should be focusing on.  This applies to everything from how the tools work to syntactic fluff in the language itself.
  • It has to be a "real" language.  As in: a language that is actually used by a significant number of people in paid jobs. 
  • Languages specificly designed for teaching programming are rarely useful.  If they were useful they wouldn't be teaching languages.
  • No oddball or perversely domain-specific languages.
  • Some exposure to a hardware-near language early on can be beneficial, but not as a first language.
In general I think most programmers tend to forget what it was like to learn how to program and they are too colored by their current personal preferences when recommending languages.   It is important to remember that a lot of the things we as more experienced programmers think are cool will make absolutely no sense to someone who lacks our frame of reference.   Save it for later.  Save it for when they are ready to listen and can understand what you say.

Nobody starts learning the violin by having the teacher ram Paganini's 24 Caprices down their throat.

42 comments:

  1. Depending on the person, I recommend learning HTML and CSS (markups that have gratification and usage), then PHP for forms and learning conditionals, arrays and loops. Then Java (or some other compiled OOP language) which is usually the hardest to grasp.

    Teaching through tutorials is the best way I've found to teach first, because at the end they have something to show for it.

    ReplyDelete
  2. strictly speaking HTML is a document markup language, so it doesn't really teach you anything useful about implementing algorithms. unless, of course, by HTML you really mean JavaScript.

    JavaScript is indeed a very interesting language, but the interesting parts are not going to be apparent to a beginner until much later.

    PHP is certainly instant gratification, but it is more a sloppy mashup of borrowed ideas than anything else.

    I wouldn't say that Java as a language is particularly hard to grasp, but the Java community has an amost perverse lust for complexity. They simply can't get enough of it.

    ReplyDelete
  3. C.

    It's a tiny language, the core has like 20 or so functions. It teaches you all the basic constructs, it teaches you that RAM is a real thing that you have to manage and understand, unlike Java.

    The only book you need for 'C' is Kernighan and Ritchie which is a tiny paperback.

    Once 'C' has taught you a lot about how programs work and what really goes on, go and play with VB which is just great for 'instant gratification'.

    ReplyDelete
  4. I'd say Java, Delphi or C#. I think all of them answer the criteria. HTML and PHP are definitely a no-no of you want to teach people from scratch.

    ReplyDelete
  5. My vote would be for Python - http://www.python.org/
    A language designed for programmers by programmers.

    ReplyDelete
  6. I usually recommend C for beginning especially if there is an experienced person (or a good beginners bulletin board).

    You can do all the mistakes with small source codes. The main part of learning how to program is to learn what you should not do - and why!

    If you learn this in "simplified" languages you'll will fall in these traps with much bigger projects. As an unexperienced developer you will not be able to understand why somethings fails within 10000 or 100000 lines of code.

    I gave C courses for java developers: One told me that he now understand what he was doing the time before. And I was a paid Java developer (without any Java experience) where some developers never used something else than java. I was recruited because(!) I was a C++ developer: "C++ developers usually know what they're doing." That was necessary - most time of that job I was debugging the code of the java-only-developers.

    ReplyDelete
  7. When we created Go-Robo as a learners programming environment, we looked at the most frequently used languages and visual programming metaphors used in education. LOGO and it’s derivatives were rejected as being obtuse and archaic, Basic & C# etc. as being too abstract for entry-level, so we created GRIDscript, like Basic but even simpler. What we have observed as baffling most people we have tried to teach programming is the abstractness of what we give them to work with, whether it’s “Hello World” or some simple mathematical function – they majority just glaze over and lose interest. Kids are unimpressed with cursors skidding round the screen; toy cars which are less impressive than those from Tomy and most other tasks we set them. To avoid this we gave them a physical IR controlled robot which they can choreograph. Almost all kids understand dancing; most are turned off by the concept of programming. We’ve had teams of kids from deprived inner-city backgrounds working hard to program, sorry choreograph, their robots. For most of the kids, that’s as far as they’ll get, and in education terms that is more than enough, others will use it as a first step.

    ReplyDelete
  8. I recommend Ruby, very useful, used by a lot of people, quiete readable, errors most of the time are clear to understand also

    ReplyDelete
  9. I concur that scripting languages are a good start. Javascript and pho are really web-only, though, are they not? That requires server setup and a little additional knowledge of web servers. I think the answer to this question depends on the OS in which they spend their time - if Windows, VBScript or Powershell would be great, and in *nix a great start would be shell scripts. While not as powerful as compiled languages, they are indeed "instant" in writing and gratification.

    ReplyDelete
  10. I too think 'C' is a good place to begin with nowadays. When I was in school, we were given an introduction of Quick Basic, and we fiddled around with it a bit, but it was 'C' that gave me more understanding of what I was doing.

    Also, I would digress a bit on the last point you mentioned. I worked a lot on pure assembly language programming (not even a C cross compiler) for micro-controllers during my college days and it helped me gauge how the instructions and APIs would work at the machine level eventually. I think this is of paramount importance and students should be exposed to such stuff early in their computer programming careers.

    ReplyDelete
  11. @Simbosan... RAM is not a real thing, no touch, no smell, no see. Also.. how do you clear the console/terminal in a standard and portable way using C? Instant gratification is all about I/O.

    I started with VB in Excel, then Pascal, then Logo, then some QBasic, then VB6, then C++, then Java, then VB.NET then C#, JavaScript, then some Ruby, then ASM, then MSIL, then Prolog, then PHP, then JSP.

    My favorite? C# but I think VB.NET is better for learning.

    ReplyDelete
  12. I think two good languages for absolute beginners are Ruby and Python. Both have a convenient interactive shell for trying things out, which makes it easier to learn, in my opinion. No need to compile, since an absolute beginner will not know what that means anyway. Instant response (gratification) with no ceremonial fluff. Easy to understand code, popular (i.e. you can even find a job with them!), etc.

    C is probably good for someone who already understands some of the basic concepts of programming. Ruby and/or Python are perfect for learning those basic concepts. (i.e. types, loops, objects, etc.)

    ReplyDelete
  13. C# is the best place to start in my opinion, its a fairly forgiving language and the .Net framework is amazing

    ReplyDelete
  14. I like C as a second language, very important to have the mental exercises of pointers, function pointers, memory allocation and deallocation, and some OS stuff in C.

    I'd have to nominate Python as a first language. Not much you can't do, good OS interaction, and I think the idea of white space breaking up expressions, statements, and blocks is more intuitive to a new programmer than semi-colons and curly braces.

    Languages to avoid: java, php, all but the most carefully put together lessons involving c++, perl. Java has arbitrary nuances that I could see causing impedance to learning new languages, c++ is boring to learn because it's so hard to do IO, perl and php are good languages for a hacker to learn, poor languages for a software engineer.

    ReplyDelete
  15. If you think of instant gratification - definitely PHP + HTML. The great benefits of having instant non-threaded GUIs, and 'classic' (C/Java like) syntax are too big to ignore.

    ReplyDelete
  16. OK I know everybody's going to laugh until the tears run down their legs at this one but for real beginners - absolute beginners with no experience whatsoever and no idea of whether they'll take to it, I'd recommend....
    ...Scratch. Yes, even for grown-ups. See? Told you you'd laugh!
    But it has a lot to recommend it quite apart from the fact that it's free. There's virtually no learning curve and as for instant gratification, you can actually change the code while the program's still running. How instant is that?
    Obviously it isn't used for commercial programming but it does consist of elements found in all "proper" languages and IMO is an excellent starting point, laying the foundations to progress on to "real" programming if any aptitude is shown.

    ReplyDelete
  17. I think you're right about the goal-oriented nature of language learning; if there is no goal and no practical application, it isn't worth learning.

    I wanted to learn to program to meet a goal: write a game. So my dad showed me how to write a game in GW-BASIC on our AT&T PC6300. Admittedly, it was text based. But I kinda have a proclivity for languages anyway.

    Peter Kibble's story is something which I've heard a couple of times from other educators, and appears to be very effective.

    ReplyDelete
  18. Okay I'll cave and say which language I've been recommending as a first language these past couple of years: Python.

    - It is reasonably easy to install where it isn't already installed,
    - you can use it interactively
    - its syntax is fairly simple to understand
    - you can do "real things" in a few lines of code
    - at a fundamental level there is very little "magic" going on,
    - you can "grow with it", meaning that it is suitable for real projects
    - there are some very good books available
    - there are lots of libraries available

    I would also agree that C is a language beginners should be exposed to. Perhaps not as a first language, but definitively somewhere early on. Understanding pointers, memory management etc and being exposed to the "nether regions" of your computer is important. I've come across CS students with good grades who can wax on about esoteric topics in concurrecy and functional programming -- yet have no idea how many bits an object reference or a pointer might occupy (I've had people tell me that a object reference is "about one [eight bit] byte" in size -- which is just astonishing).

    I think the important thing to keep in mind is that learning to program from nothing and learning a new language when you already know one or more programming languages are entirely different things. People forget what it was like to know nothing, and therefore tend to just recommend what they like.

    Actually, I don't even like Python that much. I find Groovy and Scala to be much, much more elegant and rewarding. I do most of my bread and butter programming in Java. I recommend Python because I think it is where i would have like to be directed if I knew nothing of languages today.

    (During the 90s a lot of people suggested throwing SICP at beginners. As a text for beginners it is probably one of the worst pieces of self-congratulatory wankery I have ever read. It is a brilliant example of how to bore 99% of students with no prior experience to tears. If you haven't read it yet, you should. It might teach you something important about hubris)

    ReplyDelete
  19. The Javascript shell (Mozilla) makes the Java VM accessible to javscript, and can be compiled. So you get all the advantages of the Java AWT and the bonus of an interactive scripting environment via Javascript. The opportunities to trash the primary O.S. with a coding mistake typical of newbies is much less of a catastrophe within a restricted virtual machine.

    It is also supporting multi-threading via spawn and sync constructs. Similar to the parallel-lang Cilk++ (Intel CTP) ;)

    ReplyDelete
  20. I nominate Python as first language. Its syntax is clear and easy to understand, and I think it gives most of the power a begginner needs for its early application. C is a must-know nowadays, but I cant nominate it as first language as there is some things very difficult to understand for begginners, specially things related to memory management, Pointer arithmetics and such... I was surprised when I tried to explain a colleage with 10 more experience years than me what pointer arithmetics are. C is not that good for starters.

    ReplyDelete
  21. I'd say it depends on what you plan to do with your programming skills. If you just want to play around and create things for your own personal use, HTML pages might be a good place to start, with Javascript and .CSS added a little later. You can use a text editor to create your pages and load them up to one of the free website hosters (Angelfire is the one I use). A little more work than some other options, but you have the added satisfaction of being able to immediately share your work with friends.

    If you are serious about becoming a programmer, my recommendation would be C#.NET. The VS environment allows for instant gratification; create a form, drag on a couple of buttons, double click to add MessageBox.Show commands and you have a program that does something immediately. The debugger allows you to follow the execution of your code easily. You can go as deep as you want into the language; there are a lot of tutorials that can take you through programming concepts in a clear and logical progression. And at the end of the day, you have knowledge that's worth something to a potential employer, as well as the building blocks that will help you move into other languages.

    ReplyDelete
  22. My first question would be "What do you want to build". If it's a desk, learn carpentry. If it's a web page: HTML, CSS, Javascript..., if it's a desktop app or a web app, get a copy of VS 8 on sale and choose between VB and C and install Php, too. If, as the author states, you want a difficult language that does an awful lot, choose Java.

    ReplyDelete
  23. Instant gratification can take the form of a simple "Hello World". That always gets me going when learning a new language. If it has to lure them in by doing fancy things like "post to twitter" or "turn on LEDs", then I would question the student's desire to learn in the first place.

    That being said, bite the bullet and learn C first. Doesn't mean you have to become an expert, but at least get the hang of null-terminated char arrays, pointers, and understand what a stack and a heap are. This is the basis for all other languages (how many OSs and VMs can you name that are NOT written in C?).

    Learning JavaScript first will only teach you how to write sloppy, undisciplined code. And despite the 'L' in HTML, it is not really a language, it's a document layout specification (how many algorithms can you write in HTML?).

    Don't get me wrong, I love C#, use it every day. But it abstracts away a lot of things we take for granted, and it frustrates me to see other "programmers" who only know higher level languages and have absolutely no clue what's going on under the covers.

    ReplyDelete
  24. SQL, either PL/SQL for Oracel or T-SQL for SQL Server or any other falvor of SQL so long as its SQL.

    Now many will ask why learn SQL when so many develoeprs hate it?

    The reason is if you leanr SQL first, you'll be many steps ahead of %99 of the programmers out there who avoid SQL when they can (because they don't understand it) and so they make the big mistake of trying to use some no-SQL based storage method to store data or they end up writing horrible SQL code.

    If you learn the Set Based nature of SQL before moving on to the OOP world of programming you will find it far easier tow ork with both then if you learn an OOP langauge before tackling SQL.

    SQL is only dificult to those already comfortably settled into the world of OOP.

    ReplyDelete
  25. Python or Java

    ReplyDelete
  26. First, learn the C subset of C++, plus the new and delete operators. Do not rely on any libraries or APIs other than those that expose operating system stuff, such as I/O. Implement your data structures manually.

    Second, learn templates. Implement your data structures generically, by hand, even if you are going to use those templates only once. Only after you have mastered templates, learn STL and Boost.

    Third, learn inline assembly, if only to optimize the inefficient bits of your C++ programs. Now you will understand why vector is different than vector for T other than bool.

    Fourth, learn any Turing-complete declarative language. Get quite used to it (but not too much!) and explore the power of not having to unroll your loops into iterations. Now implement a the most efficient (computer-resource-wise) C++ interpreter for that language that you can.

    Fifth, well, you are officially a programmer and a Real Man! (Yes, even if you are a woman.)

    ReplyDelete
  27. I meant "Now you will understand why vector<bool> works differently than vector>T< for T other than bool.

    ReplyDelete
  28. J from http://www.jsoftware.com

    1. Instant gratification - Check
    2. Minimal requirement is basic understanding of Math.
    3. No fluff - Check
    4. Real Language - I get paid for this and used by a lot of people in academics, actuarial, etc.
    5. Designed to solve problems - Check
    6. Successor of APL
    7. Can be used to control hardware - Check

    ReplyDelete
  29. C++ is not a suitable language for beginners. I am not even sure C++ is a suitable language for most professionals.

    Invariably, when discussing programming languages with die-hard C++ fans they usually end up talking about how great C++ is because there are techniques for mitigating problems that only occur *because of* C++ in the first place.

    It is like saying some viral disease is great because it can be used to create vaccines against the same disease.

    In fact I'd go so far as to say that a strong preference for C++ for solving tasks that can adequately be solved by other languages reveals something about a person's relationship to complexity. People who have a love for complexity rather than healthy respect for it, are not really good candidates for a career in programming.

    Programming is about trying to reduce complexity in whichever form it manifests itself.

    You need only look at Java to see what happens when people who have the wrong sort of attitude towards complexity flock together. While the Java language, the JVM and the standard library are *fairly* okay, there is an abundance of complexity everywhere else. Just look at all the frameworks that exist where each of them are MORE complex than the whole JDK itself.

    C++ is so complex it has not even graduated from trying to figure out the bare fundamentals of providing a _usably_ standardized standard library that people actually use.

    ReplyDelete
  30. Some people have pointed out that I should start by asking "why" someone wants to learn programming or what sort of programs they want to write.

    I am not so sure this is really relevant. If you know nothing about programming you still need to learn the fundamentals. It is of no consequence if what you ultimately want to do is to make a web app or if you want to program microcontrollers.

    (And yes, over the past year I have encountered *more* absolute novices who wanted to learn how to program microcontrollers than people who wanted to write web apps. Go figure. You would be surprised how many people who couldn't tell C from Javascript actually manage to get microcontrollers to do stuff by cobbling together snippets of code they barely understand.)

    When we send our kids to school we defer specialization until they have been taught a range of basic skills. Why would one approach programming any differently?
    Understanding the basic building blocks of languages, resource management, nomenclature, different approaches to the same problem etc. are all important for enabling further study and informed decision when looking into specialization later.

    ReplyDelete
  31. I can't understand why you're so against SICP.

    http://mitpress.mit.edu/sicp/sicp.html

    At least this is coming from a different perspective of 'How to codify a process' rather than 'learn language X' and tiptoe through the minefield of syntax peculiarities, achieving very little in the way of seeing the *bigger picture*

    OK. So lisp-type languages aren't for everyone. But this is a nice introduction to thinking about *how solve* problems, and less about language-tribalism.

    I'm not trying to start another flame war. But...
    imho C++ isn't the greatest language ever. It's a travesty. A nit-picky bastard version of C that does little to reduce software complexity. Or increase understanding of the overall problem. The software industry would have been better off avoiding it all together.

    ReplyDelete
  32. technogeist:

    first off: we are talking about beginners. people with no prior experience and no frame of reference with regard to programming. most people who recommend SICP *have* a frame of reference, and usually a particular kind of frame. the things they think of as important are not necessarily the things that *are* important for someone who needs to find a starting point.

    my problem with SICP is the fact that it is written for a very narrow audience of people who are content with abstract intellectual exercises. it is made worse by the implication that people who find the approach dull are somehow not pure enough. "real programmers" should marvel at the beauty of tail recursion and closures and not bemean their quest for enlightenment by writing software that interacts with the world. the clever manipulation of symbols is holier than the sinful pleasures of IO.

    Lisp type languages are "not for everyone" mostly by virtue of the Lisp _community_ and not the language. It is not an inclusive bunch (unless you are deemed worthy of inclusion)and they are almost averse to soiling their purity by stooping to be a "practical" language.

    Why is it that most popular projects quickly get native libraries for C, Perl, PHP, Java, Python etc...but almost never Lisp? Why is it that Lisp has traditionally not played well with the other kids?

    I agree that C++ is not the greatest language ever. I don't think I have ever seen C++ as anything but a manifestation of pure evil.

    ReplyDelete
  33. I agree with you 100%. C++ is evil.

    Instant gratification is perhaps the biggest driver for maintaining interest when learning programming. Although I don't use BASIC any more, the inline assembler of BBC BASIC was very accessible. Perhaps, picking up an old computer off ebay might also avoid the pitfalls of trashing a user's main PC. Closer to the metal too. Not buried several layers deep in API's.

    My view about lisp is, that I see it in the same vein as Pascal, not intended for serious mainstream use. Personally I love the purity of it, but I'd rather cut off my nuts than use it for anything other than tinkering.

    I think I read somewhere that a popular search engine uses lisp for indexing. So maybe for boring backroom tasks it has found a niche. :D

    Right now, I'm trying to get my head around Ocaml. yet another f*cktional language.
    Parallelism interests me quite a bit these days, but I didn't want to get trapped in a Microshaft world of F#, so I chose the language which F# is based on.

    ReplyDelete
  34. Technogeist:

    As mentioned earlier, there are a lot of people who are into programming microcontrollers these days. And not the types of people you'd expect: artists, musicians, electronics geeks, tinkerers etc. There's a very cool platform called the Arduino that many of these use:

    http://www.arduino.cc/

    It is a really neat device because it makes hacking hardware *really* accessible to the masses at an affordable price. It comes with a simple IDE which essentially uses plain C (avr-gcc behind the scenes).

    (I've been using the Arduino as a prototyping and testing tool while building a CNC machine. I needed something that could send pulse-trains to stepper motor drivers. it took me all of 5 minutes to hack up a very simple program that I could upload to the Arduino and then use a serial connection to send commands to it. Eventually I will use an Arduino to interpret G-code (a language for controlling CNC machines) to run the machine, though for now I use a Linux machine to interpret G-code and control the machine).

    You should have a look. It is an immensely cool gadget.

    As for Lisp, as I said, the language itself is not really the problem. In fact I know several serious, high performance systems that were written in Common Lisp. Among them a stock trading system used by a very reputable brokerage firm and Super Mario 64.

    But Lisp has a people problem. Which means that for the longest time the most mundane things, like network programming, was nonstandard and a royal pain in the ass. (For all I know there is still no standard, but I have observed that people do write more and more network apps in it). When pointing this out to a prominent Lisp hacker I got an earfull. He didn't see the point of having a standardized networking API at all and thought I was being silly for wanting it.

    Lisp has also been plagued by asperger'esque literature. An introductory text I read some time during the 90s managed to not mention a single time how you would perform file IO. Up until that point I had never encountered an introductory text for a language that didn't tell you about something as basic as IO.

    There have been published more and better books since, but Lisp is anything but instant gratification and thus, in my opinion, only suitable for a very small set of beginners. (You don't choose Lisp. Lisp chooses you :-).


    How about having a look at Scala? I am learning Scala these days. I write a lot of concurrent code and I am getting kinda tired of hand-cranking things in Java, so I figured it might be a good idea to see if I can implement at least parts of the system I am working on in Scala. (Though, again, not a language I would recommend for beginners since it presupposes basic knowledge of Java)

    ReplyDelete
  35. I never said C++ was a good language to use in the real world. I just said it is a *great* language to learn how to program, because it teaches you the real complexity behind insert-your-favorite-toy-language and its all powerful standard library.

    A lot can be said on the merits of C++, but it at least has the honor of being the only language ever designed with the aim of being all-in-one, from the lowest level to the highest level. (Bjarne just forgot to not make the language suck!) Just as he tried to create "a better C", someone should try to create "a better C++". For more info: http://apenwarr.ca/log/?m=201007

    ReplyDelete
  36. 1. C
    2. Scheme
    3. Lisp
    4. Haskell
    5. Erlang
    6. Java
    7. Python
    8. Scala

    ReplyDelete
  37. My recommendation would be Python, since Python is somewhat minimalistic in concepts and syntax. The language is dynamically typed what makes the code readable and easy to understand, but Python is strongly typed and doesn't allow ugly things like PHP does. Another important thing is the immediate feedback from the interactive interpreter. That is really good for learning.

    ReplyDelete
  38. I'm considering whether to pick C or Phyton as my first programming language, would anyone give ideas on which one is better?

    ReplyDelete
  39. Peter Young:

    do both. If you have no programming experience I would recommend that you try Python first. Set some achievable goals (like "write a command line twitter client that can post to and list my twitter stream") and make sure that you write programs that do something fun and useful.

    C is a useful language to learn because it exposes you to low level concepts such as pointers, memory allocation as well as how you compile and link programs. All very useful knowledge.
    However, it can be a bit confusing and frustrating to *start* with C because you will be faced with programs that misbehave and it can be really hard to understand why they misbehave. This can easily kill enthusiasm.

    ReplyDelete
  40. How can I keep the output console window MS Visual C++ 2010 express open, so I can view the correct output of my programm?

    ReplyDelete