Properties

Daniel Keep daniel.keep.lists at gmail.com
Fri Jan 9 06:39:14 PST 2009



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"



More information about the Digitalmars-d mailing list