Ask HN: How to choose the right language

20 points by cyruskazemi ↗ HN
I am a beginner reading the recently posted "How to be a Programmer" article and there is a section on choosing languages. The author discusses choosing the "best language for the task." That is something I see discussed quite frequently. I know there are languages that are most commonly used for certain tasks, but how do you decide between two similar languages? Like building a web app in Ruby vs. Python? Can anyone give an example like this?

39 comments

[ 3.0 ms ] story [ 85.7 ms ] thread
There are probably two dimensions to this:

1) Whether the features and capabilities of the language match the task

2) Your familiarity with using a given language for a type of task.

There might be a third, somewhat less tangible concept of "elegance" mixed in there too, insofar as that some languages might lend themselves to very direct, elegant solutions to a particular problem, while others might require more round-about ways of doing things.

If you wanted to become good at comparing programming languages, the best way would probably be to read up on various classes of programming features. For example, type systems, object systems and other factors that generally influence programming language design. The other way would be to actually use some of the languages in question to get a sense of whether they agree with your preferred manner of problem solving. This might also give you a chance to explore library support and documentation and other related factors are that might influence your decision.

After you've programmed in a bunch of different languages, using a whole lot of different paradigms, you generally start to be able to pick the similarities and differences between languages pretty quickly, hopefully with reference to your past experience about what you do and don't like in a programming language.

For a very simple language start with HTML, then add some javascript and then go for a server side scripting language.

That way you can sort of ease in to the concepts of syntax (and debugging) in a familiar environment.

Adding some js will give you some client side functionality, from there it is a (relatively) small step to running some code on the server.

Then you can add things like databases and so on.

The language itself is not the most important factor, the method (edit - (compile) - test - evaluate and iterate) is.

You'll learn how to set yourself a goal (say building a website), sketching it out (paper is good), then make a static html mock-up, then expand on that.

This will take you some time!

If you're planning to write for the web (who isn't), then I prefer javascript for 2 simple reasons:

1. Unless you use Flash, you'll probably have to use some javascript anyway if you want any logic on your client.

2. You can click View:Source on any web page to see the javascript running that page. You'll have millions of examples of source code along with that code in action right now on your machine. A live example is an excellent learning tool.

You can also use javascript for your server side logic, but that's another debate altogether. If you build some pages that do something first, you can worry about the back end later.

I can't help but notice that this does nothing to answer the question, which was about how to decide between any two languages, with Python and Ruby given as examples, rather than "What language should I use for web programming?", which appears to be the question you have answered.
The question is too open ended if you take that approach and does not allow for concrete answers. The OP does allude to the fact that he wants to build a webapp and does mention ruby and python, both decent choices. A lot of the answers here suggest that either is a fine choice, which perhaps is all the OP needs to hear.
I really have to call you on this one. Usually I would just let it go, but really, this has just missed the mark. You're suggesting that the presence of certain keywords in a question permit you to totally rephrase that question and then answer that instead?

I'll quote from the post:

> The author discusses choosing the "best language for the task." That is something I see discussed quite frequently. I know there are languages that are most commonly used for certain tasks, but how do you decide between two similar languages?

That was the question being asked.

I really wanted to use javascript (client and server) for my new webapp. But alas, the various server-side frameworks aren't quite ready for me yet. I think a pure client js + app server js + js db would be fantastic. Even though the various javascript server libs/frameworks are maturing very fast, I cannot afford to toss perfectly good high level solutions that exist with something like merb: production server process management, integrated release scripts, session management and authentication, etc... If you go with js server side at the moment, you get to roll your own for all this.

I want this to be the answer, but for right now, I can't afford to cut my teeth on it.

In my opinion there's too much emphasis on general-purpose languages over domain-specific ones. There's lots of low-hanging fruit in the domain-specific space.

While designing or implementing a worthwhile Turing-complete, general-purpose programming language with a correct and efficient implementation is a huge undertaking and requires vast amounts of knowledge, doing the same for a domain-specific language is much easier because the scope is much more focused and the efficiency requirements are often not as strict.

