Regarding hex strings
foobar
foo at bar.com
Sat Oct 20 14:16:42 PDT 2012
On Saturday, 20 October 2012 at 21:03:20 UTC, H. S. Teoh wrote:
> On Sat, Oct 20, 2012 at 04:39:28PM -0400, Nick Sabalausky wrote:
>> On Sat, 20 Oct 2012 14:59:27 +0200
>> "foobar" <foo at bar.com> wrote:
>> > On Saturday, 20 October 2012 at 10:51:25 UTC, Denis
>> > Shelomovskij
>> > wrote:
>> > >
>> > > Maybe. Just an example of a real world code:
>> > >
>> > > Arrays:
>> > > https://github.com/D-Programming-Language/druntime/blob/fc45de1d089a1025df60ee2eea66ba27ee0bd99c/src/core/sys/windows/dll.d#L110
>> > >
>> > > vs
>> > >
>> > > Hex strings:
>> > > https://github.com/denis-sh/hooking/blob/69105a24d77fcb6eca701282a16dd5ec7311c077/tlsfixer/ntdll.d#L130
>> > >
>> > > By the way, current code isn't affected by the topic issue.
>> >
>> > I personally find the former more readable but I guess there
>> > would always be someone to disagree. As the say, YMMV.
>>
>> Honestly, I can't imagine how anyone wouldn't find the latter
>> vastly
>> more readable.
>
> If you want vastly human readable, you want heredoc hex syntax,
> something like this:
>
> ubyte[] = x"<<END
> 32 2b 32 3d 34 2e 20 32 2a 32 3d 34 2e 20 32 5e
> 32 3d 34 2e 20 54 68 65 72 65 66 6f 72 65 2c 20
> 2b 2c 20 2a 2c 20 61 6e 64 20 5e 20 61 72 65 20
> 74 68 65 20 73 61 6d 65 20 6f 70 65 72 61 74 69
> 6f 6e 2e 0a 22 36 34 30 4b 20 6f 75 67 68 74 20
> 74 6f 20 62 65 20 65 6e 6f 75 67 68 22 20 2d 2d
> 20 42 69 6c 6c 20 47 2e 2c 20 31 39 38 34 2e 20
> 22 54 68 65 20 49 6e 74 65 72 6e 65 74 20 69 73
> 20 6e 6f 74 20 61 20 70 72 69 6d 61 72 79 20 67
> 6f 61 6c 20 66 6f 72 20 50 43 20 75 73 61 67 65
> END";
>
> (I just made that syntax up, so the details are not final, but
> you get
> the idea.) I would propose supporting this in D, but then D
> already has
> way too many different ways of writing strings, some of
> questionable
> utility, so I will refrain.
>
> Of course, the above syntax might actually be implementable
> with a
> suitable mixin template that takes a compile-time string. Maybe
> we
> should lobby for such a template to go into Phobos -- that might
> motivate people to fix CTFE in dmd so that it doesn't consume
> unreasonable amounts of memory when the size of CTFE input gets
> moderately large (see other recent thread on this topic).
>
>
> T
Yeah, I like this. I'd prefer brackets over quotes but it not a
big dig as the qoutes in the above are not very noticeable. It
should look distinct from textual strings.
As you said, this could/should be implemented as a template.
Vote++
More information about the Digitalmars-d
mailing list