missing HexString documentation

Adam D. Ruppe destructionator at gmail.com
Wed Feb 7 17:01:54 UTC 2018


On Wednesday, 7 February 2018 at 16:51:02 UTC, Seb wrote:
> For the same reason why octal literals have been deprecated 
> years ago:
>
> https://dlang.org/deprecate.html#Octal%20literals
>
> The library solution works as well and it's one of the features 
> that are rarely used and add up to the steep learning curve.

That's actually not the reason given. Octal literals had the 
stupid leading 0. We should have just made it 0o instead.

The library solution does not work just as well, since it doesn't 
work at all in some places. Behold:

http://dpldocs.info/experimental-docs/source/core.sys.posix.fcntl.d.html#L123

    version (X86)
     {
         enum O_CREAT        = 0x40;     // octal     0100
         enum O_EXCL         = 0x80;     // octal     0200
         enum O_NOCTTY       = 0x100;    // octal     0400
         enum O_TRUNC        = 0x200;    // octal    01000


That's from druntime. The comments being there indicate the hex 
is not obvious in this context; the octal would be more 
illustrative. But the lack of use of std.conv shows it wasn't 
applicable where the literal was (since this is druntime, phobos 
isn't available).


The octal library solution is brilliant. The genius who wrote 
that code is clearly god-like and we should all fall to our knees 
and worship his superior intellect. That pattern DOES have uses.

But for octal? It was a mistake. We should have just made it 0o.


Similarly, I think the mistake of hex strings is that they are 
typed char[] instead of ubyte[]. Otherwise... they work ok. And 
when learning, you don't need to know every bit. You'd just 
ignore it unless you hit upon the niche where it matters. (that's 
the way I learned basically all of D. my early D code is 
virtually identical to my C code, a bit later, similar to old 
style Java code. only after being in it for a while did i go nuts 
mastering the language.)


More information about the Digitalmars-d mailing list