As long as you focus on semantics, limit the scope of your language, use declarative techniques like pattern-matching that will let you avoid the Turing-completeness trap (Turing-completeness makes your code hard to analyse and process, unlike declarative data) and use a proper general-purpose language for the implementation, designing and implementing a domain-specific language is really not that hard, though proper IDE integration and a debugger are still not so easy to do.

I like to make the right tool for the job, so I use Common Lisp, which makes it almost ridiculously easy to invent new s-expression-based syntaxes via macros and compile through production of trees of closures, among other things.

You don't choose a language in such case as you don't build with Ruby nor with Python. You build with the language and a web framework such rails or django.

There are many things to consider. And most of the issues ar non-technical

- will there be support for the frameworks, language etc long enough?

- are the coders competent with the language / framework

- what limitations exists on deployment

- what limitations the customer imposes

Of course if there's are no non-technical issues to consider, go for the technically "best" solution.

Consider expressiveness. The number of lines of code that a programmer can write in a month tends to be a constant independent of language. A program in Java takes 2 to 5 times as many lines of code as in Python. In Java you will get a lot less accomplished.

Take a look at the standard libraries and third party packages. If someone else has written it, you dont have to, unless you want the experience. Python, Java, and Perl have lots. Ruby and IO less so.

Look at job listings. If you are starting out, you might as well pick on that you can get money for.

Look at the communities. Are the people ones that you would like to hang around with. If they dont like newbies, look elsewhere. Python seems to be pretty good in that respect.

As for web development, Python has Django (I recommend) and Pylons. Ruby has Rails. Stay away from Java; everything is too damned complicated, but there are a lot of jobs.

> The number of lines of code that a programmer can write in a month tends to be a constant independent of language

Says who? Ignoring the fact that LoC is a terrible metric for measuring anything except the amount of paper it would require to print the program, I think it would be very hard to use it to quantify how much you will accomplish. Your (implied) assertion that you will not just accomplish less, but accomplish between a half and a fifth as much in Java as in Python is even more outlandish. I can't imagine you have any evidence to support this?

> Stay away from Java; everything is too damned complicated

What is this supposed to mean? That the hundreds of thousands of people who make their livings from doing web development with Java and being competent Java programmers are either stupid (for not programming in Python), or super-smart (because they can grok Java)? This is pretty absurd. Java is no better and no worse than pretty much any other language in wide-spread use. To its benefit, it has extensive library support for pretty much everything under the sun, and all the enterprise features which would make it relatively painless to do a whole heap of things that would become very difficult in almost any other language.

Really, I think you should refrain from giving advice on specific programming languages if you are just going to resort to complete and utter nonsense to provide comparisons.

The argument that lines of code is constant across languages is usually associated with Fred Brooks's _The Mythical Man Month_. I don't buy it, either. (Sometimes there is the added restriction of "lines of debugged code". That may be more likely.)

Here is a study of how lines of code produced annually differs across languages in a collection of open-source projects: http://sequoia.cs.byu.edu/files/pubs/Delorey2007.pdf

Of course, the correlation between lines of code and "productivity" is pretty nebulous. (Copy-and-paste programming is the most obvious example of a negative correlation.) LoC is an easy thing to measure, but not necessarily useful.

As far as I know, the statement about lines of code was first stated by Fernando Corbato http://en.wikipedia.org/wiki/Fernando_Corbat%C3%B3 (Corbato's Law). "It's our experience that regardless of whether one is dealing with assembly language or compiler language, the number of debugged lines of source code per day is about the same! [http://web.archive.org/web/20080206153039/http://home.nycap....]

Python is generally considered to be 2 or 3 times as expressive as Java. I did some estimation on a compiler implementation in C++ and arrived at the conclusion that it could have been done in 20% as much Python.

Thanks for the source. It was probably more true then - the then-unimaginable resources available now allow very different trade-offs in language design.

