News for hackers. Stuff that matters.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by jpittis on Saturday June 15, 2019 @07:20PM (#20192815)
> I think the smaller differences are also large enough to rule out extraordinary claims, like the ones I’ve read that say writing a compiler in Haskell takes less than half the code of C++ by virtue of the language

Specifically the "by virtue of the language" part:

Seems to me like it's unreasonable to claim the languages are on equal footing because fancy parser libraries aren't allowed to be used for the project. The fancy parser libraries exist for certain languages specifically because the languages enable them to be written. (For example in Haskell: monadic libaries, libraries that take advantage of GADTs, etc.)

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by trishume on Saturday June 15, 2019 @07:25PM (#20192826)
I don't think monadic parser libraries have a real claim to be that difference. All the languages listed have excellent parsing libraries that make things similarly easy, if not by language power than by grammar DSL with embeddable code snippets.

I think if any library could make a real difference for Haskell it's most likely to be http://hackage.haskell.org/package/lens, which a Haskeller friend of mine claims could likely make a lot of the AST traversal and rewriting much terser.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pwm on Sunday June 16, 2019 @08:48AM (#20195212)
While I found your article informative and interesting I think it only works in the very specific context of this assignment. Disallowing powerful language features/libraries means it's not a level playing field and thus not a fair comparison. Some languages standard libraries are tiny some are huge. Some languages have lots of advanced features. Eg. GP mentioned GADTs with which one can write type safe/correct by construction ASTs. In other words programs passing specific tests in a specific context does not imply they are comparable in terms of general correctness/robustness/maintainability (as you noted this re caught edge cases).
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by howenterprisey on Saturday June 15, 2019 @07:52PM (#20192939)
Hoopl (data flow analysis) would also make a difference. I did a very similar project at my university in Haskell and Hoopl definitely saved us from writing quite a bit of code. We also used parser combinators in the frontend, which I think saved us time too.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by anaphor on Saturday June 15, 2019 @09:51PM (#20193351)
I've found PEGs (Parsing Expression Grammars) to make things extremely easy and terse. E.g. OMeta, Parsley, etc.

My experience with using both PEGs and parser combinators is that there isn't a huge difference in the total number of lines of code. On the other hand though, the syntax of PEGs would be easier to understand for someone who is familiar with BNF style notation.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pyrale on Sunday June 16, 2019 @02:08PM (#20196941)
Recoding a viable subset of lens would have taken 50 locs in haskell. Likewise, rewriting parser combinators would not have taken long for experienced devs. The problem here is that requiring people to recode the libs on top of the compiler is disingenuous. And if you ban idiomatic libs, you also ban most online help, tutorials, etc.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by loup-vaillant on Sunday June 16, 2019 @03:26PM (#20197385)
(A suitable subset of) Parsec is about 100 lines of OCaml. Implementing a PEG syntax on top of it is about 150 lines of Haskell (or less, I'm a Haskell noob).

Building up the knowledge to get to this point however… nope, those students were better off going hand written recursive descent (or Lex/Yacc, since an equivalent was allowed).

https://github.com/LoupVaillant/Monokex/blob/master/src/pars...

http://loup-vaillant.fr/projects/metacompilers/nometa-haskel...

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by steveklabnik on Saturday June 15, 2019 @08:30PM (#20193078)
My understanding is that in production compilers, hand rolled parsers are the norm. Parsing libraries are cool, but just aren’t used for big projects.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by sanxiyn on Saturday June 15, 2019 @10:31PM (#20193493)
Both OCaml and GHC use parser generators. It is incorrect to suggest production compilers hand roll parsers.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by steveklabnik on Saturday June 15, 2019 @11:51PM (#20193749)
Two counterexamples does not disprove “a norm”. There are always exceptions!
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by nybble41 on Sunday June 16, 2019 @12:15AM (#20193814)
Right, to prove or disprove the norm one would need much more information. Two counterexamples does, however, disprove that "Parsing libraries ... just aren’t used for big projects." GHC and the OCaml compiler are both big projects, and they use parsing libraries.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by fnord123 on Sunday June 16, 2019 @04:50AM (#20194571)
I think big here means impactful.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by grumdan on Sunday June 16, 2019 @06:01AM (#20194762)
Describing two well-engineered compilers of two relatively used languages as not impactful is quite a statement. In particular, given the good performance results they achieve, for languages that are quite far away from the normal execution model of the machine they produce code for.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by fnord123 on Sunday June 16, 2019 @06:32AM (#20194842)
>two relatively used languages

Relative to what? Haskell and OCaml are important languages for PLT but not in the context of "production", or as I understood "production" to mean: shipping products with features. To call them anything but niche players in this context is not accurate in my opinion.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by grumdan on Sunday June 16, 2019 @07:02AM (#20194916)
As in, there are a handful of large projects the languages are used for. For Haskell, Facebook's spam detection system, Sigma[1], comes to mind, along with some use by banks (Standard Chartered); then there's a bunch of smaller places using Haskell (Wire, a secure messaging app, like Signal; Galois, a US defense contractor doing software verification and related things) plus some open-source tools like pandoc.

I know less about OCaml, but at least Jane Street is using it.

It's somewhat niche, but it's not like it's only used for hobby or toy applications.

[1] https://code.fb.com/security/fighting-spam-with-haskell/

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by floatboth on Sunday June 16, 2019 @10:58AM (#20195763)
Facebook's static analyzer Infer https://fbinfer.com is written in OCaml.

There's a lot of OCaml in the program verification space: https://frama-c.com http://why3.lri.fr https://alt-ergo.ocamlpro.com

And for mysterious reasons, OCaml is now kinda popular for.. web frontends. Bloomberg created an OCaml-to-JS compiler https://bucklescript.github.io and Facebook (again!) created an alternative syntax https://reasonml.github.io and this combination is apparently a new hipster way of writing web apps.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by jcora on Sunday June 16, 2019 @07:09AM (#20194933)
I don't think language use industry-wide is a good metric for how relevant compiler software is. It is entirely imaginable that a very serious compiler that proves the original point exist for a language with very rare industry use.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by grumdan on Sunday June 16, 2019 @07:27AM (#20194974)
Another point is that Haskell and OCaml popularized features and styles that are making their way into mainstream languages (e.g. option types instead of null, immutability by default), and the compilers showed that they can be implemented efficiently.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pyrale on Sunday June 16, 2019 @02:16PM (#20196997)
Both GHC and ocaml have a pretty good claim at being among the most influential compilers of their generation.

If you look at Java for instance, generics were made by one of the Haskell creators, and it has been implementing functional features for years now.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tomasato on Saturday June 15, 2019 @10:18PM (#20193457)
Excluding the lens library (as per the article) is unusual, it provides natural getter/setter and row polymorphism type functionality.

More anecdotally, I’d argue parsing libraries are common, just look at the prevalence of attoparsec and others. But most parsing libraries in the ecosystem are parser combinator libraries which don’t support as performance and nice error messages that compilers need

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by garmaine on Sunday June 16, 2019 @12:27AM (#20193836)
That was where I stopped reading. If a library like lens—used by nearly every haskeller in every project—was disallowed, I don’t know what the purpose of this exercise was.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pyrale on Sunday June 16, 2019 @02:23PM (#20197044)
Lens is far from being used by everyone in the space. On a sample of 5-6 professional users I talked with at this zurihac, most didn't use it.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by aliceryhl on Sunday June 16, 2019 @05:01AM (#20194598)
I mean, it seems like it was an university course, and writing a compiler from scratch is probably a decent exercise in a compiler course.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by garmaine on Sunday June 16, 2019 @05:47AM (#20194709)
Restrict the students from using a parser library. I get that. But allowing nothing except that standard library? That’s stupid.

It also makes the language comparison useless. Python has a standard library that is continuously improved and people reach to that when writing programs. Haskell, like C, ossified it’s standard library when it was created and people use the external packages for equivalent up to date libraries.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by Ericson2314 on Sunday June 16, 2019 @05:44PM (#20198094)
Parsers are not the interesting parts of compilers.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tathougies on Sunday June 16, 2019 @12:17PM (#20196230)
I dunno, libraries like earley in Haskell, provide pretty nice error messages.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by willtim on Sunday June 16, 2019 @03:08AM (#20194248)
It depends entirely on whether the big project still has an elegant and complete formal grammar. Hand-rolled parsers are only common in industrial languages because many have grown to be far too complex and ad-hoc, requiring e.g. additional analysis and disambiguation during parsing. It is not a situation to aspire to.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Saturday June 15, 2019 @08:40PM (#20193111)
A typical translation of C++ code into D reduces the line count by a substantial amount, simply because D doesn't require .h files.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by jancsika on Saturday June 15, 2019 @09:54PM (#20193365)
What are relative compile times like?

Building Chromium atm, and to be honest I'd be happy if it were written in a trillion lines of BASIC if that would somehow achieve even a 10x build time speedup.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by Shoop on Saturday June 15, 2019 @10:27PM (#20193480)
D is known for having an extremely fast compiler. In fact, Walter Bright wrote one of the fastest C++ compilers (the Digital Mars C++ compiler) before he wrote D.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by z3phyr on Saturday June 15, 2019 @10:40PM (#20193524)
For chromium, the most important concern will be runtime speed, more than compile time
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pjmlp on Sunday June 16, 2019 @03:45AM (#20194355)
Languages with native support for modules can have both.

Lets see how C++20 will improve the situation.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by earenndil on Sunday June 16, 2019 @03:06AM (#20194238)
That, and most people who are compiling it are chromium developers, who will be using dirty builds and so have relatively quick compiles.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pjmlp on Sunday June 16, 2019 @03:44AM (#20194353)
Think Delphi and .NET Native compile times.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by datashaman on Sunday June 16, 2019 @12:59AM (#20193921)
I assume you are using ccache?
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @09:08PM (#20193213)
Using a fancy parser-library would mean we should also count the lines of code in it. It would basically mean adapting an existing solution. In practice that would make a lot of sense, but if the purpose is to compare the productivity of different languages then not so much.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by geofft on Saturday June 15, 2019 @09:16PM (#20193232)
Isn't it a facet of productivity of the language that it's easier to write certain types of libraries in one language than another? If you're writing a compiler, the fact that lots of people write parser libraries in Haskell is a point in favor of Haskell, whether if you intend to use those libraries (because they're available and production-tested) or you intend to write your own (because it's demonstrably a productive language for that sort of work).
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @09:54PM (#20193363)
Yes from the outset. But this study was about writing a parser and it seems Haskell didn't do much better than the others.