News for hackers. Stuff that matters.
Re:Software in 2014 by ceautery on Thursday January 09, 2014 @07:08AM (#7029980)
"JavaScript is horrible."

  > function byNum(a,b) {return +a>+b}
    undefined
  > [5, 10, 1].sort(byNum)
    [1, 5, 10]
No, it's not.
Re:Software in 2014 by i2 on Thursday January 09, 2014 @08:10AM (#7030212)
Except it is, because your code doesn't work:

  > [10, 1, 5, 1, 10, 10, 1, 5, 5, 5, 10].sort(byNum)
  > [10, 10, 5, 1, 10, 1, 1, 5, 5, 5, 10]
The right way is

  > function byNum(a, b) { return a - b; }
Re:Software in 2014 by ceautery on Thursday January 09, 2014 @09:15AM (#7030545)
A bug in my code doesn't make javascript horrible, it makes me horrible for rushing to illustrate a point instead of just harrumphing internally and finishing my coffee.

Good catch.

Re:Software in 2014 by Dirlewanger on Thursday January 09, 2014 @07:50AM (#7030134)
Writing your own method to solve a problem every other language does out of the box is missing the point...
Re:Software in 2014 by twerquie on Thursday January 09, 2014 @08:23AM (#7030277)
True, JS doesn't ship with a large standard library. But that has turned out to be one of its greatest strengths and a key reason for it's runaway success.
Re:Software in 2014 by adobriyan on Thursday January 09, 2014 @10:24AM (#7030931)
> runaway

See "runaway chain reaction".

Re:Software in 2014 by twerquie on Thursday January 09, 2014 @12:58PM (#7031994)
I'm not following, is this just snark or am I missing a point?
Re:Software in 2014 by kelseyfrancis on Thursday January 09, 2014 @08:57AM (#7030444)
The point is not that it's impossible to numerically sort an array of numbers in JavaScript; it's that calling the sort function on such an array doesn't do that. That's a surprise to most developers, I'm sure, and surprises in languages and libraries are bad.
Re:Software in 2014 by Morgawr on Thursday January 09, 2014 @07:42AM (#7030105)
that looks pretty horrible if you ask me
Re:Software in 2014 by twerquie on Thursday January 09, 2014 @08:27AM (#7030306)
It can (and should!) be written more elegantly

[5, 10, 1].sort(function(a, b) { return a - b })

Or, in ES6:

[5, 10, 1].sort((a, b) => { a - b })

That's starting to look pretty nice if you ask me.