(FWIW, OCaml is probably a better language for compiler writing. It hits all its strengths. Failing that, I'd still rather do one in Python or Lua than C, though.)

>What is this supposed to mean? ...

I didn't say anything about the intelligence of Java programmers. Like everywhere else some are brilliant and some are dumb as hammers. When I said "everything is too damned complicated", I was thinking of Java Web development which has a proliferation of one-size-fits-all frameworks which encourage bloated implementations. It could be that I have blundered into a tiny swamp and everywhere else is sweetness and light, but I dont think so.

I would be very careful not to write off an entire field just because you consider it difficult or complicated. It has its place and purpose, and the complexity is not just for show. It's not "one size fits all", it's just that the minimum size at which it might become useful is probably larger than that of many of the interpreted, dynamic web languages and frameworks that are popular these days.

For example, I would much rather maintain a Java-based web application than a PHP-based web application.

I feel a need to stand up for Java here. Most of Java's nasty reputation comes from J2EE, and not the language itself.

Java is a wonderful tool for a LOT of systems programming. It's got a nice object model, automatic memory management, and pretty good execution speed. Given the choice between C++ and Java, I'll take Java every time. Remember, Java was originally designed for embedded systems like set-top boxes. It's still one of the best languages out there for those kinds of applications.

It's not a good fit for UI or web work, but neither is C/C++. As always, consider the type of job before selecting a tool.

> It's not a good fit for UI or web work, but neither is C/C++.

That's so true. Java is a great general purpose language but it so terribly verbose when you're trying to do string heavy or database work. The web is both.

One thing though, compared to several years ago the speed penalty has all but disappeared, it's fast enough to build some pretty impressive stuff with it.

I certainly agree J2EE is a travesty. Framework design by committee is wrong wrong wrong.

I do not agree that Java is all that great. I classify it as "ok". I don't disparage "ok" but there were languages before Java that were better than "ok". Java isn't and never was a revolution, it picks from various things that came before and in some places make incremental improvement.

During the early days of J2EE I built an app framework that ended up being about 300,000 lines of Java, we had to replace most of the core JDK classes as well due to their poor design. What we ended up with was enterprise quality but far more accessible than the J2EE equivalents. Prior to this app framework, I built essentially the same thing in Smalltalk. The Smalltalk version was much fewer lines of code, easier to maintain, easier for the end-user. And so far as Java performs great, yes it does. One key reason is the hotspot and jit stuff which were directly taken from the Smalltalk world.

btw, when I'm playing up Smalltalk here, I know its hard for newcomers to see the value as Squeak is "hard to take" compared to what we had in the early 90s.

[EDIT] one thing I do like about Java is it forces the programmer to think more formally about an object's interface. This is a good skill to learn and can be applied to other languages. The loose way some play with duck typing is a little much for my tastes.

I as well stand on java's side here. Too much of it's bad rep comes from J2EE (it's too bloated). Java has some very nice technologies written around it that are quite powerful when utilized correctly (JPA/Hibernate being one of those)

Quite frankly I think Java is actually _very_ good for web programming. IFF you are using the Spring framework(autowiring and transaction handling are very strong components of this framework) along with some nice templating frameworks (tiles, sitemesh)

I absolutely love the Spring (MVC) framework and this is probably why I hold java in high regard.

The most important thing when choosing a first language is to choose a language that will allow you to get stuff done as quickly as possible. The only way to learn how to program is to build stuff, and if you optimize for that, the minor differences between two languages are actually a pretty marginal factor in comparison to the advantages of getting your hands dirty and having some early successes.

I like Python very much and think that it's a fantastic language for building things and probably the best language for learning programming. But if, say, all your friends use Ruby, or you find that Ruby has better libraries for whatever it is you hope to be doing then I'd recommend you choose Ruby. In fact, I think PHP is an awful language and that learning is is a complete waste of time, but if you're in an environment where using PHP is the best way to get up and running, you should choose that.

All other things being equal, I think Python would be the best choice for you. It's a great, very versatile language, designed from the ground to be easy to learn and understand. It comes with libraries for doing pretty much anything you might want to do with a computer. It has a wonderful community - very mature and very helpful. You'll find it easy to get very high quality help learning Python.

Speed of execution and expressiveness are common factors, and this depends on what you're doing. For instance, regular expressions. If you're doing a program that is primarily not dealing with text, but occasionally needs a regex, then Python regexes would be fine. If the program does a lot of text processing, it should probably use Perl, due to the performance and built-in syntax. And if the entire program is a simple filter, "sed" is even better than the Perl sledgehammer.

The standard library can be a big factor. Not having to download a dependency is a big win, which is why large standard libraries such as Python can often be better than something like a CPAN dependency in Perl. It can be the difference between using C++ or Objective-C, versus C. But more generally, if you need to do X, and you already know how to do it with language Y, you'll need a really good reason to try a different language.

You probably won't have enough experience to decide which language is a better fit for a project until you know at least one of them quite thoroughly. At that point, the differences that will actually matter to you should be much clearer.

While people can argue about the relative merits of Ruby and Python for days, the direct impact of language characteristics on a beginner are likely to be overwhelmed by other issues. For example, if a friend knows one of them quite well, go with that one - he/she can probably answer some questions, and in the short term that's far more important.

The same principle holds for Linux/BSD distributions, version control systems, and so on: If there's not a huge consensus and the differences don't mean much to you, just pick one. You'll be in a better position to make an informed decision later, and you're not stuck with it forever. Time spent trying to decide could instead be put toward learning the basics.

Another example that comes to mind is systems for parsing. There's ANTLR, lex + yacc, packrat parsers/PEGs, Prolog's DCGs, etc. While they have different strengths, any deep comparison will also nonchalantly throw around terms like LALR(1).

Perfect advice for a beginner. I was wasting so much time reading language debates, pros-cons, and comparisons. I was overwhelming myself with things I didn't understand.

Had I just picked a language and just ran with it, I would be farther down the road than where I am now. So just grab something, sit down, and play with it.

It's easy to find blog posts to talk yourself out of getting started with any language. None of them are perfect! Lisp has that "stupid parenthetical syntax" [1], Python has the whitespace thing, Lua indexes from 1, Javascript ...

I started tinkering with Prolog as a summer project, and as a side effect, Erlang makes sooo much more sense now. (Erlang was originally implemented in Prolog, and inherited a lot of its syntax & style.) I picked it deliberately because it's quite far from everything I know, and Peter Norvig said a lot of interesting things about it in PAIP. Chatter on the web gives the impression that it's just some weird dead AI language, but I've found it really inspiring. I'm glad I didn't let that discourage me. Even if the only benefit I get from it is the insight into Erlang's design, being able to read Sterling & Shapiro's _The Art of Prolog_* , and finally getting how unification/pattern matching and type inference work, it was time well spent.

* Which is awe-inspiring. I would recommend it regardless of whether you care about Prolog, much like Norvig's PAIP is worth reading even if you don't care about Common Lisp.

[1]: http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePe...

I'm just a newbie pythonista, so I'll just nod and smile. :)
Some great stuff here in the comments for you, but don't get caught up in decision paralysis. The truth is no matter which you learn it will create a foundation for you to (if you're interested) pick up other languages and/or frameworks. Get one solidly under your belt. None of the languages/frameworks are perfect- all will have you scratching your head (or banging it on the table) from time to time. Some will be a better foundation than others (Ruby and Python would both be great here).

