4 ms·
To me signed vs. unsigned by default seems like asking which leg to cut off by default, left or right? The correct default IMHO, is a proper numeric tower pair
by mpweiher 5y ago
To me signed vs. unsigned by default seems like asking which leg to cut off by default, left or right?
The correct default IMHO, is a proper numeric tower paired with a tagged pointer implementation for "small" integers (range in ~ ± 2^62 or so). As others have pointed out, this will essentially never overflow in practice, so memory traffic is the same as for 64 bit primitive integers. AFAICT, we are now good enough at optimising tagger pointer/small integer arithmetic that on modern machines, memory traffic should be the limiting factor.
I was vascillating between different options (for Objective-S, http://object.st http://object.st) for a long time, because while I love C's "cheap and cheerful" use of int, but I also love Smalltalk's (and LISP etc.) "we do the right thing".
What pushed me over the edge towards the numeric tower as default position was DJB's retrospective paper in Qmail security: https://cr.yp.to/qmail/qmailsec-20071101.pdf https://cr.yp.to/qmail/qmailsec-20071101.pdf
So while "cheap and cheerful" works really well in regular situations, it does not work well at all when you're under attack, because attackers will go 100% for the edge cases, the ones that "never happen". So we really need to, as DJB put it, "simplify integer semantics". Having those overflows just cause a small slowdown seems like a reasonable tradeoff, we don't need attacks to execute at optimal efficiency.
Given the advances we have in software and hardware, there simply is no reasonable case to be made for not having a proper numeric tower as default.
When you need better performance or specialised semantics, the primitive types should be readily available. But not the default.