top | item 764931

Ask HN: How to choose the right language

20 points| cyruskazemi | 16 years ago | reply

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?

38 comments

order
[+] silentbicycle|16 years ago|reply
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).

[+] colbyolson|16 years ago|reply
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.

[+] stefano|16 years ago|reply
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.

[+] JDigital|16 years ago|reply
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.

[+] ams6110|16 years ago|reply
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.

[+] intellectronica|16 years ago|reply
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.

[+] Hexstream|16 years ago|reply
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.

[+] sid|16 years ago|reply
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 !

[+] gruseom|16 years ago|reply
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.

[+] tommia|16 years ago|reply
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.

[+] gdp|16 years ago|reply
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.

[+] jhancock|16 years ago|reply
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.

[+] makecheck|16 years ago|reply
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.

[+] russell|16 years ago|reply
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.

[+] megaduck|16 years ago|reply
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.

[+] gdp|16 years ago|reply
> 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.

[+] jwecker|16 years ago|reply
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).

[+] colbyolson|16 years ago|reply
I don't understand, why does one need a beard for Python/Django? Is Ruby/Rails more hip?
[+] jacquesm|16 years ago|reply
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!

[+] edw519|16 years ago|reply
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.

[+] gdp|16 years ago|reply
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.
[+] jhancock|16 years ago|reply
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.