News for hackers. Stuff that matters.
Re:Idle Until Urgent by rbonvall on Thursday September 20, 2018 @11:32AM (#18033182)
JavaScript is a minefield of unexpected behavior when you try things like this. Besides the issue with this-binding already mentioned in the thread, there are other examples of weird stuff that happens when you don't introduce an apparently redundant lambda:

    > ['10', '10', '10', '10', '10'].map(parseInt)
    [ 10, NaN, 2, 3, 4 ]

    > ['10', '10', '10', '10', '10'].map(x => parseInt(x))
    [ 10, 10, 10, 10, 10 ]
Re:Idle Until Urgent by infogulch on Thursday September 20, 2018 @11:59AM (#18033434)
Ok this was a 'wat' moment for me until I realized that map passes up to 3 args to the function, including index, and parseint accepts a radix parameter. Still kinda weird/unintuitive, I could see myself not paying attention and reducing to the first example accidentally.
Re:Idle Until Urgent by kristjansson on Thursday September 20, 2018 @12:18PM (#18033568)
> I’ve heard something about a surprise principle in API design. Principle of most surprise I think it was? Let’s go with that.

The design process of this, I imagine.

Re:Idle Until Urgent by Serow225 on Thursday September 20, 2018 @01:22PM (#18034067)
I lol'd. Downvote away haters, sometimes you gotta laugh.
Re:Idle Until Urgent by jcelerier on Thursday September 20, 2018 @11:57AM (#18033418)
I'll take C++ UB every day over this
Re:Idle Until Urgent by rictic on Thursday September 20, 2018 @02:28PM (#18034505)
Huh, I'm the opposite. I'd gladly take a confusing combination of consistent spec'd behavior over time travel, arbitrary code execution, and nasal demons.
Re:Idle Until Urgent by jcelerier on Friday September 21, 2018 @10:59AM (#18040164)
> I'd gladly take a confusing combination of consistent spec'd behavior over time travel, arbitrary code execution, and nasal demons.

the point of UB is that you can tell your compiler to transform it into a specific behaviour -e.g., an assert with -fsanitize=undefined for instance.

Re:Idle Until Urgent by marcosdumay on Thursday September 20, 2018 @05:38PM (#18035674)
Well, at least with a consistent spec you can create a compiler for a good language.

Somehow, undefined behavior in C is a much smaller problem than it looks like. But the principle still applies.