News for hackers. Stuff that matters.
Re:BigInt Shipping in Firefox by callahad on Thursday May 23, 2019 @10:35AM (#19992152)
You can define a toJSON property on the BigInt prototype that gets used for serialization:

    Object.defineProperty(BigInt.prototype, "toJSON", {
        get() {
            "use strict";
            return () => String(this);
        }
    });
Of course you could also serialize to a Number, but that risks losing precision. For example, the Twitter API often returns IDs as both a Number ("id") and a String ("id_str") to safely handle cases where the value might fall outside of a normal double-precision float: https://developer.twitter.com/en/docs/tweets/data-dictionary...
Re:BigInt Shipping in Firefox by Spivak on Thursday May 23, 2019 @11:14AM (#19992501)
I'm sure its for backwards compatibility but hot damn is that one hell of a footgun. Even with that in place would you ever feel confident returning an id that didn't fit in a double knowing the sheer amount of code that definitely didn't handle that case?
Re:BigInt Shipping in Firefox by callahad on Thursday May 23, 2019 @11:43AM (#19992752)
Only Strings are safe,

forty years past K&R.

Wish I knew Tcl.

Re:BigInt Shipping in Firefox by ghettoimp on Thursday May 23, 2019 @01:05PM (#19993594)
I like your haiku.

But stay away from TCL...

It is such a mess.

Re:BigInt Shipping in Firefox by RHSeeger on Thursday May 23, 2019 @01:27PM (#19993827)
I love TCL, personally. It's my favorite language to play around in.
Re:BigInt Shipping in Firefox by kibwen on Thursday May 23, 2019 @01:31PM (#19993860)
Fixed it for you:

> I love TCL.

> It's my favorite language

> to play around in.

Re:BigInt Shipping in Firefox by thaumasiotes on Thursday May 23, 2019 @04:30PM (#19995578)
Your attempt conflicts with both previous haikus. By their evidence, "TCL" is only two syllables, but you treat it as three.

This does make me curious how they're pronouncing TCL in two syllables, though.

Re:BigInt Shipping in Firefox by aaronbee on Thursday May 23, 2019 @04:33PM (#19995617)
TCL is pronounced "tickle." https://en.wikipedia.org/wiki/Tcl
Re:BigInt Shipping in Firefox by riquito on Thursday May 23, 2019 @01:07PM (#19993606)
> third party ids are not yours. Treat them as strings, the other party can change them to string any day (happened to me more than once over the years) or they could use a different integer size than what you support (this case, or an unlimited integer value type - some languages have that too)
Re:BigInt Shipping in Firefox by zamadatix on Thursday May 23, 2019 @11:22AM (#19992576)
Only in JS do people seem okay with constantly mucking with built-ins.
Re:BigInt Shipping in Firefox by mikepurvis on Thursday May 23, 2019 @11:43AM (#19992755)
Ruby has a culture around it too: https://www.justinweiss.com/articles/3-ways-to-monkey-patch-...

And you can get some of the patching effect in any language with uniform function/method calls, though typically with a little more scoping and thus less ability to inflict unexpected side effects: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax

Re:BigInt Shipping in Firefox by badosu on Thursday May 23, 2019 @12:39PM (#19993301)
For pretty much the past decade (specially the last few years) I feel the culture has shifted to consider core monkey patches as a pretty bad practice.
Re:BigInt Shipping in Firefox by hombre_fatal on Thursday May 23, 2019 @12:51PM (#19993422)
Sure, but it's also a bad practice in Javascript.
Re:BigInt Shipping in Firefox by joliv on Thursday May 23, 2019 @01:56PM (#19994160)
Re:BigInt Shipping in Firefox by weberc2 on Thursday May 23, 2019 @12:49PM (#19993409)
If people could muck with builtins in Python, they would. And worse, they'd do it with inheritance and metaclasses. I say this as a Python dev.
Re:BigInt Shipping in Firefox by tyingq on Thursday May 23, 2019 @12:57PM (#19993507)
Python3 mucked with built in types...
Re:BigInt Shipping in Firefox by recursive on Thursday May 23, 2019 @01:56PM (#19994153)
I don't think monkey patching is really common in any version of python. I've not seen it done anywhere.
Re:BigInt Shipping in Firefox by kevin_thibedeau on Thursday May 23, 2019 @05:07PM (#19995962)
Setuptools monkeypatches distutils. Pip always uses setuptools so pretty much everything installed via Pypi is the fruit of a monkeypatch.
Re:BigInt Shipping in Firefox by tyingq on Thursday May 23, 2019 @02:03PM (#19994226)
Talking about the intro of bytes, bytearrays and the not quite the same types that were backported to 2.x