www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: request: python style decorators / aspect orientation

 If all it is is glorified function wrapping, I'm going to be somewhat
 disappointed :P

I think that it becomes more transformative in use than in theory; so the glorification is somewhat warranted. As this thread has shown (along with the previous CallConstraints thread) a well-crafted solution would allow the coder to say very expressive things with very little code. IMO, that deserves /some/ praise after all. ;)

It's actually pretty useful for boiling out common boilerplate code. For example, in python the Django framework uses it for things that have the same common usage pattern across lots of different operations. An example is user login; 99% of the time what you want to do is check if a user is logged in, and if not redirect them to a login page. Using this decorator syntax, all you need to so is put login_required above any of your functions that require the user to be logged in and it boils out the boilerplate for you. It's syntactic sugar, of course. You can to it in every other language in other ways. But it is nice syntactic sugar.
May 11 2007