Open source dmd on Reddit!
Nick Sabalausky
a at a.a
Fri Mar 6 22:23:45 PST 2009
"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message
news:gossg8$2qj8$1 at digitalmars.com...
> Michel Fortin wrote:
>> On 2009-03-06 14:35:59 -0500, Walter Bright <newshound1 at digitalmars.com>
>> said:
>>
>>> Andrei Alexandrescu wrote:
>>>> "Can't live without bitfields! Give me bitfields and I'll lift the
>>>> Earth!"
>>>>
>>>> "Here they are, std.bitmanip. Well-defined and more portable and
>>>> flexible than C's."
>>>>
>>>> "Meh, don't like the definition syntax."
>>>
>>> Classic.
>>
>> Well, he certainly has a point. Compare this:
>>
>> mixin(bitfields!(
>> uint, "x", 2,
>> int, "y", 3,
>> uint, "z", 2,
>> bool, "flag", 1));
>>
>> With this:
>>
>> uint x : 2;
>> int y : 3;
>> uint z : 2;
>> bool flag : 1;
>>
>> The second is certainly prettier and more readable.
>
> (Just to clarify: to me the humor of the situation was that someone who
> considered bitfields an absolute prerequisite for language adoption
> subsequently found the syntax excuse to bail out. Essentially the
> hypothetical user was fabricating one pretext after another to rationalize
> their pre-made decision to not try D -- an absolute classic attitude when
> it comes about acquiring new programming languages.)
>
I have a different theory that's based on my own experience from other
languages/software/products/brands/etc. that I've disliked in the past:
People come across a language (or anything else), see two or three things
they really don't like, and think "Meh, not worth bothering to switch if I'd
just be trading one set of complaints for another. I'll just stick with what
I'm already using, but to be helpful, I'll point out the issues I have with
it." If those issues were fixed at the time they said that, they probably
would switch, but obviously it can't change instantaneously like that. So
the things they disliked about it stick in their mind and leave them with a
generally bad impression of the language (or product) for a few months or a
couple years. Then, it finally gets fixed, but by that point they simply no
longer care.
Basically, it's the old "first impression" thing with a few wrinkles.
> About the syntax itself - definitions are few and uses are many. In
> addition the D solution:
>
> (a) guarantees data layout;
>
> (b) offers symbolic limits, e.g. x_max and x_min are automatically added
> as enums;
>
> (c) checks for overflow, which is essential for small bitfields;
>
> (d) offers a way to manipulate the fields wholesale by using the
> concatenation of all their names, e.g. xyzflag;
>
These are all things that could be done with the old C-style syntax,
provided it was built into the language. But of course, that strategy has
it's own downsides, too.
> (e) suggests that there are other cool things that can be done within the
> language, not by adding features to it.
>
> Hopefully that makes up for the more loaded syntax.
>
>> Does it matter much? Not to me; I rarely use bit fields. If I were using
>> them a lot, perhaps I'd be more concerned.
>
> I am using them here and there - even in Phobos - and they work very well.
Provided that they aren't as crappy as the ones in C, bitfields can be
immensely useful for anything really low-level, like embedded systems,
drivers, firmware, or packed data formats for network or file I/O (ie,
"systems programming" stuff). Anything higher-level then that, though, and
their usefulness certainly does seem to diminish.
>
>> While I don't care very much about bitfields, that "mixin(tmpl!(...))"
>> syntax is awful. "mixin tmpl!(...)" is better, but has too many
>> limitations, and it isn't always clear for the user which one should be
>> used. Couldn't D2 get a better syntax for mixins?
>
> I agree it should.
>
That would certainly be very nice.
More information about the Digitalmars-d-announce
mailing list