So don't spend too much more time thinking about it. If you just need someone to just tell you where to dive in so you can really get going here you go: If you have or plan on growing a beard- Python/Django. If you plan on staying clean shaven and dressing smartly- Ruby/Rails. When you've mastered the current choice and have a nice career going, go ahead and master the other(s).

I don't understand, why does one need a beard for Python/Django? Is Ruby/Rails more hip?
I think he was referring to Rails being very structured, and Django giving you the flexibility to do it your way. It depends on your tastes; I prefer Ruby/Rails.
I don't have (or want) a beard, but prefer Ruby/Ramaze.

Luckily, in both Python and Ruby there are many choices for Web dev, so don't let that drive the language choice.

I personally think he was being more tongue in cheek than anything. Basically if you need someone to tell you what to do here is an arbitrary metric for you to base your decision off. Beards.
Most common languages (but not all languages) are basically equivalent, and choosing one or another is more a matter of taste rather than "the best tool for the job". If, for example, you want to write a web app and need to choose between Ruby, Python or Perl pick the one you know best and go with it.

One factor that can make the language choice important is the speed of the program: if you need to make a computationally heavy application, you'd better choose a fast language. This would rule out interpreted languages. In such a case, you should choose Common Lisp/C/C++/Java/C# rather than Perl/Python/Ruby.

