What is the best programming language?

Learning to program in a given language requires a non-trivial amount of time. This seems to be agreed upon as a good use of LessWrongers' time.

Each language may be more useful than others for particular purposes. However, like e.g. the choice of donation to a particular charity, we shouldn't expect the trade-offs of focusing on one versus another not to exist.

Suppose I know nothing about programming... And I want to make a choice about what language to pick up beyond merely what sounds cool at the time. In short I would want to spend my five minutes on the problem before jumping to a solution.

As an example of the dilemma, if I spend my time learning Scheme or Lisp, I will gain a particular kind of skill. It won't be a very directly marketable one, but it could (in theory) make me a better programmer. "Code as lists" is a powerful perspective -- and Eric S. Raymond recommends learning Lisp for this reason.

Forth (or any similar concatenative language) presents a different yet similarly powerful perspective, one which encourages extreme factorization and use of small well-considered definitions of words for frequently reused concepts.

Python encourages object oriented thinking and explicit declaration. Ruby is object oriented and complexity-hiding to the point of being almost magical.

C teaches functions and varying abstraction levels. Javascript is more about the high level abstractions.

If a newbie programmer focuses on any of these they will come out of it a different kind of programmer. If a competent programmer avoids one of these things they will avoid different kinds of costs as well as different kinds of benefits.

Is it better to focus on one path, avoiding contamination from others?

Is it better to explore several simultaneously, to make sure you don't miss the best parts?

Which one results in converting time to dollars the most quickly?

Which one most reliably converts you to a higher value programmer over a longer period of time?

What other caveats are there?

Comments

sorted by
magical algorithm
Highlighting new comments since Today at 9:41 AM
Select new highlight date
Rendering 50/98 comments  show more

As far as I can tell, there is no such thing as a good programmer who knows only one programming language.

There just isn't. The nature of the field is that raw computation is quite alien to ordinary human thought; and that the best way to get anything even remotely resembling a reasonable grasp on it is to come at it from multiple angles.

You should know about functional abstraction, which you're not going to get very much of out of C or Perl, but you might get out of Lisp or Haskell.

