views:

982

answers:

7

After competing in and following this year's Google Code Jam competition, I couldn't help but notice the incredible number of [successful] contestants that used C/C++ and Java. The distribution of languages used throughout the competition can be seen here.

After programming in C/C++ for several years, I recently fell in love with Python for its readable/straightforward nature. More recently, I learned functional languages like OCaml, Scheme, and even logic languages like Prolog. These languages certainly have their merits and, in my opinion, can be applied more easily than C++ and Java for certain situations. For example, Scheme's use of call/cc simplifies backtracking (a tool required to answer several problems) and Prolog's logic specification, although inefficient due to its brute-force nature, can drastically simplify (and even automatically solve) certain problems that are difficult to wrap one's brain around.

It is clear that a competition contestant should use the tools that are best suited for the challenge. Even x86 assembly is Turing complete - that doesn't justify solving problems with it. In this case, why are the contestants that use less common languages like Scheme/Lisp, Prolog, and even Python significantly less successful than contestants that use C/C++ and Java? Worded differently, why don't successful contestants use languages that, although may be less mainstream, are arguably better tools for the job?

There are several motivations for my question. Most importantly, I would like to become a better programmer - both in the practical aspect and the competition aspect. After being introduced to such beautiful paradigms like functional and logic programming, it is discouraging to see so many people discard them in favor of C/C++ and Java. It even makes me question my admiration for said paradigms, worrying that I cannot be successful as a Lisp/Scheme/Prolog programmer in a programming competition.

+4  A: 

fun question, probably should be community wiki.

Look at number of finalists by countries: http://www.go-hero.net/jam/10/regions. notice number of people from East Europe and Russia. those places have very strong C++ communities, as well as Java, for number of reasons.

look at number languages in qualifiers: http://www.go-hero.net/jam/10/languages/0 and finals: http://www.go-hero.net/jam/10/languages/6. C++ starts out less than half and has 75 percent in finals. either good programmers prefer C++ or C++ makes the programmers. Probably by the time you master C++, other things become trivial.

You are free to draw your own conclusions though.

aaa
+2  A: 

First of all, as you have pointed C++ and Java are mainstream languages. These automatically means that people who start doing programming competitions will be introduced to them first - by the way who learns Lisp as a first language:) I also participate regularly in such competitions - I use C++ to compete, although my favorite language is Java. It is just I want to practice another language apart from Java - also C++ is a little bit less verbose and runs faster which is important for programming competitions. Now to my point - people become experts first in mainstream languages. To participate in programming competitions you must have quite a good grasp of the language you are using. You don't have time to search on the internet for stupid things - like forgot a construct. It is just that speed is an important factor there. To use Lisp in a competition, you must be fond of it. I don't think there are such many people out there. Correct me if I am wrong. And honestly the pros you have mentioned like simplifies backtracking: In whatever language backtracking is easy - declare a method and just call it again for every possible outcome. It couldn't be simpler. I haven't felt till now that the language I am using is trying to trip up my feet for programming competitions.

Petar Minchev
The plural of anecdote may not be data, but I learned Scheme as my first language and my intro CS course was in Haskell. I do agree that this seems to be unusual, though: C/C++/Java/Python seem to be the popular ones.
Wang
Good point; I think this gets to the heart of the matter. For programmers with enough practice at doing the things that frequently come up, there's really no great benefit in other languages. (And features like, say, Perl's text-processing ability are rarely of any use in these contests.)
ShreevatsaR
+5  A: 

Why we all speak English and not Esperanto? Well, it just happened so. Even though English is inconsistent and bloated and Esperanto is intentionally designed as 'better tool'.

Thus, one reason is a tradition. In most schools programming is still taught in C/C++, Java, Pascal or even Basic. And participate in those contests mostly students, which choose language they know better.
Also, you can notice that most algorithmic books feature psedudocode in style of Pascal or Ada, and very very rarely - Lisp. I don't know why, perhaps also a tradition. Or perhaps it's just not so good for the algorithms.

Another reason would be speed. Although it's not a problem for Google Code Jam, in almost all contests 2x speed gap is a difference between 'Accepted' and 'Time Limit' verdicts.
In other words, if optimal algorithm in C++ runs 10 times faster than in Ruby, it may mean that sub-optimal algorithm in C++ will still be faster than a good one in Ruby. And contest authors usually don't want to allow O(n^2) submissions, if O(n*logn) can be achieved.

