request: python style decorators / aspect orientation

Georg Wrede georg at nospam.org
Thu May 10 03:55:11 PDT 2007


Daniel Keep wrote:
> Chris Nicholson-Sauls wrote:

>>Overall a neat and useful trick.

Absolutely!

> Like I said, I use this sort of thing in GL programming to check for
> errors.  So:
> 
> glMatrixMode(GL_PROJECTION)
> 
> becomes
> 
> glSafe!(glMatrixMode)(GL_PROJECTION)
> 
> Which automatically throws an exception containing the human-readable
> name of the error condition if something goes wrong.  The other neat
> side-effect is that I can throw a version switch and have my program log
> every GL call made, which makes tracing problems a lot easier.

Looks like an idiom to remember!

> Tell you what, though; I'd *kill* to be able to do this:
> 
> 
>>module mygl;
>>static import derelict.gl.gl;
>>foreach( symbol ; derelict.gl.gl.symbols )
>>    static if( startswith(symbol.stringof, "gl") )
>>        mixin(`alias glSafe!(derelict.gl.gl.`~symbol.stringof~`) `
>>            ~symbolstringof~`;`);
> 
> 
> Which is, incidentally, a trick I used for some Python GL code.  Make my
> D code a lot shorter :)

I've sometimes used preprocessing (activated by makefiles) to achieve 
something like this. But it should of course be in the language itself.

> On a side note; is this all Aspect-oriented programming is?  Everything
> I read about it basically amounted to "AOP is the Second Coming!!!!!
> Also, Java is the best language EVAR!!!!!!" and never really said what
> it was or why it was useful.
> 
> If all it is is glorified function wrapping, I'm going to be somewhat
> disappointed :P

My exact feelings when OOP was all the rage. People dancing on rooftops 
hailing the Object. And all it was, was simply structs, and functions 
that pretended to be inside their scope. And folks saying "saving the 
objects" when they should have said "writing the data in some of the 
fields of some of the struct instances to disk".

For a long time I thought I was stupid because "I didn't get it". Turned 
out there wasn't anything to "get". Or rather, the thing to get was the 
previous sentence.



More information about the Digitalmars-d mailing list