Abstract:
Which programming language to learn first?

Created by Peter Kankowski
Last changed
Filed under General

Share on social sitesReddit Digg Delicious Buzz Facebook Twitter

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.

Peter Kankowski
Peter Kankowski

About the author

Peter lives in Siberia, the land of sleeping sun, beautiful mountains, and infinitely deep snow. He likes to program in C with a bit of C++, also in x86 assembly language, Python, and PHP (on Windows platform). He can be reached at kankowski@narod.ru.

37 comments

Peter Kankowski,

I waver between two languages: PHP and Python. PHP is eclectical (and so, bad from didactical point of view), but also very practical and widely used for web programming. Python is cleaner and more well-planned, but still quite exotic. JavaScript is also a good choice, IMHO.

ace,

It's not modern to say this since long ago, but I still think that Basic is the best for the first steps. Of course, later the kid will be disappointed to find out that all other languages are too complicated in comparison. But at least he'll be able to make first steps in real imperative language without having to learn too much unnecessary things at that point, he will be able to think from the start about the algorithms!

My first program in Basic, which I wrote without the computer but even added the features to display results one page at the time, and some other interactive error handlings (even if I didn't know that was so called), was summing the rows and the columns of some 2-d array which was entered by the user element by element. I can still write such program from memory in Basic. Basic is just so simple that very little has to be remembered.

Here's the program, without paginating, checking for too big dimensions, display of the 2d array and the possibility to edit the wrong inputs before the calculation starts etc. All that I really added to this basic code before I had computer to try – and everything worked the first time I typed it in! It's all so simple, and I'd probably fail to write everything correctly in any other language (except for FORTRAN and C, the former is also so simple, the later is already in my reptile part of the brain so that doesn't count) without looking in some help files or googling! What's Python's equivalent to dim a( 100, 100 ) when you're not allowed to install extensions for numerical Python? AFAIK you have to synthesize it from many lists. There's of course array module, good luck explaining all that module stuff to the beginner at that point (I haven't used it so don't ask me)! Or that it has to "import" modules to call basic math functions. Argh. What's equivalent in your proposed language?

dim a( 100, 100 )
dim sumrows( 100 )
dim sumcols( 100 )
input "num of rows ", xdim
input "num of cols ", ydim
for i = 1 to xdim
  for j = 1 to ydim
     input a( i, j )
  next
next
for i = 1 to xdim
  sumrows( i ) = 0
  for j = 1 to ydim
     sumrows( i ) = sumrows( i ) + a( i, j )
  next
next
for j = 1 to ydim
  sumcols( j ) = 0
  for i = 1 to xdim
     sumcols( j ) = sumcols( j ) + a( i, j )
  next
next
print "sums of rows"
for i = 1 to xdim
  print sumrows( i )
next
print "sums of columns"
for j = 1 to ydim
  print sumcols( j )
next

So I had only to learn that dim makes 1d or 2d arrays, input inputs the value, print prints it, and for iterates from the given value up to including the other value. That's really all!

Now let me see the implementation of this on the language you propose! Let's compare them, how many things have to be explained to the beginner before he can produce the program? Can he keep in head all that info that has to be introduced? Does he have to know the difference between doubles and integers (in Basic he doesn't!) Does he have to learn more complex rules of, let's be honest, not really necessary interpunction (like where to put "{" ";" "}" in C)? How many different language construct does he have to understand? How many "native" and "non-native" data types of the language you propose? Etc!

I think Basic is still the simplest programming language that's really useful. In a nice minimalist way – not when there's no something to add but when there's no something to remove and still keep it useful! So starting form this Basic example, you do it for any other language, I'd really like to see a better language, in a already mentioned minimalist sense – how much knowledge is required from somebody before he is able to write such program which works!

Check yourself: try to write in a plain text editor the given program without looking at any references for the language you'd propose, and then to make sure in your head you haven't made any mistake! Only then try to compile it or interpret it. Then let's compare: the number of characters in the program, the number of special characters like "{", "[", ";" in the program etc.

