you are viewing a single comment's thread
view the rest of the comments
[–] 134 points 8 months ago (11 children)

One way in which this could have come about is that Math.random wasn’t supported in all relevant browsers when the library author wrote the library. So they had to roll their own randomness with blackjack and hookers. Later the web standards evolved and the author was able to remove the custom code, but now had people relying on his library’s exposing a getRandom function.

  • source
  • hideshow 11 child comments
  • [–] 49 points 8 months ago (1 child)

    You see this kind of stuff in C all the time when a code base supports multiple OSs by using macros.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 27 points 8 months ago

    Yes, though at least with C you have the compiler to optimize the cruft out of your binary and end up with a nice, clean program.

    With JavaScript this is going to incur some runtime cost everywhere this library is used, even if it only happens once when getting optimized out by the JIT compiler.

  • source
  • parent
  • [–] 10 points 8 months ago* (8 children)

    Pretty sure that math.random is decades old.

  • source
  • parent
  • hideshow 8 child comments
  • [–] 5 points 8 months ago (5 children)

    Pretty sure many codebases running today (even JS ones) are older

  • source
  • parent
  • hideshow 5 child comments
  • [–] 10 points 8 months ago (2 children)