

Ask HN: How to choose the right language - cyruskazemi

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?
======
silentbicycle
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
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.

~~~
silentbicycle
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...](http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePerl/)

~~~
colbyolson
I'm just a newbie pythonista, so I'll just nod and smile. :)

------
stefano
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
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.

~~~
silentbicycle
Care to say why?

------
ams6110
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
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
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
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
_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
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
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
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...](http://www.amazon.com/Ruby-Programming-Language-David-
Flanagan/dp/0596516177)

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

------
makecheck
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
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
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.

~~~
jacquesm
> 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.

------
jwecker
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
I don't understand, why does one need a beard for Python/Django? Is Ruby/Rails
more hip?

~~~
ashleyw
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.

~~~
jamesbritt
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.

------
jacquesm
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
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
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
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.

~~~
gdp
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.

