3 ms·
I mean, most of the reason why this works is because Python doesn't care about type safety in the slightest. There's a reason why more strongly-typed languages
by smoldesu 5y ago
I mean, most of the reason why this works is because Python doesn't care about type safety in the slightest. There's a reason why more strongly-typed languages would outright disallow a program like this: it's not only unsafe, it's outright incorrect. The ASCII symbol for '-' is not a suitable analog for our concept of 'negative'
- upbeat_general 5y agoYou could certainly do this in languages with stronger type safety. All it relies on is checking the type and toString/fromString conversations.
- D13Fd 5y ago> The ASCII symbol for '-' is not a suitable analog for our concept of 'negative' Why not?
- smoldesu 5y agoConventional computing has no concept of positive or negative, but rather uses a signing bit to discern their polarity (for example, an 8-bit value could represent either -127-128 or 0-255). That concept of "type correctness" is lost whenever you haphazardly cast unlike values between one another (in this case ints and strings), so we're trusting the Python interpreter to magically perform this illegal, slow operation without supervision.