Comment by neonsunset
1 year ago
The following is probably going to be a closer comparison:
let arr = [1, 2, 3, 4];
let max = arr.reduce((a, b) => Math.max(a, b));
Or C# and Rust (which will be >100x faster at finding max value[0][1]):
var arr = new[] { 1, 2, 3, 4 };
var max = arr.Max();
let arr = [1, 2, 3, 5];
let max = arr.iter().max();
Ruby does nail the minimalism in this code golfing example, but it does not offers uniquely high productivity to the end user, which is a frequently brought up point in defense of interpreted languages whenever their shortcomings are mentioned. Lacking static typing, Ruby users have to resort on e.g. Sorbet, which is a worse experience and numerous comments on HN seem to provide negative feedback on it.
I do actually hate to mention performance every time, but it's difficult to not do so when apples-to-apples comparison can be made. Compiled statically typed languages with GC offer similar or better (because the code is verified by compiler, not Sorbet) productivity without any of the drawbacks that come with Ruby.
This is to illustrate the point about the languages that do come with rich standard library, that also happen to go to great lengths at ensuring that shortest way to express something is also the fastest whenever possible.
[0]: https://github.com/dotnet/runtime/blob/main/src/libraries/Sy...
[1]: https://godbolt.org/z/srfWE9qcE
(the >100x figure is not an exaggeration)
No comments yet
Contribute on Hacker News ↗