After spending some time looking at examples of the meta programming Boo supports by having an open compiler it got me thinking how you could effectively generate boilerplate code for a class by just decorating it with an attribute, the example I was thinking of was of the standard singleton design pattern, the general setup for a singleton object involves:
- having a private constructor
- having a single static instance variable holding the type of the singleton
- exposing an static instance property/method that returns the instance variable
- possibly thread locking code if it will be used in a multi-threading environment
Now with Boo you can use an inherited attribute class of the AbstractAstAttribute to make adjustments to classes, fields, methods etc…
And just as I was thinking you could have a SingletonAttribute to perform the above standard tasks I came across this https://docs.codehaus.org/display/BOO/Useful+things+about+Boo someone has already implemented it!
I’m starting to really appreciate how powerful this language is