Red Code, Green Code (nwcpp video)

Pragma ericanderton at yahoo.removeme.com
Thu May 10 07:18:11 PDT 2007


David B. Held wrote:
> Pragma wrote:
>> [...]
>> One way I can see this working is to use a custom pragma() - I think I 
>> managed to talk Gregor into trying it out in Rodin, at some point or 
>> another.  The suggestion isn't a personal bias, it's just that they're 
>> pretty much the ideal construct in D for supporting attributes.
>>
>> struct ExceptionSafe{
>>   static ExceptionSafe opCall(){
>>     ExceptionSafe_this;
>>     return _this;
>>   }
>> }
>>
>> // attach the ExceptionSafe attribute to the function f()
>> pragma(attr,ExceptionSafe()) void f(){
>>   /* do something */
>> }
>> [...]
> 
> Interestingly enough, this may well be only the second reasonable 
> application of AOP that I've encountered. ;)  The problem here is that 
> we want to perform a certain check *on every function*, but we don't 
> want to make it *look* like we are performing the check.  Implementing 
> these attributes as aspects actually makes a lot of sense.  I wonder 
> whether D should try to support AOP somehow...
> 
> Dave

Well, this example is really more of an attempt to emulate C#'s attribute feature, which is really just to help enrich 
reflection.  I could easily see a pragma being used for AOP, though something like AOP (read: function-wrapping) should 
really be a first-class construct IMO.  I have no clue what that would look like, since there's so many different ways 
developers would expect AOP to work (i.e. explicit meshing of aspects, cross-cutting, etc).

You should drop a message in the "python style decorators thread".  It has morphed into an AOP for D discussion.

-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list