Nikita Rybak
Just a comment on your analogy: Esperanto fails miserably at its goals. Its sounds are pretty much exactly those of Zamenhof's dialect of Polish, and its grammar is unnatural and complicated. It is in no way a good universal language; Klingon, in many ways, does a better job of seeming like a natural Human language. One could, I suppose, argue that there are similarities in this to C++ and Java, but that would be unfair :) (See also http://www.xibalba.demon.co.uk/jbr/ranto/ .)
Antal S-Z
@Antal Well, analogy may be flawed, but you get my point. _Between you and me, I don't speak Esperanto either_ :)
Nikita Rybak
+1  A: 

A vital reason might be that every contests don't support languages like python or prolog. Specially ACM ICPC World Finals support C/C++ and Java. And TopCoder also supports only C++, Java, C# and VB. It is natural for the contestants that they will choose one language that is available in every contest. Another reason might be execution speed. And yes, another reason is these are the languages that most of the people learn first.

taskinoor
A: 

Big libraries were a selling point for Java in ACM ICPC. It's handy to be able to realize you want some random data structure or algorithm and just pull it out of the standard libraries.

Wang
+12  A: 
ShreevatsaR
I wouldn't agree about libraries: not long ago people used to win ACM finals in Pascal, which doesn't offer even simple hashtable (and nothing remotely similar to stl). Not sure about now, though: it seems more and more people migrate from Pascal to Java. But an interesting answer anyway.
Nikita Rybak
I agree; as I said, the existence of libraries is a relatively very minor issue. I can remove it if you think I overstated it.
ShreevatsaR
That bit about Java in the second to last bullet point is not quite true. Many of GCJ's top contestants use Java.
NullUserException
@NullUserException: Isn't that what I said, with "a few" instead of "many"? :-) My numbers were slightly off — actual figures, from [stats linked above](http://www.go-hero.net/jam/10/languages/0): in the qualifier, 4911 used C++ and 2762 used Java out of 10192 (48% and 27%). Among those remaining in the [final](http://www.go-hero.net/jam/10/languages/6), 18 used C++ and 5 used Java, out of 24 (75% and 21%).
ShreevatsaR
[The other participant in the final ("linguo") used Python, and through the contest has used languages including LOLCODE, Piet, FALSE, Whitespace,and FRACTRAN!]
ShreevatsaR
I would just like add a bit to the part about speed. The "speed" in contests like the GCJ is the runtime complexity of the code (i.e. big-O). In the GCJ usually the correct algorithm get accepted even in a slow language (hence there are lots of accepted Python submissions) while a slow algorithm will take forever even in asm. There are exceptions, but generally if you use the correct algorithm/technique, you are safe even with a slower language.
MAK
+2  A: 

First, I'd question your premise [edit: or what I take to be a premise -- that contestants using C++ and Java fare about equally well]. For example, here's what languages were used for the entries that came in the first 100 places and the last 100 places in Google's recent AI contest:

alt text

Contestants using C++ and Java did not seem to be anywhere close to equally successful in that contest. Contestants using Python didn't seem to fare particularly well either, though there were considerably fewer of them, weakening any conclusion in that regard.

Second, of course, an awful lot of the explanation (as others have pointed out) is undoubtedly just the number of people who are familiar with each language. There are probably more people taking a course in Java right now than the total number of people who've ever written any Lisp, Scheme or Prolog.

Edit: I think a third possibility is simply versatility. To pick an extreme example, Prolog is very well suited to a few problems, but equally poorly suited to many others. Few people can (or at least do) learn more than one or two languages well enough to use them in a contest, so most people who are interested in such things are likely to choose languages that can work reasonably well for almost anything, rather than attempting to learn a specialized language for every problem that might be chosen.

Jerry Coffin
Well, it does seem that most of the top participants used C++/C# and fewer of them used Python/Haskell/Lisp/Scheme/Ruby/Prolog, which strengthens the premise of the question, doesn't it? The question wasn't to compare C++ and Java among themselves (though this is interesting, thanks), but something like: ”Why are "nice" languages less succesful at the top? Why don't the good contestants (who presumably know many languages) pick one of these?” But I agree that familiarity is one of the major reasons.
ShreevatsaR
My impression (perhaps mistaken) was that the question assumed contestants using C++ and Java were about equally successful. That may be true in some contests, but certainly didn't seem to be in this one. Though it's certainly true that there were fewer of them, contestants using Go, Haskell, Lua, and CL seemed to be more successful than those using Java (though, admittedly, in terms of success rate, C++ certainly seemed to dominate, at least in this particular case).
Jerry Coffin
Pardon my nit-pickin' but this should really be a bar chart rather than a line graph...
tzaman