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:
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...
[ Parent
| on HN ]
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?
Only Strings are safe,
forty years past K&R.
Wish I knew Tcl.
I like your haiku.
But stay away from TCL...
It is such a mess.
I love TCL, personally. It's my favorite language to play around in.
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.
TCL is pronounced "tickle." https://en.wikipedia.org/wiki/Tcl
> 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)
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
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.
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.
Python3 mucked with built in types...
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.