News for hackers. Stuff that matters.
Re:Things I Was Wrong About: Types by jcranmer on Sunday September 27, 2020 @06:34PM (#24610732)
The other issue with dynamically-typed languages is that the language sometimes "helpfully" fixes the types for you. I came across one JS project that said this:

  for (var i = 1; i != Math.pow(2, 16); i <<= 1)
Replacing Math.pow(2, 16) with 1 << 16 effected a 30× speedup--and this was in SpiderMonkey, which tends to be a little less finicky about optimizing mixed types than V8.

(It's been a while since I coded PHP, but my recollection is that PHP tries to pull a strings-are-integer tricks a few times).

Re:Things I Was Wrong About: Types by pavel_lishin on Sunday September 27, 2020 @09:34PM (#24612018)
> my recollection is that PHP tries to pull a strings-are-integer tricks a few times

Yeah, the implicit casting in PHP is bonkers, especially when it comes to comparisons. The comparison table looks like the scribblings of a madman: https://www.php.net/manual/en/types.comparisons.php

(though granted, Javascript acts very similarly.)

Re:Things I Was Wrong About: Types by nucleardog on Monday September 28, 2020 @04:53AM (#24614500)
I have no hate for PHP, it’s been a tool in my toolbox for over a decade, I think it has a lot of good qualities, and it has made me a lot of money.

That said, after ten years of use, I still see something like:

    function_returning_false_or_int() > -1
And sometimes have the wrong intuition about what it does.

Now, nobody should write that shit in the first place, but turns out it’s equivalent to ‘!== false’.

‘(int)false’ is zero, but ‘false > -1’... is not true.

Re:Things I Was Wrong About: Types by three14 on Wednesday September 30, 2020 @04:32PM (#24643472)
This doesn't look to me like a dynamic typing problem. All the types are Javascript numbers. The issue probably stems from Math.pow's flexibility; it can even accept fractional exponents. The more general algorithm is probably slower.