in reply to Re^14: why are hex values not numbers?
in thread why are hex values not numbers?
This thread gave no valid reason.
Well, most of the thread didn't even try to give a reason. But I think Re^2: why are hex values not numbers? got it right.
I recall finding a bug in C code that misinterpreted IP addresses padded to look nice:
216.211.126.174 216.057.063.004
by interpreting octets with leading zeros as being in octal.
Perl decided to require you to be explicit if you want to interpret a leading zero as indicating octal when interpreting a string. oct() is how to indicate that you want the leading zero to impact the base when interpreting a string as a number.
I concur with the choice to have "010" == 10 and "010" != 010. And I can see how it could seem more consistent to have the interpretation of 0x and 0b fall along the same lines.
But stepping away from that consistency, I agree with you that it would be good to transition Perl so that it becomes possible for "0x10" == 0x10 (and that such eventually becomes the default). And I would like to see similar changes so we get to where "1_000" == 1_000.
Beyond just a foolish consistency, it could also be argued that when asking a user for a numeric value, you should not assume that the user is a programmer. So you should treat "012" as "12" because that is what a non-programmer would mean. And you could extend that argument to other number formats that are expected of programmers but not others, like "0x1A4". But I disagree with that conclusion. "012" is a valid way to write 12. "0x12" is not a valid way to write 0.
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^16: why are hex values not numbers? (octal)
by BrowserUk (Patriarch) on Oct 02, 2016 at 10:56 UTC | |
by Anonymous Monk on Oct 03, 2016 at 07:38 UTC | |
by BrowserUk (Patriarch) on Oct 03, 2016 at 08:38 UTC | |
Re^16: why are hex values not numbers?
by perl-diddler (Chaplain) on Oct 03, 2016 at 12:25 UTC | |
by Anonymous Monk on Oct 03, 2016 at 19:38 UTC | |
Re^16: why are hex (not octal) values not numbers?
by perl-diddler (Chaplain) on Oct 03, 2016 at 18:15 UTC | |
by Anonymous Monk on Oct 03, 2016 at 18:31 UTC | |
|