== Quote from grauzone ([email protected])'s article > Ary Borenszweig wrote: > > Michel Fortin escribió: > >> On 2009-03-06 14:35:59 -0500, Walter Bright > >> <[email protected]> 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. > >> > >> 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. > >> > >> 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? > > > > Well, now the \ is character if free: > > > > \bitfields( > > unit, "x", 2, > > int, "y", 3, > > uint, "z", 2, > > bool, "flag", 1, > > ); > > > > But I think it looks ugly: the \ is "lambda" in some languages and this > > also reminds me of LaTeX... :-P > String mixins are awful in the first place. The only thing that could > save this kind of thing are AST macros.
????????????? String mixins are an absolute godsend. I mean really, how much more general a metaprogramming facility could you possibly ask for than the ability to generate arbitrary D code at compile time? Of course they can get ugly, so there should be better ways to do things that are done frequently (regular templates accomplish this), but last I checked, bit fields are not an everyday run-of-the-mill programming type of feature. As a more general comment, of course syntax and readability count for frequently used features, but there's only so much pretty syntax available, and simplicity of the core language is a virtue. If certain things in D are going to have ugly syntax, they may as well be niche features like bit fields.
