Abstract:
What programming language to learn first?

Created 5 months ago by Peter Kankowski
Last changed 3 months ago
Filed under General

Discussion: the first language

Poll results: Python - 24%, C - 23%, Basic - 10%, C++ - 9%, Java - 7%, Lisp/Scheme - 7%

What programming language should be learned first? And what was your first programming language?

Some articles on the topic

Questions

What are the criteria for choosing the first programming language? What language would you use if you wanted to teach programming to your kid? Why? And what was your own first programming language?

Your feedback is welcomed. Please use the comment form below.

24 comments

Ten recent comments are shown below. Show all comments

Jeff Langr, 5 months ago

Ruby, maybe; Smalltalk (although there are almost no jobs left in it). D if you're insistent that every language must look like C in some manner but don't want the ludicrousness of C++.

david mercer, 5 months ago

ok, i'm going to go out on a limb here and give my standard advice for a first language for someone with a totally virgin mind so far as programming…FORTH, with a copy of Leo Brodie's "Starting Forth" in hand.

rationale:

1) it teachs low level machine concepts in a friendly, gentle way. they'll know what's going on down underneath all those layers of abstraction in the higher level ones they'll move to next and get 'real work' done in.

2) the 'weird' syntax is only weird if you've been exposed to other languages before.

3) i've had both children and english majors come away from working through that book able to pick up other labguages quite easily

4) it has meta-programming equivalent to lisp-macros, and your programs get higher level as you build them. the 'beginners mind' of a programming virgin tends to find the 'everything is a word, you just make up new words' metaphor very easy to grasp

then if they are serious about continuing to program, get them dr. scheme and a copy of SICP and only after that turn them loose on more commercially relavant thinga like perl, python,java or javascript.

'Starting forth' and SICP are of course free online, and weirdly enough lisp and forth and almost mirror image theoretical equivalents, at high and low levels respectively (macros and compiling words altering the language itself).

i've found that they give raw beginners a much better grasp of machine architecture (brodie just slips it in there without letting on that he's doing it :-) and sicp just straight on lets you 'think right' about how to do things.

polluting the virgin programmer with imperitive/oop languages seems to solidify some bad, concrete mental habits that are hard to break out of…and forth and lisp are only 'weird' if you've been tainted by the other stuff first.

and i'd also be in favor of starting them off with LOGO, that wonderfully 'stealth lisp' too, i've just not found as good of texts for them to work through on their own as 'starting forth' and sicp.

after those two the rest is so easy to pick up, although they'll chafe at the lack of flexibility and meta-programming in the popular langs mentioned above that are popular in commercial settings.

i've taken a number of folks down this path with great success.

Peter Kankowski, 5 months ago

Thank you for your comment. Here is an interview with Forth creator and similar interviews with other language authors (including Bjarne Stroustrup, Guido Van Rossum, Alfred V. Aho, and Brian Kernighan).

To Ace:

PyPy: in fact they only get the real speed gains by producing the C code.

I agree that it's very complicated. PyPy can compile a restricted subset of Python not only to C code, but also to .NET and Java bytecode. A couple of years ago, they also had a LLVM backend, but its support was discontinued.