You should know something about how the machine operates, which you're not going to get out of Java, Python, or Haskell, but you might get out of C, Forth, or assembly. And reading about the actual architecture you're working on. (It's easier to do this on a dinky architecture. I recommend 8-bit AVR microcontrollers.)

You should be eager to reuse other people's code to solve your problems, which you'll learn from an open-source, big-library language like Python, Perl, or Ruby, but probably not from a small, standardized language like C or Scheme.

You should learn about data structures, which you'll only get deeply if you have to implement them yourself, which is really only something you do in a CS class — but you should also learn about not reimplementing data structures that someone has already done for you better than you can do yourself. You can pick that up in any language with good data-structures libraries, like C++ with STL, Python, Haskell, etc.

You should learn about types as an expressive system and not merely a burden, which you'll get from a strongly-typed, type-inference language like Haskell, but not from a heavyweight manifest-typing language like Java or C++.

You should know how the OS works, which in most systems today you can really only get by learning C. You should know about system calls, the standard library, sockets, and so on. You should know why we don't use gets(3) any more.

You should know about Lisp macros because there's really nothing else comparable in any other language. Template Haskell doesn't really count, and C macros especially don't count.

You should learn about parsing the traditional way; and then learn about monadic parser combinators in Haskell, because they are fucking awesome.

You should know what a buffer overflow is, what a format-string exploit is, what an SQL injection is.

You should know about relational databases. I could go on about relational databases because they are deeply misunderstood by most programmers and actually contain a wealth of hidden awesomeness; but I won't, because it would go on forever, and much smarter people like Chris Date have written it already. Suffice it to say that a relational database is not just a place to stuff variables that you want to keep around for a while; it is a place to stuff facts that you want to draw inferences from. There — that makes it sound suitably AI an' shit.

You should learn how to work with a nontrivial runtime that does things like garbage-collection, which you won't get out of C or C++ but you might get out of Lisp, Java, Python, Ruby, or Go ... if you pay attention.

You should learn about concurrency, which you can maybe get by learning about threads and the like in a language like Python, C++, or Java, but you'll probably learn better in a language like Erlang, Go, or Clojure that treats concurrency as a first-class concern.

Anyway, as should be obvious, computation is big and there is a lot to learn. But you can pretty much jump in anywhere. There's no right or wrong starting point, so long as you keep in mind that it's a starting point. Don't let anyone convince you that their personal pet language or system is all you will ever need. They're just trying to get you to join their phyg, and phygf exist at your expense.

Computing is a field that you can keep doing for a long time and still have lots to learn. This is, in fact, part of what makes it awesome.

I eagerly await the most rational toothpaste thread.

I think it has been mentioned before, but it bears repeating, please don't use "most rational" in titles. Just ask for the best programming language and describe your needs.

Upvoted for being the most rational comment in this thread.

Snark isn't the same as rationality.

Let's break it down, shall we? The comment contains the following three things:

  1. A joke insinuating "rational programming" is the same as "rational toothpaste". No claim is made explicitly, so no rebuttal can be made. This is pure dark arts if you ask me.
  2. Negative instruction: Don't do this. No attempt to explain why.
  3. Positive instruction: Do that instead. Again, no attempt to explain why.

And you think this is more rational than the detailed, respectful, intelligent comments made by people who actually thought about the questions for five minutes and shared their expertise?

I'm appalled.

Maybe it's obvious to you that having "most rational X" in the title is stupid. And to be honest in hindsight it seems a bit silly to me as well, now that I have explicitly thought about the reasons for it. But it wasn't obvious when I wrote it, and it surely isn't self-evident to everybody.

I'm not against setting up norms and rules, and yes they are gonna change on people, and yes people need to be humiliated from time to time for breaking them flagrantly, but it's simply unfair to make humiliating jokes in retaliation for breaking them when there is no actual reason for the person to have known about the norm's existence.

Note that Konkvistador didn't even have a link to a top level post to substantiate the claim that this norm exists, just "I think this has been mentioned before" -- am I supposed to read every comment on LessWrong to see what norms I'm supposed to be following?

Give me a break!

Negative instruction: Don't do this. No attempt to explain why.

Rational is a frequently used but unfortunately more and more meaningless applause light on LessWrong.

Hmm, I guess people that follow most of the discussions here might be overestimating how much "community lore" others are aware of (or they may mistake "opinions shared by a few posters" for "community lore").

For prior discussions of this see here:

We are one step closer to the glorious time when a thread titled "Most rational choice of footwear" will appear.

or here:

This might be the most blatant misuse of "rational" in a post title I've ever seen.

Now that's a challenge ...

  • Rational snorkeling
  • Rational hash brownie preparation¹
  • Rational weasel appreciation
  • Rational captchaloguing
  • Rational cache flushing
  • Rational cash flashing
  • Rational rasher rationing

Most people seem to have liked the suggestion to use "optimal" instead.

Snark isn't the same as rationality.

Forgive my ignorance; so what is the most rational form of humor?

Note: Both of these comments are jokes and were intended to be funny, not snarky punishments for norm-breaking.

It turns out to be fart jokes. I have an elegant proof of this, but it is too long to fit in a comment.

Louis C.K. was deconstructing why farts are funny on the daily show the other day:

  1. They come out of your ass.
  2. They make a trumpet noise.
  3. etc

Argh, I can't believe that went completely over my head in both cases. Now that you've added the italics around "most rational" I can see it.

I think it has been mentioned before, but it bears repeating, please don't use "most rational" in titles.

I haven't seen this advice before. A link would be appreciated.

Edit: The post has been retitled to "what is the best programming language". My main reason for doing so is to avoid confusion as well as dilution of the meaning of the word "rational" -- which should probably be reserved for specific contexts (e.g. avoiding cognitive biases) rather than used as a catch-all for "most optimal" and so forth.

Just ask for the best programming language and describe your needs.

My needs? Well I am already moderately skilled at a dozen or so languages, including Python, SQL, and Forth. My first scripting language was Perl and my first GUI language was REALBasic, which was essentially Visual Basic for the Mac.

Why did I go into Forth? Well, I wanted some down and dirty understanding of what the heck is actually going on in a computer. And I couldn't stick with C long enough to get that for some reason. Now I've done things like creating my own string manipulation functions (by concatenating other functions and primitives). I'm not sure I could have got that from Python.

On the other hand, now when I look at C code slinging pointers and char arrays around it makes perfect sense, and I can also visualize linked lists and other data structures. As a newbie though I remember it was all extremely confusing.

"Rational" is so frequently used as a contentless word that, if I were to have a comment keyword blacklist, it'd be number two on there, right after "status", perhaps followed by "downvote me". Unless you're talking meta (as in the parent comment), I strongly recommend trying to figure out what you actually mean, and use that word. "Rationality" ain't the goal.

I'm pretty sure the short answer is: Become really good at Python. Learn additional languages if you want to solve a problem Python isn't good for, you want to learn programming concepts Python doesn't facilitate, you want to work on a project that isn't in Python, etc.

Rationale:

  • I've seen lots of discussions online about what people think the best introductory programming language is. Python seems to be the clear favorite. (1, 2.)
  • UC Berkeley and MIT both use Python for their introductory CS classes. (Yes, both universities switched away from Scheme.) I don't know much about any other universities.
  • Recently on Hacker News there were polls on what programming languages people like and dislike. Hacker News is the unofficial homepage of programmers everywhere, and thousands participated in these polls. According to two different ways of analyzing the data (1, 2), Python was the most favored language. Note that the poll was for general purpose programming, not best introductory language.
  • In my experience, it's quite valuable to be highly fluent in your chosen language. For me, there seems to be a substantial productivity difference between a language I am fluent in and a language I am mildly familiar with.
  • You can hack on LW.

The answer might change if you're partway invested in learning some other programming language. I don't know if it's worthwhile to restart in midstream or not.

Also, one shouldn't ignore the practical advantages of a batteries-included language (like Python) for enabling you to do things.

For example, if one wants to do some transformation of a spreadsheet which might be tricky or annoying to do in Excel/LibreOffice, one can just import csv and you've got a complete CSV file reader. Similarly, it's an import and 2 function calls to get a file off the internet.

Similarly, it's an import and 2 function calls to get a file off the internet.

I only count one function call:

import requests
f = requests.get(my_url).text

The built-in urllib and urllib2 modules can do this too, but they're a disaster that should be buried in the ground. The general consensus is that requests is the Right Thing. You have to install it, but that should be easy with the pip package manager:

$ pip install requests

By the way, I agree with the recommendation of Python. It's a very easy language to get started with, and it's practical for all sorts of things. YouTube, for example, is mostly written in Python.

Is it better to focus on one path, avoiding contamination from others?

Learning multiple programming languages will broaden your perspective and will make you a better and more flexible programmer over time.

Is it better to explore several simultaneously, to make sure you don't miss the best parts?

If you are new and learning on your own, you should focus on one language at a time. Pick a project to work on and then pick the language you are going to use. I like to code a Mandelbrot set image generator in each language I learn.

Which one results in converting time to dollars the most quickly?

If you make your dollars only from the finished product, then pick the language with the highest productivity for your target platform and problem domain. This will probably be a garbage collecting language with a clean syntax, with a good integrated development environment, and with a large available set of libraries.

Right now this will probably be Python, Java or C#.

If you make your dollars by producing lines of code for a company, then you will want to learn a language that is heavily used. There is generally a large demand for C++, C#, Java, Python, and PHP programmers. Companies in certain domains will focus on other languages like Lisp, Smalltalk and Ada.

Which one most reliably converts you to a higher value programmer over a longer period of time?

No single language will do this in the long run, but you might take temporary advantage of the current rise of Python, or the large install base of Java and C++.

For a broad basic education I suggest:

  • Learn a functional language. Haskell is my first choice; Lisp is my second choice.
  • Learn an object oriented language. Smalltalk has the best OO representation I have come across.
  • Learn a high level imperative language. Based on growth, Python appears to currently be the best choice; Java would be my second choice.
  • Learn an assembly language. Your platform of choice.

If you want to do web-related development:

  • HTML, CSS, Javascript.
  • SQL and relational DB.
  • XML, XSD, and XSLT.
  • C#.NET, Java, Python or PHP.

If you want to do engineering related development:

  • C and C++.
  • Perl
  • SQL
  • Mathematica or Matlab
  • for some domains, LabVIEW

Everyone says you should start with Python. Everyone's right. It's a beautiful language in which you can write good, concise, elegant code. Lots and lots of shops use it.

If you want to learn a second language, to give yourself some sense of the diversity available, I'd recommend Haskell. I think Haskell conplements Python nicely because a) it's nicely designed and b) it's almost nothing at all like python. It's fantastically strict where Python is fantastically permissive. It's functional where Python's object-oriented, etc.

I honestly don't know what the best Python tutorial is -- I learned from a handful. The best Haskell tutorial in the world is Learn You a Haskell for Great Good

The "other" Haskell tutorial is also worth a mention: Real World Haskell. (That said, I prefer LYAH.)

Languages are for completing tasks, and each has varying strengths and weaknesses for different tasks. What specifically do you want to be able to do?

If you are a scientist or engineer who needs to quickly and accurately answer questions from quantitative data or perform statistical inference, R is the way to go. It also has a great interactive command line with powerful data visualization tools and plotting functions. The experience of "playing with" and manipulating data to quickly ask questions, and consider the data in different ways directly from the R command line is amazing.

If you want to do web development, I would recommend Python.

If you want a general low level language to better understand how computers work, or to develop very high performance code I recommend C which is practically a portable assembly language.

Don't waste your time with proprietary languages where without purchasing expensive licenses your code and skill are useless: visual basic, MatLab, etc. unless you're employed by a company that requires it.

In general once you learn a few programming languages, learning new ones becomes easier and easier. For example, as a person proficient in half a dozen other languages I was able to quickly complete big projects in Python without taking any time to explicitly learn it- just by looking at example code, and referencing digital copies of the O'Reilly Python books whenever necessary.

That's a learning strategy I highly recommend: don't waste time just to learn a programming language with tedious examples, just choose a programming project and immediately start learning what you need to know to finish it once step at a time.

R

I've been wanting to learn R. Do you have any reccommendations for tutorials?

I recommend these: Girke Lab R manuals

Full disclosure, I am biased because I co-authored several of those... but I really do think they're quite good. They're oriented primarily towards people that want to do biology/bioinformatics with R.

Bayesian content is in the works...

Just today, there was a post at Coding Horror, which was itself a follow up to another excellent post, about whether or not learning a programming language is a good use of your time. I think you should read those before you get too invested in the idea of teaching yourself how to program.

Learn assembly, C, and Scheme, in that order.

Start by learning assembly for some small, manageable microcontroller, like PIC16 (if they still sell those) or a low-end Atmel, preferably one that you could wire up yourself. Prove to yourself that you can make LEDs light up by writing bits to ports. This will give you a good understanding of what computers actually do behind the scenes.

Follow that up with C, for your desktop machine. Implement some common data structures like linked lists and binary trees (you could do it in assembly as well, but it'd be too annoying). Get a good feeling for pointers, memory allocation, and recursion. Learn what clean syntax feels like.

Finally, learn Scheme, which is a language of pure abstraction completely divorced from any hardware, operating system, or syntax (ok, this isn't 100% true, but it's close). Understand how you can manipulate very simple building looks to build powerful expressions, and how code can be used to generate other code and pass it around. Implement an object-oriented "meta-language" in Scheme.

At this point, you'll be well equipped to learn any other language you want in a manner of days. You will probably never use assembly, C, or Scheme ever again, but which would you rather have -- a single tool, or a factory inside your mind that lets you create tools at will ?

Oh, and stay as far away from C++ as you possibly can, it's pure poison.

I recommend outright reversal of the above process. If you absolutely must learn assembly language, do it once you can already program. The same applies to other excessively low level languages with a lot of emphasis on memory management rather than semantic expression.

I actually started with Basic, then went to Perl, then Python (which I didn't grok all that much at the time), and finally Forth, which is probably lower level than C in some respects but was somehow easier for me to stick with. I tried picking up C and couldn't get past Hello World. With Forth (specifically the RetroForth project -- which was a bit less smooth at the time) I built my own linked lists, dictionaries, string splitters, and stuff like that, using concatenation that maps more or less directly to machine code. Now when I look back at these other languages I see real stuff going on instead of magic. Maybe this is the equivalent of practicing fencing with a weighted sword.

This still misses a few ares. You would not be completely ready to learn OCaml (or Haskell) with sophisticated type inference system. You would probably not be ready to learn Erlang (unless you used something like Termite if your Scheme turned out to be Gambit). If you picked an R5RS Scheme, you would probably miss some parts of the power of macros. You would miss APL/J array processing. You would probably (unless you pay attention to using some Scheme object system) miss SmallTalk object orientation and also multiple dispatch-capable object oriented programming (which is not SmallTalk, but, say Common Lisp Object System).

As for calling C syntax clean... Well...

Anyway, for long-term learning you need to ask what concepts to learn - you will most probably have a choice of languages (but no one specific languages will include all).

If a programming language has nothing new to teach you, it is not worth learning. For this reason, it is probably a good idea to learn multiple ones that are "conceptually orthogonal" to each other. Examples:

lisp (code-as-data, syntax vs semantics, metaprogramming)

prolog (declarative programming)

a simple RISC assembly language (machine details, stack vs heap)

haskell (functional programming, type inference, lazy evaluation, monadic theory, type classes)

ruby (message passing, object oriented programming, regular expressions)

APL (concise syntax, vector programming, non-ascii programs)

If a programming language has nothing new to teach you, it is not worth learning.

Assuming you are a person not influenced by external incentives.

Learning ideas has better ROI than learning tools. It's easy to pick up tools as needed for work, but recognizing ideas/patterns is both a more transportable kind of knowledge and harder to acquire. Also key ideas behind computation do not have a "half-life," whereas tool/tradeschool type knowledge does.

Time to dollars: Python. Ubiquitous, powerful enough, useful for everything, has a friendly learning curve but also a wide variety of concepts in the language.

Highest-value programmer: Probably C, but it's sort of a moot point because I don't think there's a way to become a programmer of above-average value without becoming pretty competent in two or three languages along the way.

Caveats: I'm pretty sure that it varies a great deal based on your inclination and logical ability going in.

A question regarding your title: are you looking for the programming language that best teaches rationalist thinking (if there is one in particular)? Or are you asking for a more general analysis of what the various languages are best at?

Regardless, as a novice programmer (I'm taking my first Java class right now), I would be interested in hearing what LW's opinions are. I chose Java because I wanted to develop Android apps, and because of the large number of jobs calling for Java programmers in my area.

I would like to ask the commentators: what do you think about learning JavaScript as a "first" programming language? I would like to learn to use modern programming technologies and utilize best practices, but learn something quickly usable in the real world and applicable to web programming.

I was going to learn JavaScript for a while (but haven't got around to it) because:

  • I heard it's kinda Scheme on the inside, and generally has some really good parts
  • To do web programming, I need to learn JavaScript for client side anyway; with Node.JS I can utilize (and practice) the same language for server-side programming.
  • Node.JS seems to be a great framework for web programming, built with asynchronous/evented paradigm that should be good for doing... whatever stuff they are doing on the web?
  • Looks like Node.JS is slowly climbing to mainstream acceptance. I mean, I think I could really get a job with that outside of Silicon valley and Japan!

But I have heard so much advice to learn Python lately that I am thinking: am I missing something and being difficult?

It looks like lsparrish has been around and tried learning different languages before, so did I: I was paid to program in C and Forth. But I am a real beginner actually.

JavaScript is fine as a first language. I consider it to be a better first language than the TRS-80 BASIC I started on.

JS has a powerful advantage as far as usefulness in that it comes with all the browsers already, so you're going to have to learn it for client side if you are doing web apps. My suggestion to newbies trying to find a quick 10-minute intro is coffeescript.

I'm still leaning towards Python and Haskell as things I should be learning for various reasons. (Python seems useful and career-friendly, and I already know enough to be dangerous. Haskell seems to teach a different kind of math/thinking, which is attractive long term even if I never use the language.)

However Javascript is pretty friendly, especially with CoffeeScript and NodeJS. It might actually be a better language for the web-entrepreneur track since the hottest apps will be optimized for the client side.

One thing I've noticed about the NodeJS community is they seem really good about removing trivial inconveniences. For example with Meteor I was able to get an example set up in about 30 seconds.

I have no interest in evaluating languages based on how quickly they lead to money; only how they affect your ability to program. Additionally, I am not particularly experienced. I've only been programming for three or four years. Take my words with a grain of salt.

I remember one semester in college where I was using three separate programming languages at the same time. VB, Java, and Assembly (16-bit x86). Sometimes it lead to a small amount of confusion, but it was still a good experience. I would suggest beginning a second language soon after achieving minimal competence with your first language, but continuing to learn the first as well. Sticking too long to a single language encourages you to stick in a rut, and think that is the only way to do things. Go down as many paths as you are able to. Getting in a language rut is not a good idea.

Java is not the most amazing language in the programming world, but it is an extremely useful one to learn. It contains a C style syntax without some of the more difficult aspects. In other words, you learn how to program in the traditional way, but more easily. It is relatively verbose, and strict on some matters, but that teaches a methodical way of programming that is necessary to making good programs, but less strict languages do not teach. You can do anything in Java, and most of it is of reasonable difficulty. While you will need C++ to round out your C style, knowing Java is a very good stepping stone for it. It is an advantage to learning how to program that it is not interpreted (ignore that it compiles to bytecode), since that means you must have a coherent thought before writing it. When just learning, winging it is not the best strategy. Complexity should be approached by the newbie programmer as quickly as they are able to handle it.

Prolog might be the most amazing programming language, but I wouldn't recommend it to someone just learning how to program, and it isn't particularly transferable. It does give a person a way to think about the problem directly in a logical manner. The algorithms can often be expressed in a more pure form than in other languages, since it utilizes a search algorithm to actually get the answer rather than a series of commands. I would have liked to learn some algorithms in Prolog. As an example: factorial(0,1). factorial(1,1). factorial(N):= N>1, N * factorial(N-1). This looks almost exactly like the algorithm as it would be described. In fact, this could be used to intuitively explain the algorithm perfectly to someone who didn't know what factorial was. Notes: Prolog operates on equivalence. The first line declares that factorial(0) is logically equivalent to the number 1. Likewise factorial(1) is logically equivalent to 1. Disclaimer: As a (hopefully) just graduated CS student, I have written two different term papers and given a 36 minute presentation related to Prolog, but was only exposed to it these last few months, and have not yet had the chance to do a significant amount of programming in it. (19 units ftw.) I wish I had taken the opportunity to use it when I first heard of it a couple years ago; it was that or Lisp and I did Lisp.

On that note, Lisp. Definitely a good language, it can be very difficult to learn, especially due to the overabundance of parenthesis obscuring the fundamentally different approach to problems. I freely admit that my first attempt to learn Lisp went down in flames. Make sure you understand Lisp's fundamentals, because they are not the same as a more normal programming language. It takes real dedication to properly learn Lisp. Still, Lisp is one of those languages I wish I had spent more time on. It is a different and excellent way to think about problems, and is a very good language to expand your horizons after you already know how to program. While it is possible to write in a C style in Lisp (Common Lisp at least), make sure to avoid that temptation if you really want to understand it. It is especially good for recursion, and you are right about the whole code as lists thing being an interesting perspective. I didn't really learn much about Lisp macros. Okay, fine. I wish I had done Prolog and Lisp.

If you want to be a good programmer, then you must learn assembly of some form. It would be utterly insane to try to learn programming with assembly, (of course, some did, and I wouldn't be here on my computer if they hadn't.). Understanding how the machine actually (logically) works is a huge step toward being a good programmer. A user can afford to only know what is done, a programmer needs to learn how it is done, and why. High level languages will not make you a good programmer, even if they are what you end up using for your entire career. The two semesters I spent learning how the computer operates on a logical level were of extreme importance to me as a programmer, and assembly is an important part of that.