Another important factor is the platform where your app will be running. If it's on your own server, you can use whatever you prefer. If it's on the iphone, the most abvious choice is Objective-C. If it's a small device with little memory and low computing power, languages with a low memory footprint and manual memory allocation like C and Forth would make a better choice than Python or Ruby.

Use Python.

If Python is too slow, use C.

If you don't know C, use Java.

If you don't know any of these, you ought to learn at least one. Use Python.

(comment deleted)
How do you decide between two similar languages?

If two languages are truly similar, like Ruby/Python or Java/C#, it doesn't matter much which you start with. If I were you I'd pick one based on gut feeling or a coin flip and get at it.

Funny, when I was a beginner most people hacking on a computer at home had two choices, either some dialect of BASIC or, assembler. Today you can probably choose from literally hundreds of languages.

Here's what I'd recommend: start off with an interpreted language, maybe Python, and work through a couple of tutorials. If you want to be a little different maybe look at Lua. Then try to build something. Tutorials are good but not as motivating as your own project. I would avoid IDEs like Visual Studio at first, they have a lot of power but for a beginner they might be distracting and keep too much under the covers that you really need to understand.

Then start exploring other stuff. At some point you should try a functional language. Work through a book like the Little LISPer until you "get" recursion, currying, how the Y-combinator works (no not this site). Definitely take the time to learn C and pointers. Even assembly. Learn about object-oriented programming. Exposure to all these perspectives will make you a better programmer, no matter which language ultimately becomes your favorite.

Also dont forget that once you learn the language well, say you picked python, dont evanglise it as the best language onces you have fnished your first little app or program. Read about other languages also and just play around alittle. If you know one well you know where you can always run when there is a big project you want to do, but give others ago, you could be pleasnantly suprised

I know alot of poeple who picked up perl as their first language during uni and wont pickup anything else cause they are so deeply into it and say its the best language. It might be from their point of view which is fine but dont let the first language you learn be the only one you ever use also.

Like the other guys said, if your a beginner pick one, hell pick python for the simple reason that google use it (so it must be good) get used to it and then try to compare with others once you get the swing of things.

Like buying a guitar for the first time, you dont know which one is good cause you dont know what a good guitar is supposed to sounds like so you buy a fender or a les paul cause one of your idols use it !

If your new web app isn't too complex to get bootstrapped, you will learn better if you choose a light framework: ruby - Merb or Sinatra, python - webpy, etc...

One of the reasons you see so much disappointment with ruby is people start with rails and that doesn't really help you become a good ruby programmer. It may actually teach you bad habits and keep you from knowing how the language and http requests, and db requests really work (none of which is that complicated).

I use ruby over python. Mainly because I picked it up first and don't have a good reason to switch. I use merb as my framework, which is a fine choice, but if I had to start again, I might go with Sinatra.

If you do go with Ruby, buy this book: The Ruby Programming Language http://www.amazon.com/Ruby-Programming-Language-David-Flanag...

I have seen no text that comes close to this new book in teaching Ruby.