LLVM is an interesting project by itself (basically it's a p-code that can be optimized and analyzed; their optimizer saves some time for a compiler developer).

I once taught web programming in PHP to a fellow. He has a little experience in Pascal/Delphi, so I started from showing the syntax differences. Almost all learning was based on examples from my past projects.

IMHO, real-world examples are essential to motivate the learner. I never understood where OOP could be useful when it was explained with cats and dogs (or, worse, foo and bar). You should pose a problem, then show a language feature that solves it. For example, the problem is making clickable links from URLs. Try to do it with strstr() and substr()! Then explain regular expressions and show how useful they are for this task.

My Full Name, 4 months ago

x86 Assembler, start from basics to uunderstand how the computer works, understand the stack, calling conventions, etc. Then move to C, then C++ or Python.

Peter Kankowski, 4 months ago

I would start from a high-level language such as Python, because it allows to explain basic algorithms without dwelling on the low-level details (calling convention rules, memory allocation, etc.) IMHO, the learning curve is too steep for assembly language; it should be learned as the second or third language.

h4x0r, 3 months ago

Programming is about coping with tediousness and insanity. Therefore, the first computer programming language a person should learn is the following:

http://en.wikipedia.org/wiki/Brainfuck

Just go insane right at the beginning, and get it over with! The interpreter is only 200 bytes!

When they've mastered that, they are ready for:

http://en.wikipedia.org/wiki/Whitespace_%28programming_language%29

To complete their studies in Computer Science, the student should become proficient in:

http://en.wikipedia.org/wiki/Befunge http://en.wikipedia.org/wiki/LOLCODE

Google uses LOLCODE on its mainframes to handle searches relating to cheeseburgers. Microsoft uses Befunge as inspiration for API design. Python and Makefiles use the same technology found in Whitespace to ensure that we don't take invisible characters for granted.

OK… Perhaps I exaggerated the virtues of those languages, and maybe I am mistaken about the role those languages play in the world's biggest software companies.

Actually, in all seriousness, I think C# might be the best contemporary language to learn first. Microsoft Visual C# 2008 Express Edition is free, and is an excellent development environment. The .NET libraries are extensive, uniform in style, and generally well thought out. A person can start the compiler, select the type of program to create (console mode or windowed), and press a single button (after the project selection dialog box is dismissed) to compile and execute the empty program. A person can then type a single line of code (e.g., Console.WriteLine( "Hello, World!" );), and, one click later, see that appear in their console mode program. Or, a person can type g.Clear(Color.Blue); in the Paint() method of their Windows Form, and, one click later, see their windowed program filled with blue. Then they can add g.DrawLine( Pens.White, 0, 0, 100, 100 ); and see a line. (Maybe I got one or two details wrong with those drawing calls, but it really is that simple.) Adding a button to a form is easy, and making that button do something is also easy. But, really, there's plenty of fun to be had with pure console-mode programming. Like many other languages, reading a file in to a variable is a single line of code, like String s = File.ReadAllText("file.txt"); (maybe the function name is not quite right), and reading text in to an array of lines is also easy: String[] s = File.ReadAllLines("file.txt"); (again, maybe that function name is not quite right). Some people LIKE languages that "liberate" people from thinking about types, but I think that's a recipe for future frustration (when people inevitably have to learn the secrets of all the implicit activity of a language to solve mysterious bugs with their programs – e.g., strings being interpreted as integers, integers being interprets as strings, and floats sometimes becoming integers, and data types having both array and associative array properties, etc).

Also, I am no fan of Microsoft, but C# is superior to Java. Java might have generics now, but C# had those since .NET 2.0 (2005). Using C# with platform libraries is trivial, whereas with Java it is a bit of a pain (although maybe in the past few years Java might have made advances in that area). Although novice programmers obviously have no interest in that language feature, such a feature allows other people to provide interfaces to many native libraries the might be very interesting to a novice programmer. For example, maybe a novice programmer thinks it would be fun to write a program to control a robot or get images from a web camera. The ease of providing C# interfaces to external, native libraries means the such C# libraries will be available for the novice C# programmer.

Having said all of that about C#, I do think Java has its merits as a first language, too. But one has to consider the WHOLE programming experience, and Java proves to be annoying in so many ways. Java would be a much more popular and relevant language today if the people who created and updated Java over the past 15 years had given more attention to the programming and end-user experience. The Java SDK and run-time environments should have had a simple version numbering scheme right from the beginning. The stupid CLASSPATH environment variable, and the frequent failure to find classes that are "right in front of its face" (e.g., contained in the same JAR file as the main class), for example, could have been fixed by a more aggressive search for "missing" classes. Forcing a class to be contained in a file having the same name as the class is not so bad, but requiring a directory structure to match a package hierarchy is SOOOOO LAME! Java is also exception crazy, and its fondness for exceptions was imitated by C#. Anyhow, Java could have dominated much harder than it did. Instead, the creators of Java were evidently blind to the extremely annoying and lame aspects of the total experience of using their language. It's the same kind of blindness that allowed the Python developers go ahead with making white space significant, and that allowed Objective-C to exist at all.

h4x0r, 3 months ago

P.S.: I wanted to actually answer the posed questions.

What are the criteria for choosing the first programming language?
  • A development environment that enables a person to edit, execute, and debug programs rapidly, such that the cycle from typing in code, and seeing program output, to going back to typing code, is on the order of seconds.
  • A development environment that explains in detail any syntax errors and run-time errors
  • A development environment that provides easy access to information about the language and the associated libraries
  • Simplicity and intuitive structure to the syntax
  • Ease with which the program can display output and acquire user input
  • The ability to do really cool graphical and auditory things using the available library functions

Even BASIC on the Commodore 64 satisfies these criteria more than Lisp, Haskell, Ocaml, Python, PHP, and Javascript. LOL

What language would you use if you wanted to teach programming to your kid? Why?

C#, because the language makes it easy to do many interesting things, also enforces strict rules regarding program structure and types. Although *some* programming errors reported by interpreters and compilers are merely syntactical, or are mere artifacts of the arbitrary requirements of the language, I think many errors promote critical thinking about the relationships between concepts. Of course, it would be nice to be able to focus on algorithms, rather than on more mundane details, like data types.

PHP, Python, and even Javascript, offer fun and easy activities with arrays, associative arrays, etc, which aren't so simply expressed in C#, but those languages mush your mind.

I think the oldest version of BASIC might be a really good introduction to programming, but only for a week, just for laughs, before switching to C#. The thing about BASIC, with its line numbers, is that it is really easy to understand.

10 PRINT "HELLO"
20 GOTO 10
RUN

That is a great first experience.

People proposing Lisp, F#, Haskell, etc, as a good first language, saying that procedural languages are a bad habit – closing the minds of people who indulge in them, making them unable to understand or appreciate more abstract ideas about "execution" and data types – overlook the rewards of actually doing anything evidently cool! I'm sure some nutcase implemented a video game in Lisp or Haskell, but those languages are better suited for making A.I. textbooks look ugly for a decade and for computing things inefficiently. When a language is forced to introduce "syntactic sugar" to enable people to do practical things, and when a language is forced to compromise on its core features (e.g., allowing some mutability) to not be super annoying, and when a language is not easily used for fast, interactive experiences, then I think that language is LAME.

And what was your own first programming language?

BASIC on the TRS-80 Model III at the local Radio Shack when I was 10 years old. My family was poor, so we couldn't afford to own a personal computer at the time. But the manager at that local Radio Shack store didn't mind that I visited a lot to do programming on the computers they had on display. But in middle school I had access to Apple II computers, which were lots of fun (color drawing functions and speaker tone functions). Then the Commodore 64 computer came out and was only $199. I LOVED THE C64! The games were awesome, and programming graphics and sound on that computer was SO MUCH FUN! Although I already did some assembly language for the Apple II early on in high school, I did much more of that stuff on the C64. I wrote my own floating-point functions in assembly language, and used the numerical integration methods appearing in Feynman's Lectures on Physics to reproduce his planetary motion calculations, and used the C64 sprites to show planets orbiting the Sun. But, wow, the games were awesome. Chopper Command, Bruce Lee, Quasimodo, Forbidden Forest, Montezuma's Revenge, Pogo Joe, Necromancer, Conan the Barbarian, Jumpman, Impossible Mission, etc.

Peter Kankowski, 3 months ago

Thank you very much for your opinion! Old good BASIC was a nice introductory language. My first computer was a cheap Russian clone of ZX Spectrum and I spend a lot of time in my school where "real" computers (IBM PCs) were installed. The teacher was so kind that I could write programs in evening, when there was nobody in the computer class.

LOGO may be good for learning programming, because of its intuitive turtle graphics. Here is a nice e-book and an online interpreter. (However, there is no OOP and first-class functions in LOGO; the syntax for variable assignment is terrible, etc.)

Microsoft has Small Basic language, which is (IMHO) worse than 40-years-old LOGO (no function parameters!)

John McPherson, 2 months ago

I agree with David Mercer, for novice programmers FORTH is pretty hard to beat. The entire metaphor, if taught properly, rapidly gets a beginner up to speed as to what the machine really is and that is by no means a small feat. I know professional programmers with years of experience that still do not understand the fundamental premise upon which the machine is built, logic gates. FORTH, because of its stack orientation is somewhat similar to the way the CPU works. Also, in a stack based system programmers tend to learn good habits. That, coupled with the extensibility of the language through creating new 'words' tends to make learning and understanding easier for novices.

Years ago I was flabbergasted by a program, written in FORTH, for the Apple II computer, Das Fleeter mouse. It was written by a German in FORTH to simulate a bat flying. It was fast, represented the bat as well as it could for that era. But let me say this again, it was FAST. This was on an 8 bit machine (6502) running at 1 MHz with 32 KB of accessable memory! Yeah, the II could have up to 64KB but because the video memory was mapped stating at 8000H the upper memory was virtually useless without patching your way around it. I dissected the code and was amazed at how you could build this simulation in that language by building up a set of 'words'.

I haven't looked at FORTH in probably going on 3 decades, being a profession programmer I am caught up in the Microsoft world, C#, HTML, VB, java, oop, agil, etc. But I do still remember learning how to do this stuff. Fortunately for me the school I attended taught us logic, how to manipulate the CPU and the basics of machine design. Back then we delt with punch cards and had to load them into an IBM 5250 card reader.

My first program of any significance was a loan amortization program written in Fortran 77 on a mainframe using an acoustically coupled teletype. Now I'm dating myself but I am probably the only one I can get a date with!

But, in all seriousness, learning to program is not the easiest thing for most people and when you heap C++, C#, OOP, understanding the machine, Assembly and a whole bunch of other stuff with questionable application on a poor college student who just entered his or her first year of computer science. It can be and very often is, overwhelming.

An introductory course with something like FORTH or Logo or even VB as the language would be a much 'gentler' way to go about it.

Patrick, 24 days ago
x86 assembly, because the person learning it also learns how a CPU works.
Furthermore if a person is able to use the complete x86 instruction set, he is also able to program nearly every other CPU in assembly because most other CPUs only use only a subset of all the x86 instructions available.

If someone can program decently in assembly, the person won't have any problems using pointers, arrays etc. in any HLL. He will also know how to program fast because he knows how the CPU works. He will also know how to use a debugger, if his complier doesn't work properly or if some apps needs some reversing.
Your name:
Comment: