Hacker News new | past | comments | ask | show | jobs | submit login
Hyperpolyglot (hyperpolyglot.org)
249 points by tosh on Dec 28, 2016 | hide | past | favorite | 45 comments



Lua conditional expressions look like this:

    x > 0 and x or -x
It says none in the reference, which is wrong, so I'm posting it here in hopes the author might fix it.

Edit:

Found a bunch more things they got wrong.

    * Bit operations: It says "none", but it's present in Lua 5.3 and LuaJIT.
    * Hex literals are prefixed with 0x
    * String capitalization is used with string.upper, but it says "none".
    * Arrays as function arguments is table.unpack(t), or just unpack(t), depending on the Lua version.
    * Iterate over range is for i=1,100 do --[[ code here ]] end
    * The dictionary size example uses a loop, when you simply could have used #d
    * Sort by values is table.sort
    * Command line options are ...
... Anyway, I have to go. There are way more errors in this, with regards to Lua anyway. I wouldn't use this reference.


Add closures to the list. Also, I thought it's really strange that scripting languages 1 and 2 have different tables. Even if the tables were complete and accurate, can't compare javascript and lua because the rows are different.


It looks like they take contributions: https://github.com/clarkgrubb/hyperpolyglot


I don't think the author should "fix" this. If these are language features but undocumented, then for all intents and purposes they don't exist.


When I said undocumented, I was saying that it's undocumented in this reference. I'll edit that part out to avoid confusion.


Can we have an IDE that let's us use our favourite syntax with other languages, please? Auto-correct, suggest syntax, advise on proper usage/best practice/pitfalls in target language.

We already have autocomplete, stubs, and smart guessing which library I might need to include. People probably repeat the same typical mistakes thousands of times each day as they transition between languages. So just allow us to use fundamental programming concepts and take care of the details for me!

If we were able to use our syntax of choice, and "reformat" existing code to our preference, we would probably all be much more inclined to move on to newer languages and thus advancing the field much faster.

"Looks like you're coming from VBA, remember in this language arrays start at 0..."


Theoretically this seems possible with Haxe (http://haxe.org/manual/introduction-what-is-haxe.html). It seems possible to write something that went from Python -> Haxe -> Java?

Right now all I know for sure is that Haxe offers Haxe -> Python in sourcecode (though an AST would be better, probably), and Haxe offers Haxe -> C++...

Generally, it might make more sense to go from AST to AST then back to source code or something, if you didn't need to see the source code after.

I personally appreciate that different languages have different syntax. In some languages it doesn't matter (because they're so close anyway), but across large gulfs there are non-negligible differences in productivity, IMO. If I need to write lots of regexes and do some small scripting or write something no one will understand later, perl's syntax might shine there, it would be bad (I think) to get into the habit of writing in one syntax or with one syntax when there are better syntaxes that might cut down on writing time for the job... Of course, there is the benefit of cutting down unnecessary writing by using perl INSTEAD of something like Java by using this idea...


*AST -> AST -> vm/interpreter bytecode/machine code


...and commit in the syntax of choice of target repo automatically as well.


I've been writing Go for the last 18 months, and seeing it dissected side-by-side with C [0] is causing some epiphanies that I wouldn't normally get to see in day-to-day programming.

Excellent resource.

http://hyperpolyglot.org/c


Its discussion of stack vs heap is not entirely accurate:

    // memory allocated on heap:
    ptr := new(int)
    *ptr = 7
Depending on how ptr is used, escape analysis may place *ptr on the stack. Also note that the terms stack and heap are not directly comparable between languages anyway.


The biggest difference is that you cannot actually force Go to allocate on stack (which is the only important use case in this context), the escape analysis only works for primitive cases, but throw a higher order function into it and it fails.


Out of interest, could you give some examples of these epiphanies?


> capitalized top-level identifiers are exported

I saw this and thought that it's just weird and confusing. Why would someone make case-sensitivity a syntax for exports?


One less keyword in the language, and you can tell at the call site whether it's an internal function.


it's also used in erlang and haskell, which happen to also use "_" for "don't care"


I find it funny that the C code is in a larger font than the Go code.


It is not for me.


The stated integer divide-by-zero behavior of golang is incorrect.

Whether the process is sent a SIGFPE or not, from the programmer's experience a x/0 will cause the offending goroutine to panic with a divide by zero runtime error (integer divide by zero) which, unlike a signal, can be recovered.


Quite a few errors for Haskell. 'n <- return 3' is NOT a way to create a mutable reference. Silly things like that are scattered all around.


