This is a wonderful recap of the different ways of expressing the same idea in different languages. It is a fine Rosetta Stone.<p>That being said, it would also be useful to characterize features that are completely unique to a given language. For example, Python has 1) a unique and powerful version of super() for working with multiple inheritance; 2) it has generators (the yield statement) that allows state to be suspended and restarted (and allows data and/or exceptions to be passed back in to the generator); 3) the with-statement for managing contexts and for providing a new way to factor code; 4) easy-to-write class and function decorators; 5) metaclass support that provides full control over the creation of classes; 6) and descriptors for fine-control over attribute/method binding behavior.<p>Collectively, these capabilities make the language more than just another syntax for expressing the same ideas as other languages.
Note that anywhere you see array() in that list for PHP 5.4 you can replace it with [ ]'s. So the example that has:<p><pre><code> $a = array(1,2,array(3,4));
</code></pre>
becomes:<p><pre><code> $a = [1,2,[3,4]];
</code></pre>
Also<p><pre><code> 0b101010
</code></pre>
works in 5.4.
This is great. Very handy for explaining to others the differences between various languages, and surprisingly enough until you get into the array functions i'm starting to feel like PHP isn't really that messy since reading this!<p>Thanks for sharing, ill pass it on whenever a comparison is needed.
This is a really great effort, but I noticed a handful of areas where the PHP example was off. I wonder if people with more experience with the other languages noticed the same thing for their language.<p>Some examples:<p>Null test:<p><pre><code> $var === null // omitted
isset($var) // actually checks if $var exists and is not null (apparently--
I actually didn't know about the not null part)
</code></pre>
Undefined variable access: it's a notice. Many people consider it best practice in PHP to treat notices as error, because things like this are notices.<p>Add time duration<p><pre><code> strtotime('+10 minutes') is more typical than the objects
</code></pre>
Array out of bounds behavior again issues a notice.
Previous discussion: <a href="http://news.ycombinator.com/item?id=2882070" rel="nofollow">http://news.ycombinator.com/item?id=2882070</a> with lots of bug reports. I wonder if they incorporated all the changes suggested.
"Passing by reference" section is wrong about Ruby (not sure about Python). Ruby passes everything by reference, it's only that integers are immutable so that the function can't alter them. Strings, though, are mutable:<p><pre><code> def foo s
s.concat 'foo'
end
a = 'bar'
foo a
a
# => "barfoo"</code></pre>
Here's a simpler comparison with <i>way</i> more langauges: <a href="http://rigaux.org/language-study/syntax-across-languages/Strng.html#8" rel="nofollow">http://rigaux.org/language-study/syntax-across-languages/Str...</a>
sed begat awk.<p>awk begat perl.<p>perl begat python and ruby.<p>python will get you a job at google.<p>ruby will get you a job at twitter.<p>php will get you a job at facebook.
Unfortunately tests page for PHP does not mention PHPUnit: <a href="http://www.phpunit.de/manual/3.6/en/index.html" rel="nofollow">http://www.phpunit.de/manual/3.6/en/index.html</a>
which is the best solution for testing in PHP. Neither it mentions xdebug for debugging and xhprof for profiling.
Perl's treatment of regex still trumps all. It's so pleasant to use in so many ways. It's for this reason alone I will probably never bother "switching" to Python or Ruby.
Wish Lua was added to the list.<p>Edit: Found Lua compared on the same site here: <a href="http://hyperpolyglot.org/embeddable" rel="nofollow">http://hyperpolyglot.org/embeddable</a>
Very good comparison between all the languages, and like other people said: a nice Rosetta stone. With that said, it would be very useful to add a comparison of the database layer syntax as that it is, at least for a me, a common task in all of the scripting languages. I also agree with the comments about adding the features that are unique to the languages, as that would be extremely helpful.
Even though there is no native "switch" statement in Python, the same control flow structure can be done with a dict construct:<p><a href="http://simonwillison.net/2004/may/7/switch/" rel="nofollow">http://simonwillison.net/2004/may/7/switch/</a>
Wonderful reference for comparison! I admittedly haven't had time to pursue the whole table, but wanted to point out that there is indeed an increment and decrement in python:<p>x += 1<p>x -= 1
The Perl described in this article is COMPLETE SHIT. He calls deprecated and improper libs for some functions, unnecessary libs in others, assumes improper or unoptimal syntax in other examples. The list goes on. Learn languages before releasing articles on them.<p>He never even uses Perl's foreach in equivalency examples!! WTF.
A very useful page if you know one or two of those languages and need to do something in another one.<p>A suggestion: For people doing some work in Perl, a review of the OO syntax might be critical. Both Moose and the old way.<p>A note, re the repl part: I don't use a repl for Perl, I just write one liners in shell. Afaik, Perl is the best command line tool that exist, it is even a superset of awk.<p>Edit: For named parameters the page might want to reference one of the CPAN modules doing that. Same goes for exceptions. The use of do to create blocks most everywhere might also be noted in e.g. the ternary operator. Unicode support should probably also be discussed. And so on.
[I wonder if this is a personal watershed for Hacker News?]<p>These languages are essentially the same thing. I often write code in at least 3 of these languages most days, and I simply translate the minor differences between them in my head.<p>"Hyperpolyglot" -- excess in many tongues -- I don't think so.<p>Learn at least some static languages, assembler and some functional languages, and <i>then</i> post something interesting on HN.<p>Well, I have plenty of karma to waste on noobs.