PHP as first language? With $ for every variable? Why in a world? $ was really needed in shell because the content of the variable is text substituted in the line, so you have to mark somehow "replace this what follows with the content of that." Names without $ are actually… wait for it… filehandles(!) in Perl (like, you need them much more often???). I can't believe PHP needed that at all anyhwere outside of strings, if variables in strings are expanded like in Perl. They are there only to make it looking more like Perl. Perl is ugly, and useful, but wouldn't say it's for beginners.

Here's the only place you don't have to use $ in Perl:

open( so, ">abc" ) or die;
print so "I knew it\n";
close( so );

More than that, using these filehandles is major pain in Perl (try passing it to the function), so anybody sane today uses variables there too:

{
  open( $so, ">abc" ) or die;
  print $so "I knew it\n";
}

and even close is implicit. Btw you don't have awk on the list, at least that example is nicer:

BEGIN {
  print "I knew it" >"abc" 
}
ace,

I just glanced some links, first I've thought, this Shlomi guy must have been on drugs when he wrote: "The reason for that is that people who dive right into Assembly, tend to write sub-optimal code because they don't understand well how this code is executed by the processor and how to compile it." How's that, I thought. If you have the assembly instructions you can more or less count the number of clock ticks in your programs! If you know only C then you don't have a clue at all what's under your text. All clueless C++ programmers prove that – they think the second they managed to do an operator overloading their program got faster – hey it's less characters in this line now!

But then I understood – the guy probably wrote article for the 1st of April. Think again about the quoted claim, and then go to: "Final Verdict: All things considered, I'd say that Perl is the best choice now, as Python is too strict and unexpressive."

Brilliant!

Peter Kankowski,

Thanks for the criticism :) The problem with the old Basic is that you cannot do many interesting things with it, e.g., write a web application. (VB .NET can do this, but it requires OOP knowledge.) The learner will have a little motivation to learn the language, because he cannot use it in the modern world.

I agree that Basic was easier to learn than PHP or Python, with less details to keep in head. Multidimensional arrays in Python are too complex, but is it so important? I would devote more teaching time to associative arrays, because they appear more often in real programs.

The best "language" to implement your example program is Excel sheet, where you can correct a wrong number entered in the previous line (the Basic program cannot do this).

Here is a small example to introduce PHP programming:

<?php
 
function factorial($n) {
    $ret = 1;
    for($i = 2; $i <= $n; $i++)
        $ret *= $i;
    return $ret;
}
 
echo '<table>';
for($i = 0; $i < 15; $i++)
    echo '<tr><td>' . $i . '</td><td>' . factorial($i) . '</td></tr>';
echo '</table>';
 
?>

Another example I used to explain cookies to a fellow – a number guessing game:

<?php
    if(!isset($_COOKIE['number']))
        setcookie('number', mt_rand(1,100));
 
    if(isset($_POST['num']) && is_numeric($_POST['num'])) {
        if($_POST['num'] == $_COOKIE['number']) {
            setcookie('number', mt_rand(1,100));
            echo '<b>You are right!</b>' .
                 '<form action="/guess.php" method="post">'.
                 '<input type="submit" value="Play again"></form>';
            exit;
        }
        else if($_COOKIE['number'] > $_POST['num'])
            echo 'The number is bigger';
        else if($_COOKIE['number'] < $_POST['num'])
            echo 'The number is smaller';
    }
?>
<p>Your computer chose a number from 1 to 100. Try to guess the number!</p>
<form action="/guess.php" method="post">
    <input type="text" name="num">
    <input type="submit" value="OK">
</form>

As you can see, PHP is not ideal, but quite easy to understand. The Basic version is not ideal either, with spaghetti-like GOTOs.

Thanks for the critique of the Shlomi's article. I will try to find more competent articles on the subject.

ace,
The best "language" to implement your example program is Excel sheet, where you can correct a wrong number entered in the previous line (the Basic program cannot do this).

Still, more interactive features can be added to the code, I've given the minimal example. The fact that there's some application doing something doesn't mean that therefore nobody has to write a program for that – I don't think that's the valid argument.

The problem with the old Basic is that you cannot do many interesting things with it, e.g., write a web application

Don't we talk about the absolute beginner? Somebody who has to first understand the semantics of "store to I the value of I + 1"? I don't think such person would even want to make a server side web application – how much does he/she has to know additionally for that? HTML, what happens on client, what and when happens on server, cookies as a way to keep the state of something otherwise stateless… Not nice at all…

