Re: Macro Library for Java?
pintman wrote:
Robert Klemme wrote:
Hm, what do you need that for? I've never felt the need for that in
several years of doing Java. IMHO there are superior mechanisms that
also have the added advantage of not breaking tool support.
With macros its possible to create new abstraction layers into the java
programming language without the need of parsers.
True, although I have to say I always feel wary about preprocessing. I
think Stroustrup regretted not having got rid of CPP in C++ for a reason...
Do you have concrete examples where the benefits of macro processing far
outweigh the disadvantages?
> For instance it would
be possible to create Singletons (or other paradigms) without the need
of knowing implementation details.
Hm, I've never felt it too much typing to do that pattern myself.
> Another example is the usage of
shortcuts for syntatic constructs. If I need to handle a lot of
integers it could be more understandable to say
for(int i : 1..5)
instead of
for(int i=1; i++; i<=5)
In this particular example I don't see improvements in readability and
the breaking of tool support would definitively make me not use a macro
for this.
As one could see in LISP there are a lot of applications for this.
I guess Lisp is a bit different because the macro facility is so tightly
integrated with the language (and very powerful indeed). But YMMV.
Thanks for giving a bit more background on your motivation!
Kind regards
robert