Properties

Nick Sabalausky a at a.a
Fri Jan 9 08:13:50 PST 2009


"Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message 
news:gk7nij$rlo$1 at digitalmars.com...
>
>
> Michiel Helvensteijn wrote:
>> [Condensed: syntax sucks, let's introduce more!]
>
> I might be old fashioned (get offa mah lawn!), but I've always found 
> something like the following quite acceptable:
>
> class Foo
> {
>     mixin(properties
>     ("
>         rw int bar;
>         ro float baz;
>         wo Foo zyzzy;
>     "));
> }
>
> I know I had a CTFE function lying around that would parse that and 
> generate the code for it.  I agree that C# has a nicer syntax for this, 
> but with CTFE/templates and string mixins, we can have whatever syntax we 
> damn well want.
>
> Hell, I used this in a prototype game engine to generate CVars; it'd 
> generate the properties, the backing store, the hooking code, event 
> registration, etc.  One line generated about 10-20 lines of boilerplate 
> for me; C# can't do that!
>
> Why change the language when you can just abuse it's already-existing 
> features? :D
>
>   -- Daniel "downs is my hero"

String mixins are very powerful, and certainly welcome IMO, but they involve 
dynamically generating code by algorithmically splicing together little text 
snippets, and that's just very hack-ish. It's literally just like using 
classic-style ASP or PHP. That was too clumbsy even for the 
already-clumbsiness-embracing world of the web; that's why they're moving 
towards proper page-templating engines. I see the role of string mixins as 
being a handy way to hack together a piece of advanced functionality until a 
better more proper way comes along. 





More information about the Digitalmars-d mailing list