I agree. The Lisp dialect page for example, has:

- inaccuracies (e.g. word separator in CL depends on current readtable), which is understandable given the very terse format

- missing cases (e.g. no compiler for CL?)

- and factually wrong elements (identifiers are case sensitive, but upcased while reading by default; they can starting with numbers, like 1+, etc.).

Fortunately there is a way to fix that: https://github.com/clarkgrubb/hyperpolyglot/issues


Nor is it a way to achieve anything useful. Might as well just write “let n = 3”. :-p


http://rosettacode.org/wiki/Rosetta_Code is also an interesting site for similar problems


Rosetta Code is cool, but I've long been looking for a "Rosetta stone" type of tool to show the equivalents of lower level operations in various languages. Recently I found a good resource for matrix operations (http://sebastianraschka.com/Articles/2014_matrix_cheatsheet....). This however covers other topics and languages as well . Another gem to add to my bookmarks :-)



When looking at scripting languages, there's a couple problems.

What does "no encoding" mean, or "constant by convention"? Can I write gibberish UTF32 in PHP and it won't care? Can I modify one of this "by convention" constants without a parsing error?


Could be wrong, but constants are all UPPERCASE by convention in a few different languages, I think that's what that means. I don't think this would break anything, I think it's supposed to make the code easier to read/nicer for handing off code to another developer. I don't use Python, but I have seen it in PHP, Ruby, and Javascript and they don't break there.

PHP handles encoding in a very naughty way. I don't know the origins behind this, I only know that it will produce text in the wrong format at times.

I have had issues where I would try to get some JSON with Japanese text and it will produce some janky unicode that doesn't work. There are work arounds for specifying encoding, but it's contingent upon what version of PHP you are using (I am stuck on 5.3.2 for a legacy, closed sourced app with a custom PHP binary).


> Can I modify one of this "by convention" constants without a parsing error?

Depends on the language. Python does not enforce constants, so you can modify them freely. JavaScript as of the ES5 spec did not enforce constants, but ES6 does. Ruby mostly enforces constants, but there are certain bits of metaprogramming that will allow you to overwrite a constant if you are determined enough.


Is this managed by an individual or is it something open-source that can be contributed to?

Edit: Nevermind. Found https://github.com/clarkgrubb/hyperpolyglot


I remember a similar site with someone who set it up as a "learn a language in a jiffy" where it was set up sequentially instead of a cheat sheet. Had languages like Python and Ruby, can't remember the rest.

I haven't been able to find it, but it was a really useful resource, and I wish I could remember what the name was.


That might have been https://learnxinyminutes.com. It's pretty useful as a quick reference if you're switching languages a lot.


That's an awesome site, but it's not the one I failed to remember. That one had a few pages for each language showing you lists and the like.

Will bookmark this, though.


I use this quite often and find it really helpful, thankyou to the founder if you're listening.

It'd be even better if it was wiki-editable so that people can make improvements without having to use git. It would also be great if the language functions used (like strpos) linked to official documentation.


This. I've found a few minor glitches and would've already submitted them while reading if there was a faster way to do it.


Some of this is incorrect like the PHP bit about "expression interpolation". Here is an example:

   <?php
           $hello_world = 10;
           $two = "two";
           echo "hello_world = $hello_world\n";
           echo "two[1] = {$two[1]}\n";


It is a strange example, but it looks correct. What's wrong with it?

Also, you can always open up a PR on https://github.com/clarkgrubb/hyperpolyglot


Would be good to add some concatenative languages to that list :)

http://evincarofautumn.blogspot.com/2012/02/why-concatenativ...


There is a "Forth, PostScript" section.


I find it interesting they essentially say 'node.js is a scripting language'. I dont get that. As far as I know, Node.js is a js interpreter with extra system api bindings. How would that make Node.js the language?


Kudos to the author for compiling these. One note: Maxima can do fast Fourier transform, too (with fft and inverse_fft).


this is a good idea, creative commons so it's ok to scrape I think...

I'm interested in using nodejs to replace bash scripting, I loathe doing any kind of logic in bash and I just want to excise it. No maven or gradle for build tools. I'll revisit later.

Good domain name as well, easy to memorize, good job.


Math.min.apply(Math, [1, 2, 3]) Math.max.apply(Math, [1, 2, 3])

Could just be:

Math.max(...[1, 2, 3])


The JS code is written in ES5 so this syntax is not available.


There are several other examples which show both ES6 and ES5 syntax, there is no reason the better ES6 syntax couldn't be shown here as well.


This is such a great project :+1: for putting it together




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: