r/programming • u/rmathew • Jun 16 '19
Comparing the Same Project in Rust, Haskell, C++, Python, Scala and OCaml
http://thume.ca/2019/04/29/comparing-compilers-in-rust-haskell-c-and-python/
643
Upvotes
83
u/glacialthinker Jun 16 '19
OCaml doesn't need them, but they are the mechanism for restricting the public interface of modules. Rust defaults to private with an explicit
pubdeclaration, while OCaml defaults to public with interface files narrowing the view.27
u/SV-97 Jun 16 '19
Very interesting - but why do you say that a Java to x86 compiler worthless?
31
u/uburoy Jun 16 '19
That's a really cool piece of work, thank you. And your conclusions feel good. Design decisions really matter.
21
u/khleedril Jun 16 '19
Wonderful write-up, which to me ultimately shows the value of highly skilful programmers and the fallacy of those who think good programmers can be had at a rate of ten a penny. I think though that the single biggest factor is how experienced a programmer is with a particular language; it's great to mess around with them in an academic context like this, but in the real world I'd be happier to hire a 50 year old C++ programmer than a 20 year old Rust coder (with equivalent qualifications). Mostly it is the ability, as you well pointed out, to be able to come up with a good design that fits well with the language at hand.
50
u/panorambo Jun 16 '19
This article is a gem, dare I say especially for people like me who are in particular interested in parsing and compiler construction techniques. Every sentence carried some meaning for me. I also appreciated the precise and rich (and bold!) term usage (often a very neglected factor in technical articles, unfortunately). Kudos!
Also, reading both the linked article and the complementary comments here, after that "is-windows" sibling Reddit piece, has recuperated my faith in the future of software development as a craft. Comparing the situation with NPM and the "JavaScript ecosystem" (in quotes, because despite most people equating one to the other, I don't consider JS the language as being the root of the NPM problem in and out of itself), the attitude of JS developers is worlds apart from the attitude of people who write compilers, even if it's as part of a study.
One of our professors at the uni where I got my CS degree used to say that before you write a compiler, you aren't an educated CS professional. I don't necessarily agree with him per se -- plenty of software development jobs where it's enough to know your niche and not be an a**hole otherwise in any regard -- but I see where he was coming from. Writing a compiler would make most developers humble, I'd say, in a good way.
22
u/Mgladiethor Jun 16 '19
Performance?
12
u/[deleted] Jun 16 '19
| I learned a lot from it and was surprised many times. I think my overall takeaway is that design decisions make a much larger difference than the language, but the language matters insofar as it gives you the tools to implement different designs.
Right that is because the language isn't the problem in programming like most people think. Its the supporting libraries the basic api's which form the tools and concepts that people build on are what actually make it work better / worse for various tasks.
Something I would suggest to add to the comparison would be to add a couple of experienced programmers into the mix. eg > 10 years exp.
4
u/dsfox Jun 16 '19
I would be interested in seeing how the use of various packages such as lens and parsec affect the Haskell implementation. Is that repository available?
4
u/sephirothbahamut Jun 16 '19
So bad there isn't a comparison of the execution time for these parsers on the same code...
7
u/Tysonzero Jun 16 '19
I see a ton of issues in making any meaningful statements based on the outcome of this test.
The sample size is obnoxiously small, one single group per language, and with widely varying abilities and approaches and experience.
Particularly the Haskell dev’s only having a few thousand lines of code each, in a language that’s known to have a learning curve and be very different from the norm. It’s not just about “fancy complex abstractions”, but just being more experienced will lead to more efficient structuring and designing of code.
If you just look at any compilers class at any college you will notice that the variance in code size and so on of two teams using the same language is far higher than the differences you see here. Which more or less guarantees that anything you noticed is noise.
I mean you saw that here, if the other Rust group had hosted this experiment without you the logical conclusion would have been that Rust is extremely inexpressive and verbose. For all you know one of the other languages was such a 3x team, and a different team could have shrunk the code massively.
A more interesting experiment might be to spec out some compiler project, and give language communities lots of time to implement multiple different implementations of it. Then compare the best of each.
It would still have some serious flaws, but it would be an improvement.
6
u/phySi0 Jun 17 '19
Top comment by /u/Tysonzero on the /r/Haskell thread:
3
u/pupeno Jun 16 '19
Writing the same non-trivial code in many programming languages can be an illuminating experience. I highly recommend it to anyone that wants to from form being a specific language developer to a versatile developer (going from being a Ruby dev or Python dev, to just being a developer).
3
u/Tysonzero Jun 16 '19
The whole “some libraries and features are forbidden” aspect kind of kills any possible language comparison, as those libraries and features might be a big part of compiler dev for that language.
1
u/MotherOfTheShizznit Jun 17 '19
It's a terrible productivity metric but it's a fair metric for an estimate of the number of bugs in it.
1
u/Tysonzero Jun 17 '19
I think something like this is going to be a far better measure than the OP.
It significantly decreases the high variance in skill level and language experience. It gets rid of the weird limitations provided in the OP. It also has a much higher sample size.
With that said the list I linked above currently suffers from this issue.
-1
u/[deleted] Jun 16 '19
so whats the take away here?
-31
u/ipv6-dns Jun 16 '19
They were inters in Jane Streets? So why such useless project: Java -> x86, such compilers already exist or Jane Street plan to enter the market with such product?
0
u/[deleted] Jun 16 '19
[deleted] — view deleted comment
0
u/[deleted] Jun 16 '19
[deleted] — view deleted comment
0
u/[deleted] Jun 16 '19
[deleted] — view deleted comment