But as you mention, you can happily program in Basic web pages, if you want to use Microsoft solutions. And even if you don't, there are enough other ones. The quality of other solutions is however disputable as Basic was not considered serious for too long. I admit that I don't know a Basic implementation I'd personally like as the first step language – I don't know how VB NET looks like.

If I'd really start teaching some real beginner now, I'd probably teach him JavaScript (from the command line) as it's already installed on every Windows machine and is quite sane: it doesn't even demand ";" at the end of statement if there's only one in the line (a fact unknown by a lot of people who write about it on the web) it doesn't force you to declare variables or to explicitly convert types. The most unfortunate thing with JavaScript is that it lacks I/O in the language. But it's quite good for 2d arrays:

a = [ [ 1, 2, 3 ], [4,5,6] ]
print( a[1] )
print( a[1][2] )

However, starting with JavaScript has that interesting effect that somebody who starts with it can't imagine that the syntax can be different (he can jump to Java and it still looks similar). I think that's bad, since it leads to language fundamentalism. That's why I voted for Basic, there's chance that somebody who makes first steps with Basic will be more ready to use other languages (different syntaxes) if he is early enough introduced to them.

So maybe the best answer I'd give is: don't keep your beginner with only one language for too long – expose him to more of them as soon as you can, but try not to confuse him too much.

Moreover, I think we have different vision who the beginner is supposed to be? My beginner is somebody who should first come to understand the meaning of something like "I = I + 1" and how to translate some processing he needs to do to some (the simplest possible) language that would allow him to run that. Once he understands the principles he can of course learn other languages to fulfill some specific needs. Why anybody supposes that the tool to make the first steps for something should be the same as the tool for something specific? Should the kid who wishes to be an astronaut only learn to drive a space shuttle or shouldn't he start with a bicycle? I still think the bicycle is the proper start.

So who's your beginner?

The Basic version is not ideal either, with spaghetti-like GOTOs.

I'm certainly against the Basic which depends on line numbers.

Peter Kankowski,
Why anybody supposes that the tool to make the first steps for something should be the same as the tool for something specific?

When you and I learned programming, it was cool by itself. Computers were rare and new. I still remember the awesome atmosphere in my computer class :) Today it's harder to interest kids, because computers and electronic devices are everywhere. As Mikhail Donskoy wrote, programming is no longer a romantic profession, but a routine one.

So I would try something cool and useful: do your own "comment wall" similar to Facebook, create a simple game, read aloud news received via RSS, collect some data from multiple Wikipedia pages, etc. The first programming language should allow doing such things, or else the learner will lose motivation and will not study the second and following languages. Frankly speaking, summing up arrays is not a very interesting example.

One of my favorite examples for novices is a deposit calculator. Say, you have $100 and put in on 11% deposit. How much will you get after N years? It's interesting from many points:

  • for the basic task, you just have to know about variables, power function, and input/output;
  • if you want to print a year-by-year table, you need to learn about loops;
  • if the interest rate is more than 5% higher than the central bank's discount rate, you have to pay a tax in Russia (need to learn about if statement);
  • ideally, calculations should be done in fixed point (explain why floating point is imprecise);
  • the interest can be added monthly or annually (the former is more profitable);
  • there are many related tasks, e.g., if you save up $100 each month, when will you be able to buy a $1000 laptop?
  • you can discuss economical issues such as why do people prefer to buy on credit instead of saving up money. It can be useful for everyday life, not only as an abstract model.
ace,
So I would try something cool and useful: do your own "comment wall" similar to Facebook

From all of "professionals" I worked with last 25 years, I know only a some small percentage that would be able to "do their own comment wall," and out of them, and only much less were able to do that efficiently for the server. It worked good when they were the only user, it collapsed once real clients came.

As far as I understand, you took existing wiki. If programming web sites was suitable for beginners, a professional like you would do this over a few nights? I don't think so. I really don't think server-side web programming is good for first steps in programming.

So your definition of beginner is "somebody that is going to be assigned to develop server-side web code?" OK.

ace,

Here's from the guy that believed Perl is the most convenient language, after he tried Python:

http://xkcd.com/353/

"Programming is fun again," compared to Perl, but in my opinion still is some points clumsy compared to some good aspects of Basic. In my opinion Python has still some "fundamentalist" failures, insisting in some cases on more complex ways (just because they are formally "right") instead to move in the "sanest" direction.

One nice example of this ("I don't care for convenience, only what's right") is when you type exit in interpreter:

>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>> 

So they recognized that you typed the line with exit and pressed enter. There's no other thing you'd want to do then to exit. And they have code to tell you "we know what you want to do but we won't let you, because we want to teach you what we consider is 'right' and we think that the right is that you have to type unnecessary braces or the crtl combination you wouldn't know which" (that depends on platform, in Unix it's ctrl d). Bastards. There are "warts" like this when you develop the code in Python too. It can be made easily saner but they don't add it since they think it's not 'right.'

On another side, Larry Wall on Basic:

http://www.perl.com/pub/a/2007/12/06/soto-11.html

"You could do extreme programming. In fact, I had a college buddy I did pair programming with. We took a compiler writing class together and studied all that fancy stuff from the dragon book. Then of course the professor announced we would be implementing our own language, called PL/0. After thinking about it a while, we announced that we were going to do our project in BASIC. The professor looked at us like were insane. Nobody else in the class was using BASIC. And you know what? Nobody else in the class finished their compiler either. We not only finished but added I/O extensions, and called it PL 0.5. That's rapid prototyping."

Now I'm sure if you'd write some test compiler today, Python would be easier for that than Perl.

Peter Kankowski,
I know only a some small percentage that would be able to "do their own comment wall"

I only proposed what may be interesting and not very hard in my area of competence (web development). If you are more experienced in another field, please feel free to propose other tasks.

As far as I understand, you took existing wiki.

I actually have a plan to rewrite strchr.com from scratch. This wiki has some limitations (especially annoying are delays in updating RSS feed).

Fully agree about exit() in Python. About compilers: have you seen PyPy?

ace,
If you are more experienced in another field, please feel free to propose other tasks.

I've taught only once a guy who didn't do any programming before. He studied economy, was experienced player of casino games, but absolutely wanted to learn… C++. Not anything else. He was a friend so I agreed to make some intensive sessions with him. It was already the time of Windows. But I believed that it's impossible to cover both Windows programming and C++ as language in short time. So I decided to teach him C++ in text mode. And I targeted the area he had a lot of experience – casino games. Using a few special characters and gotoxy to position text cursor, I showed him how to draw cards (as objects), and then showed him how he can develop a real game – a simple computer opponent for Black Jack. First a "fair one," then a "cheating one." Games are nice (like the simple guessing game) because when you use random numbers, you practically program something that's a bit unpredictable. And if you want to demonstrate creation of objects, you introduce them where it really has sense, not "just so" like most of the books do. So he learned most of basic features of C++ and how to program something nontrivial. But once he did all this he concluded that he is not interested in programming. :)

Still I believe games are the most interesting start. But it should be easy to display graphics on the screen. Visualizing anything, including mathematical functions, is also interesting, and the display part should be easy enough.

But back to our discussion – without the vision of the profile of the "beginner", there's no need to think about the best language for him. In my story, the beginner himself insisted that I teach him the language I used for my profession, and he decided he doesn't want that to be his profession.

PyPy

It's interesting, even if they started with making "Python which is interpreted in Python" in fact they only get the real speed gains by producing the C code. Which is the only reasonable way – Python is simply slow. But they write much around like that they intend to obscure that simple fact, when that's really all to it, as far as I understand. So personally I have an impression that they come to their results in a longer way than it would be needed to get the same improvement. But I'm not really surprised – that's the project which got the money to be done for research – anything funded tends to spend more time in not really necessary topics.

Edgar Sánchez,

I think it's important to start with a functional (as opposed to imperative) language, that gives you a cleaner entry point into programming. From this perspective, Haskell is the cleanest of current functional languages. If you find this too unorthodox, I'd say Python but with an emphasis in functional programming. A personal third choice: F#.

Jeffrey Griffin,

Permit me to ramble on for a bit…

