11 ms·
A syntax comparison across many languages
- timaelliott 14y agohttp://hyperpolyglot.org/scripting http://hyperpolyglot.org/scripting is a similiar resource for php, perl, python and ruby only.
- oconnor0 14y agohttp://hyperpolyglot.org/ http://hyperpolyglot.org/ provides comparisons between various "families" of languages - not just the above. But there isn't a comparison between, say, Ruby and Haskell.
- timaelliott 14y agoThank you Dr. Obvious.
- brittohalloran 14y agoMy big takeaway is that Ruby generally does things the "most-popular" way, and that maybe a lot of those obscure languages are obscure for a reason (object["method"](params) to invoke a method?!?)
- walrus 14y agoobject["method"](params) is just an alternative syntax. Normally you would do object->method(params).
- ajanuary 14y agoYou mean like JavaScript? Not sure why it's not listed there next to Pike. var f = [] f['push'](2) // f -> [2] Pike also has the more familiar object->method(params) syntax. It's actually a pretty useful bit of syntax. I've been using it recently when combining multiple objects deserialised from json. var report = [name, dob] var person = { name: 'Andrew', dob: '1980/03/23' } _.each(report, function(prop) { console.log(person[prop]) }
- wilmoore 14y agoGood call...and for those not necessarily using something underscore.js-like (thought almost always nice-to-have): var report = ['name', 'dob']; var person = { name: 'Andrew', dob: '1980/03/23' }; report.forEach(function(prop){ console.log(person[prop]); });
- rll 14y agoNot sure about that. The regex for variable identifiers shows that Ruby is alone on the island of languages that force a lowercase first character.
- aaronblohowiak 14y agoGo uses casing for semantic meaning as well. Also, you can use non-A-Z in ruby source. http://rosettacode.org/wiki/Unicode_variable_names#Ruby http://rosettacode.org/wiki/Unicode_variable_names#Ruby
- objclxt 14y agoGo is missing from the analysis (sadly, because it's definitely more popular than some of the languages listed!) - but yes, casing is used to determine the scope of your variables. It's actually a rather elegant solution (I find Go's syntax to be generally elegant, but YMMV)
- CanSpice 14y agoI haven't looked at everything, but the Perl variable identifier regexp is incorrect, as Unicode characters are allowed as of 5.12, which was released in 2010. For that matter, same goes for Java, except Unicode letters are allowed.
- rll 14y agoThey are allowed in PHP as well. The set of regexes looks odd for a number of the languages actually.
- hythloday 14y agoJava also allows currency symbols (e.g. £€$) as identifiers. I know this because I had a colleague who was quite proud of having switched to Dvorak, and another colleague who immediately wrote a code-generation tool that emitted € characters in variable names...which are untypeable on a Dvorak keyboard. :)
- emmelaich 14y agoJava allows a vast array of odd characters, including nulls. http://stackoverflow.com/questions/4838507/why-does-java-allow-control-characters-in-its-identifiers http://stackoverflow.com/questions/4838507/why-does-java-all...
- nn2 14y agoDvorak doesn't support the Alt-<type unicode number on number block> trick?
- dsr_ 14y agoEleven ways to comment to the end of the line; five of them used only by one language each.
- jonathansizz 14y agoAnd the most common way is one of the worst (most inconvenient), although J seems to win the prize.
- kamkha 14y ago"Inconvenient" because typing a # requires a modifier key on most keyboard?
- gebe 14y agoWell, depends on your layout. That might be the case on a US keyboard but for many others (for example German, Spanish, the Nordic countries' layout and many other European and non-European layouts) it would be preferred over for example "//". For "//" you need to use a modifier (just as with '#') but you need to stretch more (or use both hands) and as well tap it two times. That's one of the reasons why I prefer to code using an English layout in my IDE/editor :)
- emillon 14y agoWadler's law strikes again : http://www.haskell.org/haskellwiki/Wadlers_Law http://www.haskell.org/haskellwiki/Wadlers_Law
- perlgeek 14y agoAlso relevant: http://rosettacode.org/wiki/Main_Page http://rosettacode.org/wiki/Main_Page Some parts are about language features, others are about implementations of algorithms in many languages.
- mbell 14y agoWhat is "Assembler"? Is that supposed to mean assembly? If so what architecture uses '!' as a line comment token?
- heretohelp 14y agoNot an architecture, an assembler.
- mbell 14y agoFair enough, my underlying point is that `assembly` isn't a language, it's a family of languages which have a set of characteristics which are tied very tightly to the instruction set used (often called an architecture). Comments would be a characteristic of the compiler, which you may call an 'assembler' if you wish, however an assembler is not a language.
- heretohelp 14y agoAn assembler is a utility with its own dialect regardless of target hardware.
- pjmlp 14y agoAssembler is what translates assembly code into executables, a compiler for assembly if you so wish. In many countries like mine, both terms tend to be used interchangeably.
- deleted 14y ago[deleted]
- haberman 14y agoOh poor XSLT. I can't decide whether to laugh or cry.
- ret 14y ago#if 0 ... #endif in C/C++ is not a true comment -- commented text is parsed by preprocessor.
- splicer 14y agoThis glosses over some important syntactic differences. For instance, a semicolon is used differently in C than it is in Pascal. In C, it's a terminator; in Pascal, it's a separator.
- jhrobert 14y agoThis is quite an amazing achievement. There are a few other dimension to explore beside syntax. Like "are arrays 0 or 1 based?" etc Apparently the author is now part of the opalang effort. They used to have a slightly weird syntax for their language and later changed that to have it look more like JavaScript. That's a strange move when concise syntaxes à la Ruby or CoffeeScript seem popular.
- astrodust 14y agoIf there was ever a project that required an emergency typographer, this would be one. That's a terrible presentation for a lot of great information.