News for hackers. Stuff that matters.
Re:Blessed Are the JavaScript Developers by manquer on Monday August 31, 2020 @12:22PM (#24332965)
It is not obvious that you need to include comparative function for a straightforward numerical sort ? How many developers are going to miss that ?
Re:Blessed Are the JavaScript Developers by Supermancho on Monday August 31, 2020 @12:45PM (#24333224)
> It is not obvious that you need to include comparative function for a straightforward numerical sort ?

No. It's not obvious.

Python -

    a = [6, -2, 2, -7]

    a.sort()

    print(a)
PHP -

    $arr = [6, -2, 2, -7];

    sort($arr);

    print_r($arr);
Rust -

    let mut vec = vec![6, -2, 2, -7];

    vec.sort();

    assert_eq!(vec, vec![-7, -2, 2, 6]);
The expected behavior is a default natural number sort.

What other default was chosen? String comparison for some value of Strings, coerced from the integers in some way.

If you have to research a bunch of implicit behavior to understand how sort works for numbers. I believe that's unintuitive by definition (simplest case is more complex than necessary). Fixable with a required flag or specialized functions (eg PHP).

Re:Blessed Are the JavaScript Developers by SamReidHughes on Monday August 31, 2020 @01:56PM (#24334091)
It was more intuitive back in the day when everybody knew Perl.
Re:Blessed Are the JavaScript Developers by sukilot on Monday August 31, 2020 @01:23PM (#24333691)
> "numerical"

JavaScript is weakly typed, so it's never appropriate to assume such a thing without applying a type conversion. Sad, but true.

> "Straightforward"

Again, this is JavaScript.

Re:Blessed Are the JavaScript Developers by amiantos on Monday August 31, 2020 @12:43PM (#24333201)
Probably every developer, but only the first time... if they catch it anyway.