For the average person in his or her mid teens and later, Python is superior. However, if I were trying to teach programming concepts to, say, a 6-year-old, I would use LOGO instead, for its superior graphical feedback for the learner.

Note that in the aforementioned teenage to whatever age bracket, Scheme might also be an acceptable choice. The decision to choose between them, however, will depend on how "practical" the learner wants the lesson to be and/or whether or not a Lisp-y language feels comfortable (you'd be surprised how many people are terrified of Lisp syntax). While Lisp is excellent, it might be better to ween someone off of something like Python into Lisp, rather than terrifying the crap out of them at the start.

I notice quite a few people selected C, which I'm sure is out of some attempt to start people "closer" to the hardware. However, this is rather misguided, as one must think at the level of an *absolute* beginner: would you want to be trying to master pointers and malloc/free while figuring out what a while loop does? Would you be able to see the benefit of typing extra crap like variable type declarations just because the compiler "says so", hand-waving all the while (heh) because they aren't advanced enough to have higher-level concepts explained to them? That would be frustrating, to say the least. It probably makes a lot more sense for the newbie to type

x = 4

instead of

int x = 4;

Learning C++ first, however, is little more than sheer stupidity - there's no way the novice would feel comfortable trying to learn a language very few professional programmers can hold in their head. I get tired of newbies being thrown in the line of fire of a bloated, industrial strength language at their first attempt because it's what's 'popular', as if learning programming is just so easy that you can bypass that whole "experience" and "learning" parts and throw average Computer Science students head first into code written in a complex, shitty language.

PHP and Visual Basic are trash, and should be regarded as such. PHP is the programming version of genital herpes: everyone's got it, no one wants it, but the unprepared ignore the side effects, ignorant of the consequences until it's too late. (derrr, "true" == 1 returns true in all languages, right?)

I think an even more important question is, what second language(s) should one learn? In my opinion, after mastering Python, one should move to both C and Lisp, in no particular order. Thus, mastering lower-level programming, a scripting language, and a high level functional language should provide one the necessary background to move onto other things. Only from there should one attempt to use C++ or Java. Yes, what I'm saying is at odds with every Computer Science program everywhere, but if you think about it, my way makes a lot more sense; it takes into account the actual didactic context for learning programming, not just learning something so you can stick it on your resume.

Background: My first programming language(s) that I actually learned well was a mix of Scheme and Python (mostly Python). I had, however, used BASIC somewhat before that, although only as a small child and not in enough concentration to cause permanent damage. (:

Jeffrey Griffin,

Edgar Sánchez:

As much as I would want this to work, I don't think it would, for the simple fact that trying to master Monads for the first time at the keyboard might be a bit much. (:

Peter Kankowski,

I agree, C/C++ is too complex for a novice. A language with dynamic typing (probably even weak dynamic typing) and garbage collection would be a better choice. A novice should not struggle with type system or memory management, he should understand language constructs (assignment, conditions, loops, and functions) first, then learn some primitive algorithms (such as linear and binary search in array, recursion, hash tables, etc.)

Python has its own problems; some of them are mentioned in the comments above.

I started from old Basic, too :)

Jeff Langr,

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,

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,

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,

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,

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,

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,

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,

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,

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,
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.
th3cl41,
i love C
Your name here,
It appears that most people are saying their favorite language is the "best" one to be a person's first language. Nobody is mentioning anything about aptitude or career choice. If the student is planning to write business software in the commercial world, I doubt that I would start them with assembler.

The responses that cite an easy to use development environment that explains syntax errors and catches the various "beginner" programming errors sounds good, but ... Having learned to program using FORTRAN on punch cards, and with limited resources such that I only had about 14 attempts to get an assignment correct, I quickly learned to be meticulous and thorough. I don't see that in the junior programmers today.

IMHO, I think a first language should be one that is available on ALL platforms and has tools available through the public domain. It is a serious career error to become locked into an architecture or operating system. A good software engineer (differentiated from "programmer") will look at the programming language as a carpenter does his tools, as an artist does their brushes and paints.

My choice for "best" first language -- pick the worst (hardest, complicated, etc.) one there is. If you can learn that one and still want more, send me your resume. Otherwise, go get an MBA.
John Wagner,
For a first language, say, one that could be taught in high schools, I would say that Python seems obvious, for its clarity and elegance. In University, Scheme/Racket/Lisp ought to be taught simply because this group emphasizes recursion, and recursive techniques are often the first approaches to try; also, at this time, Discrete mathematics should be clearly made a part of CS. When Data Structures and Machine design are studied, so should C be mastered. But in these courses, previous languages once learned shouldn't be forgotten: a good practice would be to ask of homework in a C class to be translated into last year's Python, as well. Promising students ought to be taught Ocaml or Haskell, or another functional language, as these seem to be the future. Students that are not promising should be shown Java. And the door.
Kevin Whitefoot,
My first language: Basic on remote timesharing computer via acoustic modem and paper tape (LeaseCo? London, 1969?).

Recommended first language: Erlang because it has lightweight processes and encourages you to write parallel code, it is also concise, clear, and useful for real world tasks. It also has some great virtues that can positively influence the way you write code in other languages: no globals, single assignment of variables, etc.

No beginner should ever be asked to learn a language that does not have parallel processes as part of the language. We will never get away from the dumb calculator approach that most of us were taught if we don't start taking parallel processing, multiprocessing, multitasking, distributed computing, cooperative sequential processes, etc., seriously.
Josef,
First, C for its power and simplicity. Then assembly to learn what happens behind the code you write and hardware interfaces. That should do all your programming necessities.

If people start to lose their interests when learning these languages and saying they're too hard. Then they should stop and do something else instead because programming isn't easy. Either they're going to know that soon or soon enough.
Carl,

TCL. TCL starts with a stunningly simple syntax. Originally, everything was a string. Hello World is incredibly simple to write. Ditto for the basic console apps you start off with when learning just about any language. However, from there you can go in some very interesting directions:

* Since source code is data, you can do lots of the cool things Lispers can do, without all the annoying parentheses.

* TCL makes a great scripting language, especially when you consider expect.

* TCL has an easy to learn GUI library (Tk) included which runs on all operating systems.

* TCL is a dead enough language that its features are stable. If you write a TCL example in a textbook, it is still likely work ten years from now.

* And if you want speed later, you can hook TCL up to C or C++.

* And though it is a mostly dead language, it is easy to extend, either using C/C++ or within TCL itself to build your own domain specific language.

* Ousterhout's original book on TCL was wonderful. Haven't seen the later edition.

If you are doing a lot of mathematics, then TCL's need for expr can be annoying, but it is far less annoying than Lisp's bizarre syntax, or that of any stack based language.

Alan,

Programming is never easy.

Learn the most complex high level language.

then go for most complex low level language.

Simplicity never precedes complexity.

Tsaadaasmarino,

Lua, by a wide margin. (www.lua.org). I taught the language to undergrads in an African country in a week. The most readable scripting language, and the fastest, too (www.luajit.org!). And, importantly, a language operating by the principle of 'least surprise'.

Marco van de Voort,

My first language was Basic V2 (C=64), then C=64 asm, short time QB then TP. Still mostly Delphi programmer, but I do C/C++ too.

Given that history, my suggestion is predictable, but admitted, depends on target.

Testing a young kid's interest in programming? Then something scripting and visually appealing.

However once it goes in the direction of a more formal CS education, I like Pascal. (and then a procedural one). Simple syntax, string management and little boilerplate code

for a minimal program. Easy upgrade to C/C++ later.

kirbyfan64sos,

My first was Python. It's actually still my favorite(along with C++).

Simon,

Python is my favourite language by far, but I wouldn't be able to do half the things I can do in Python if I didn't know C. So my vote is learn C first, because almost everything else is written using it, in particular most compilers, BIOSes, operating systems. Some time or another you'll have to use it so why not start with it?

Anonymous,

I used BASIC at first, and it is not bad actually. However, for many programs, C is a good idea, and you should learn C too.

Ben,

As an introductory language I go with Python, but for professionals C is a must. As someone who interviews candidates for junior developer positions it is worrying to see that most newly graduated are seeing JVM as the "native" language of the CPU...

Your name:
Comment:

Please ignore this field: