‹ BackHN Continuity

Thread

My temporary PHP fix from 2014 has nearly 20M installs. Today I'm deprecating it

341 points · 107 comments · jakeasmith

  1. jakeasmith · · focus · HN ↗
    Author here, happy to answer any questions. I never imagined a polyfill for http_build_url would gain so much traction. After 12 years, deprecating it feels like the right move, especially given the new options from the community and PHP itself.
    1. HackerThemAll · · focus · HN ↗
      The JavaScript world is littered with stuff comparing to which your patch seems like a complex project. See those examples:

      <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-odd" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-odd

      <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-even" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-even

      <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;left-pad" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;left-pad

      <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-whitespace-character" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;is-whitespace-character

      <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;isarray" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;isarray

      1. JaggerJo · · focus · HN ↗
        what a broken ecosystem.. The crazy thing is not that the package exists, but that it is used by JS devs.
        1. junon · · focus · HN ↗
          I feel like I have to remind people of this quite often, but the history is such that npm was lightweight at one point, bundling wasn&#x27;t a thing, and while `isodd`&#x2F;`iseven` are of course silly, things like `isarray` were not functions that existed back then (we didn&#x27;t have Array.isArray). `typeof [] === &#x27;object&#x27;` in JS, so e.g. my package `is-arrayish` checked for a similar structure to an array (whereas Id guess `isarray` checked for the prototype). `isarray` failed for the `arguments` keyword, which was needed for variadics before argument spreads were added to the language I believe in ES5.

          So of course they don&#x27;t make sense now. But they were created for a reason. Before even Markov chains were a fad - let alone LLMs - we were trying to be as efficient as possible and maximize code reuse I stead of writing the same helper functions over and over again. That&#x27;s what you&#x27;re seeing.

          1. IncreasePosts · · focus · HN ↗
            You want to implement your own is-odd in your code - simple, right? isOdd = (x) =&gt; x % 2 == 1

            Ut oh, your code is broken for negative numbers now since % isn&#x27;t a true modulo operator...

            Fine then, isOdd = (x) =&gt; x % 2 != 0

            Ut oh, your code is broken because isOdd(&quot;hi&quot;) returns true now...

            Fine then, isOdd = (x) =&gt; if(!isNumber(x)) throw... else return x%2 != 0

            Ut oh, your code is now broken because isOdd(2^55+1) returns true now...

            1. Dylan16807 · · focus · HN ↗
              &gt; Ut oh, your code is now broken because isOdd(2^55+1) returns true now...

              I think you messed up this example. Whether I literally use &quot;2^55&quot; with XOR or replace it with &quot;2*55&quot;, that version of isOdd returns false.

              False for isOdd(58) is obviously correct. (Also thanks C for permanently screwing up the precedence of bitwise operations because you didn&#x27;t want to break some existing programs in 1972.)

              False for isOdd(36028797018963970) is also correct, and if you expected to send in a different number the bug is in the &quot;+1&quot; not the isOdd.

              1. IncreasePosts · · focus · HN ↗
                Sorry, it&#x27;s supposed to be power. So 2**55 in JavaScript

                2 to the 55th power is obviously even, so that +1 is obviously odd, but ((2*55) +1) % 2 == 0 in JavaScript.

                1. Dylan16807 · · focus · HN ↗
                  But there&#x27;s no bug in isOdd. You&#x27;re sending the number 36028797018963970 into it, which is clearly even.

                  Putting extra code between the parentheses of the function call doesn&#x27;t make it the function&#x27;s responsibility. As nice as it would be for debugging if you could stuff your entire program inside of isNaN((function(){ &#x2F;* your code here *&#x2F; })()) and force your browser vendor to fix all problems.

                  1. IncreasePosts · · focus · HN ↗
                    You should check the math on a real calculator.

                    Despite what most JavaScript implementations will tell you, 2 to the 55th power is 36028797018963968, and adding one to that value is 36028797018963969. That&#x27;s clearly odd.

                    There is no extra code between the parens. I just put them there so there wouldn&#x27;t be any question as to operator precedence. I do see now that hn ate my double star, but I think you know what I mean since you told me the value that is spits out when you do the exponentiation

                    1. Dylan16807 · · focus · HN ↗
                      &gt; There is no extra code between the parens.

                      You have a plus and an exponentiation in there. That&#x27;s code.

                        var n = 2**55 + 1
                        console.log(n)
                        isOdd(n)
                      
                      n is 36028797018963970. isOdd(n) is giving you the right answer. Putting the +1 inside the parentheses and talking about calculators is a sleight of hand that lets you pretend isOdd gets an odd number, but it doesn&#x27;t. No odd numbers are around by the time isOdd actually does anything.

                      The problems are in + and&#x2F;or our expectations of +. It does not output 36028797018963969, and we must acknowledge that.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.