News for hackers. Stuff that matters.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by zmmmmm on Saturday June 15, 2019 @09:34PM (#20193285)
Seems like a bit of a bold claim when the author themselves directly contradicts that in their own conclusion:

> I think my overall takeaway is that design decisions make a much larger difference than the language

After all, Scala was 0.7x the size and is one of the most strongly statically typed languages. So you could almost invert your conclusion and say the big result is

"Python only saved 20% code lines over fully statically typed language"

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @10:06PM (#20193406)
No I would not reach quite that conclusion I would say "Python saved 20% code lines over Scala!".

The results say something about the greatness of Scala, not of statically typed languages in general. The other ones did not do quite as good as Scala.

From what little Scala I've read it looks very terse indeed. That can be a benefit but at the same time makes it harder to understand code written in it, in my opinion.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by zmmmmm on Saturday June 15, 2019 @10:41PM (#20193533)
I think most people would consider 20% basically within the margin of error induced by stylistic and other non-meaningful differences.

For example, it's not completely clear from the post but it seems like the 0.5x figure is from wc -l, which means Python wins a line every time there is a conditional or loop just because it doesn't need a closing brace. That alone might eat up a lot of the 20%, but you would be hard pressed to say that is a meaningful difference.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @11:08PM (#20193610)
My surprise from this study was simply that dynamic languages are clearly not much worse than the best-of-breed statically typed languages. Maybe 20% is within the margin or error, but you definitely can't take that as any evidence that Scala is "better" than Python.

The reason I think this is "big big news" is I thought the general consensus had already been reached in academia if not the programming community that "statically typed functional languages are much better". There's little or no evidence of that in the results of this study.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by esarbe on Monday June 17, 2019 @10:12AM (#20203132)
I don't know where you get that. This is about code base size. Dynamically typed languages have always had fewer LOC than statically typed languages.

If there's a surprise, it's that Scala is able to snuggle up to Python so nicely, while being one of most strongly typed languages.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by mannykannot on Sunday June 16, 2019 @08:38AM (#20195183)
It is actually nearly a 30% reduction with respect to the Scala line count.

More to the point: while the numbers nominally show differences in languages, everyone with programming experience recognizes that unmeasured and uncontrolled human factors probably had a big part in the outcome.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Saturday June 15, 2019 @09:47PM (#20193330)
One factor on why Python only saves 20%.

Scala has a very rich standard library. Python doesn't. An example is: https://stackoverflow.com/questions/363944/python-idiom-to-r...

Ruby would have been a better example of how succinct a dynamic-typed language can be.

(I made a similar comment on the parent level.)

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by saagarjha on Saturday June 15, 2019 @10:15PM (#20193438)
> Scala has a very rich standard library. Python doesn't.

This is not something I could have expected someone to say about Python's standard library…

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Saturday June 15, 2019 @10:58PM (#20193577)
I know. It's strange to say that. But Scala's library is very very rich.

Another example is that Scala offers a lot of ways to process a list like foldLeft, foldRight, unzip, headOption, lastOption, flatMap, groupBy, and many methods around Map, Set, and etc. Python probably doesn't offer many of these methods.

Of course, this comes with the cost of higher learning curve.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by xenator on Sunday June 16, 2019 @01:01PM (#20196496)
List of standard methods of this kind https://docs.python.org/3/library/itertools.html
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Sunday June 16, 2019 @02:25PM (#20197064)
Yes, itertools is great. But its stblib is still much lighter than Scala's and Ruby's.

Actually, that seems to be the direction/principle of Python, where it is less inclined to add a helper function.

"It has been discussed ad nauseam on comp.lang.python. People seem to enjoy writing their own versions of flatten more than finding legitimate use cases that don't already have trivial solutions." from https://softwareengineering.stackexchange.com/questions/2542...

Not that this is better or worse. It's just that, on the brevity aspect, Python code is gonna be longer.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by dragonwriter on Saturday June 15, 2019 @11:55PM (#20193764)
I don't see how that example is relevant, because:

(1) It shows Python expresses the concept fairly compactly in the core language without even resorting to stdlib,

(2) It ignores an option (also in the core language) using a ternary and the truthiness of lists: my_list[0] if my_list else None

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Sunday June 16, 2019 @12:28AM (#20193839)
While what you say is true, my small example shows that the code is longer in Python for solving the same problem, i.e. `my_list[0] if my_list else None` is longer than `my_list.headOption` or `my_list.first`.

And we are talking about the brevity of a language here.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by ibejoeb on Saturday June 15, 2019 @10:32PM (#20193497)
I'm not sure what your example is illustrating. The SO question asks for the idiomatic one-liner to get the first non-null element of a list. The accepted answer does that.

    next(iter(your_list), None)
This is 100% standard library.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Saturday June 15, 2019 @10:45PM (#20193542)
Maybe I should have given the comparable example in Ruby, which is `array.first`. Even Scala offers `array.headOption`. Both are more succinct than Python's.

The degree of richness and/or the height of abstraction seem lower in Python. (Not that this is a bad thing. It depends on people's taste, of course.)

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by zmmmmm on Saturday June 15, 2019 @10:54PM (#20193565)
Python is indeed very frustrating that way. So many of its limitations and flaws are justified on the basis of clarity and then there are this array of very simple things that can only be expressed in unclear ways which every other language offers a solution for.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Saturday June 15, 2019 @10:59PM (#20193582)
A comparable example from JavaScript, there is no library-method for getting the last element of an array, so it gets clumsy: myArray [myArray.length - 1]. A better standard library would provide a method for that: myArray.last(). Or maybe myArray[-1].
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Saturday June 15, 2019 @11:02PM (#20193588)
That's a great example. And, yes, Javascript has a similar problem.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by vesche on Saturday June 15, 2019 @11:21PM (#20193659)
Sounds like you just don't like Python, but you don't have great reasons for not liking it. The standard library is fantastic in Python. Find better reasons to back up your unfounded dislike.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Sunday June 16, 2019 @12:35AM (#20193856)
Saying Ruby/Scala have richer standard lib than Python isn't really a stab at Python.

Like dragonwriter says, it shows that "Python expresses the concept fairly compactly in the core language without even resorting to stdlib".

It depends on your taste whether you like richer stdlib, and I do. But some don't.

We are talking about how short the code can be in this post, and `my_list[0] if my_list else None` (Python) is longer than `my_list.headOption` (Scala) or `my_list.first` (Ruby).

I'd appreciate more if you elaborate why my example isn't a good illustration on the brevity aspect.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by zapzupnz on Sunday June 16, 2019 @04:27AM (#20194474)
I think there are just a lot of people here getting touchy and defensive because other people aren't automatically leaping to false conclusions from this article's data, preferring to imagine that the article validates their personal choice of favourite programming language rather than engage in proper speculation about the quality of the conclusions made within the article.
Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by galaxyLogic on Sunday June 16, 2019 @11:25AM (#20195916)
I would agree that the sample size was small so programmer competency may be a big factor.

The interesting takeaway from this study I think is that it does not show that statically typed (even "pure") functional languages are not obviously better than plain old Python.

The interesting thing is not what this study proves, but what it does not prove.

Re:Comparing the Same Project in Rust, Haskell, C++, Python,... by tanin on Sunday June 16, 2019 @12:41PM (#20196395)
> The interesting takeaway from this study I think is that it does not show that statically typed (even "pure") functional languages are not obviously better than plain old Python.

Could you elaborate more on this statement? Not a native english speaker here, so I don't quite understand the sentence. Thank you.