News for hackers. Stuff that matters.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by bfung on Saturday June 15, 2019 @08:23PM (#20193048)
Excellently written, great topic, and done w/o flaming/too much bias. I'm amazed as many older folks in the industry would not be able to have this level of content and maturity to write an informative article.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Saturday June 15, 2019 @08:44PM (#20193123)
It's difficult to write a fair comparison without being a fairly competent programmer in each of the languages. The trouble is, if a person is an expert C programmer and then translates it to Python that he's only modestly familiar with, the Python program will look like C. It won't be idiomatic Python.

For example, my early Fortran programs looked like Basic. My early C programs looked like Fortran. My early C++ programs looked like C. And my early D code looked like C++.

It takes much more than being able to write a program in X to be able to write one that makes proper use of the language.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @09:02PM (#20193189)
That is all true. At the same time here the groups were allowed to use the language of their choice. Presumably they chose languages they felt they were competent in.

Of course an expert of a given programming language can write much better in it than a novice. But a comparison like this is not necessarily about comparing top-programmers in every language, but average programmers, because we want to know results that are true "on average" .

The author does note he "knew (they) were highly competent". So they were not exactly novices in their language of choice. Writing a compiler is not a task for novices in general.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tigershark on Sunday June 16, 2019 @12:42AM (#20193889)
There were people with 2k to 10k loc of experience in some language. That seems extremely low for any meaningful comparison and I would really hope that “average” programmers have way more experience than that... I think I was pretty junior after writing north of 100k loc and working on 1M loc projects. And for sure I don’t consider myself highly competent in F# after writing some thousands lines. I agree with the conclusions when they say that the design decisions are much more important than the language of choice. But I still firmly believe that the language makes a very big difference in real world projects. In toy throw away projects obviously metaprogramming cuts a lot of locs.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by jodrellblank on Sunday June 16, 2019 @06:27AM (#20194831)
When reading about APL recently, arcfide - the chap working on a GPU compiler - has expressed that he likes APL's terse code because you can throw it away and rewrite it without too much trouble. His compiler is around 750 lines of code after 6 years of development, but[1]:

"If you look at the GitHub contributions that I've made, I've made 2967 of about 3000 commits to the compiler source over that time frame. In that time I've added roughly 4,062,847 lines of code to the code base, and deleted roughly 3,753,677 line of code. [..] It means that for every one of those 750 lines, I've had to examine, rework, and reject around 5400 lines of code."

Yet a 750 loc codebase sounds like someone with very little experience and a few days or a long weekend.

I'm not saying only the trivial "some languages are denser than others", but also that it would be interesting to compare projects in total lines of code written including all commit history, and that it would be interesting to compare people's experiences and project designs in terms of "how many times something got implemented in several ways before settling on a final version", or "writing once and the design got set in concrete because it was too big to bother changing", how many prototypes that work differently were explored before deciding - and what that does to people's skills, and to project designs.

I'm guessing thousands of lines of F# would make you more skilled than the same thousands of lines of C#, even moreso if the F# was higher-abstraction than the C#, would you agree?

[1] - https://www.sacrideo.us/smaller-code-better-code/

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by nybble41 on Monday June 17, 2019 @01:06PM (#20205039)
> Yet a 750 loc codebase sounds like someone with very little experience and a few days or a long weekend.

For the purpose of evaluating experience you count the total amount of code written, not the final codebase size. Four million lines of code is a fair bit of experience in any language, even if most of those lines were later deleted or replaced.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Sunday June 16, 2019 @03:24PM (#20197372)
The code I initially get to work is often pretty large and complex. Then going over it again, I can see how to shrink it and make it elegant. And then again, then again.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by Intermernet on Sunday June 16, 2019 @10:08AM (#20195507)
That's the best example of why loc is the worst indicator of both work and talent available. Thanks!
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by ginnungagap on Sunday June 16, 2019 @10:32AM (#20195629)
The github link in [1] is dead, where is the repo now? I was curious about that compiler
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by jodrellblank on Sunday June 16, 2019 @02:53PM (#20197200)
It would be unfair to leave it without the link to the HN discussion where he explains in detail his reasons for writing it that way and defends against a lot of criticism, and video stream walkthrough of the codebase as of a couple of years ago

https://news.ycombinator.com/item?id=13797797

https://news.ycombinator.com/item?id=13638086

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by vedantroy on Sunday June 16, 2019 @12:06PM (#20196152)
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by speedplane on Sunday June 16, 2019 @02:38AM (#20194155)
> There were people with 2k to 10k loc of experience in some language. That seems extremely low for any meaningful comparison ...

It's low if you're comparing languages based on the skills of experienced programmers, but most programmers are not terribly experienced. A comparison of languages by programmers that are novices to the language is still meaningful. A language that is easier for a novice to pick up and write good code is at the very least one good measure for the quality of the language.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by StreamBright on Sunday June 16, 2019 @05:23AM (#20194655)
Sure but 100k LOC Java is bot equal to 100k LOC Rust or Clojure because there is a huge discrepancy between expressiveness of those languages.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by pjmlp on Sunday June 16, 2019 @06:53AM (#20194885)
It also depends if one is using Java 12 or Java 1.4 programming style.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by StreamBright on Sunday June 16, 2019 @09:24AM (#20195316)
Exactly. Even within the same lang, it does not work.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by nybble41 on Sunday June 16, 2019 @12:41AM (#20193888)
> So they were not exactly novices in their language of choice.

The Haskell team had "maybe a couple thousand lines of Haskell each" at the start. This one project ended up being 9.7k lines, so it constitutes half of their collective experience with the language. I'd say that counts as "novice" in terms of prior Haskell experience. Under the circumstances I think they did remarkably well to produce a thoroughly tested and maintainable end product in just twice the lines of code of the quick-and-dirty Python implementation.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by danielscrubs on Sunday June 16, 2019 @04:41AM (#20194533)
I thought it very amusing that the teams focus would reflect the language: The Python implementation was as you say quick-and-dirty, while the Haskell one "caught a few edge cases that our team did not" and the C++-team did "optimizations on their IR".
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by anaphor on Saturday June 15, 2019 @09:22PM (#20193244)
The article says that the instructor for the course cautioned against using Haskell because some people overestimated their competency with it.

I think it is actually very likely that people would chose a programming language or system for reasons other than how competent they are with it. E.g. to seem "smart" because you wrote your compiler in Haskell, even though you actually have much more experience with Java or Python.

FTA:

> Another interesting thing to note is that at the start of every offering of the course the professor says that students can use any language that can run on the school servers, but issues a warning that teams using Haskell have the highest variance in mark of any language, with many teams using Haskell overestimating their ability and crashing and burning then getting a terrible mark, more than any other language, while some Haskell teams do quite well and get perfect like my friends.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @10:18PM (#20193455)
> would chose a programming language or system for reasons other than how competent they are with it

Good point these were students so they were eager to learn new things. Can't blame them.

At the same time much of programming is learning new things continually. Some things are harder to learn and master than others. Seems like Haskell might be one such thing, based on what the professor says.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by anaphor on Saturday June 15, 2019 @10:30PM (#20193488)
Yeah, I think the problem comes when you try to learn too many new things at once. If you're still learning about compilers, then trying to learn about functional programming on top of that is just asking for trouble.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by willtim on Sunday June 16, 2019 @03:00AM (#20194218)
Sounds like he (edit: or more accurately, the university) has hasn't taught them enough functional programming and Haskell.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by epse on Sunday June 16, 2019 @03:20AM (#20194292)
He teaches compilers. Not programming or fp, so definitely not the professors fault
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by willtim on Sunday June 16, 2019 @03:52AM (#20194373)
Yes, but it's still a great pity, as Haskell, a descendent of ML (the "meta-language") is a suberb fit for writing a compiler.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by anaphor on Sunday June 16, 2019 @02:36PM (#20197119)
It's my understanding that UW offers some undergrad courses in Racket, but apparently they're optional so if you hadn't taken that course you might not know much about functional programming.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by 256 on Sunday June 16, 2019 @03:15PM (#20197315)
There is a mandatory compilers-lite course at UW and he teaches the advanced version of it, where the project is to fill in pieces of a Scala-lite compiler written in Scala.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by nine_k on Sunday June 16, 2019 @12:27AM (#20193834)
I'd say that "on average" results may be very misleading, in formal statistics and in results like this. Variance and median are very important: see comments about Haskell downthread. (Ideally you have a histogram.)

In particular, some languages with a good average may contain pitfalls that could lead to abysmal outlier results (e.g. C++ or Scala, in entirely different ways), some would keep you from doing really dangerous things but also would not let you achieve spectacular things (e.g. Go).

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by 59nadir on Sunday June 16, 2019 @02:20AM (#20194113)
> So they were not exactly novices in their language of choice. Writing a compiler is not a task for novices in general.

Only having a few thousand lines of code written in Haskell very much makes you a novice. With that said, writing a compiler in Haskell is actually pretty trivial. It's at the very least considerably easier than most other languages.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by objektif on Saturday June 15, 2019 @09:25PM (#20193253)
How do you like D btw? Is it worth learning for a c++ programmer? I find the syntax very appealing.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by trishume on Saturday June 15, 2019 @09:30PM (#20193268)
Fun fact the person you're replying to is the creator of D, I'm pretty sure he likes it. I've personally played around with D a bit and written maybe 1kloc in it and I like it.

It doesn't have good pattern matching or the borrow checker, but it does have much better metaprogramming than Rust. I think a lot of the metaprogramming used in the Python project could also be done basically as easily in D, which is a big accomplishment.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Sunday June 16, 2019 @01:50AM (#20194039)
D has many characteristics of lifetime checking in that it can track lifetimes across function calls and issue errors for incorrect usage. I've been looking into increasing its reach, and it looks promising.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by mhh__ on Saturday June 15, 2019 @09:48PM (#20193338)
Walter Bright is (along with Andrei Alexandrescu - which should be a good enough reason if you like c++) the BDFL of D.

D won't get you hired (probably), but D is designed with hindsight from a C++ compiler writer and a C++ template wizard: It shows, D is objectively better than C++ is many ways. It's worth checking out, at the very least (It's also not hard to learn, so I say go for it)

An example of the power of D: The Pegged library for D can generate a parser, D code which gets compiled, directly from a grammar specification in a text file [inside a D program, e.g. mixin(Grammar("Your Grammar Here"))]

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Sunday June 16, 2019 @01:46AM (#20194031)
> D won't get you hired (probably)

On the contrary. Many members of the D community have managed to leverage their D expertise into well-paying jobs. Many industrial D users recruit from the D community.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by mhh__ on Sunday June 16, 2019 @05:10AM (#20194617)
Not me though!

I was aware of that but I meant in comparison to (say) Java or JavaScript etc.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by WalterBright on Tuesday June 18, 2019 @04:00PM (#20217741)
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by objektif on Thursday June 20, 2019 @08:37PM (#20238841)
Such a good guy creates a language and finds people job postings for that language. Jokes aside didnt know you were behind D. Thanks for your contribution. I will give it a shot.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by p0nce on Sunday June 16, 2019 @08:16AM (#20195108)
> Is it worth learning for a c++ programmer?

I was a former C++ full-time programmer (4 different jobs in high performance teams, high maintenance etc) and now I'm a D full-time programmer for 4 years.

It's easy to underestimate the difference, but to me _as a user_ those languages are night and day as an experience.

D is learnable, in the sense that your learning will have some sort of ending at one point. D is surprisingly stable too, the front-end doesn't change too much and all 3 compiler share the front-end. And it's somehow forgiving. So the whole experience is tilted towards what you do with it: you feel like "programming", not "programming in C++".

C++ has a few things going for it: it has some sort of mathematical completeness, you can find jobs maintaining C++ codebases for your retirement, and it has an aura of legitimacy. But overall I fear you would live in a much more complicated world, for reduced productivity.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by lelf on Sunday June 16, 2019 @06:00AM (#20194759)
I find compilation times very appealing.

D compiler can compile itself in under 5s (+ 10s for stdlib).

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by vfclists on Sunday June 16, 2019 @03:09PM (#20197290)
From make clean? On what CPU?
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by lelf on Sunday June 16, 2019 @03:39PM (#20197462)
Yes. Zero to working compiler on vanilla MacBook Pro.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by ChuckMcM on Saturday June 15, 2019 @11:42PM (#20193725)
I would have liked to see what a team using C would have come up with in the author's set.