Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^12: why are hex values not numbers?

by perl-diddler (Chaplain)
on Sep 29, 2016 at 06:01 UTC ( [id://1172890]=note: print w/replies, xml ) Need Help??


in reply to Re^11: why are hex values not numbers?
in thread why are hex values not numbers?

That after 22 years of Perl5, you've invented a requirement no else needs, and are completely impervious to reason.
Impervious to reason? What reason has anyone given to the question of why a hex constant (e.g. 0xa0) shouldn't be able to be converted in any place perl auto-converts a decimal number?

Requirement? If I was adding a restriction or forcing someone to use the feature, it would be a requirement -- but right now, it's something that doesn't work -- so no one is using it. If it was adopted, then still no one would be required to use it. In no way can it be considered a "requirement" that people would need to follow.

Extending privileges or options, to people, is never something that is "required".

Requirements are things forced upon people. In contrast, options are things people have a choice to do or not.

Replies are listed 'Best First'.
Re^13: why are hex values not numbers?
by Anonymous Monk on Sep 29, 2016 at 06:19 UTC
    Impervious to reason? Yes. This thread is full of reasons, and you've ignored them all. Not even attempting to counter argue, just ignored them. You're like a child: I want! I want!

    Requirement? Yes. An industry standard term, that you obviously have no knowledge of, which explains a lot.

    What reason has anyone given to the question of why a hex constant (e.g. 0xa0) shouldn't be able It is not that it could not be done, it is that there is no good reason to do it.

    And the potential for silent failures, where a non-number that would now look like a hex or octal number, is accidentally used in a numeric context, that would currently warn loudly, is too high a price to pay for something you think would be nice to have even if nobody needs it or would use it.

      This thread gave no valid reason. Or are you claiming that my asking for rational, logical support in the form of reasoning or reasons, that such is a child-like behavior. This is a not a nursery school. Isn't it supposed to be a place where we can have technological discussions? It seems asking for references or valid & consistent reasons valid in computer science.

      Requirement? You claim I don't know what the word means, yet like a petulant child, you say "And I'm not gonna tell ya." You can't define your terms in a technical forum? Then don't claim to know them or claim to be capable of judging others' use of the them.

      There is a good reason to do it: compatibility with any other language -- in places where other languages allow decimal input (usually at the source level, though also at runtime in interpreted languages), they also allow hex, and, usually octal at the minimum. Perl stands alone in not being able to convert a hex constant in a string when it CAN convert a decimal in the same place.

      Potential for silently getting a '0' value for bad-source code? What more do you want? Show me anyplace in CPAN where the person put "0x" in front of a string of hex digits, and they didn't mean that they wanted a hex string.

      You are talking about a error in the first place and second, it's a very unlikely error, one I doubt you can find an example for, but if you needed such pickiness, you could have 'lint' complain about such cases. You shouldn't use it as the only reason to block a feature that makes the language easier for others.

      This is why perl is dying a slow death -- because no one will support any common sense changes that make things *easier* for new people coming to the language. Instead, the things that do get approved are pinning tails on vars, that, of any method of allowing forced-typing, is the most verbose and most cryptic looking. So much so, that I know no other mainstream language that uses such a syntax (may be out there, but I've not seen such). It won't help outsiders understand perl -- just create more confusion.

        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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172890]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found