[nem-en] macros attached to methods

Kamil Skalski kamil.skalski at gmail.com
Fri May 5 19:32:56 CEST 2006


One of possible uses was implementation of Aspects-Oriented
Programming, though the required support by compiler would be quite
large - we would need to easily attach given macro by its name to the
set of chosen methods. Then, upon every call of method

x.foo ()

we could wrap it with some generated code:

beginTransaction();
try {
  x.foo();
}
finally {
endTransaction();
}

The other point is that such macros would allow very convenient and
localized macro expansions. You wouldn't need to define macro, which
captures some name, but attach it to some standard method instead.
The example from my MSC Thesis is the design pattern, which tells you
to use factory method to construct objects, instead of direct calls to
constructors. Assuming you have plently of calls to some constructor,
attaching a single macro to it is much easier than converting all
those calls.

So, I guess the usage scenarios are maybe rare, but not completely absent ;)
Maybe we should consider having this functionality in future (e.g. if
we would do some refactoring to put methods + builting operators +
extensions methods into one bag, this bag could possibly also contain
extension macros).


--
Kamil Skalski
http://nazgul.omega.pl


More information about the devel-en mailing list