Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Meta-Programming > Whither Meta-Programming?

Whither Meta-Programming?

Seeing all this meta-programming code may make you queasy because it violates the cardinal rule of not writing self-modifying code. But this is precisely a place where you should question authority (see Chapter 11). Yes, this can be dangerous, when used incorrectly. But that’s true of any powerful feature. You can do dangerous things using Aspects in Java as well, it’s just more difficult. But it’s a bad argument to say that powerful language features should be so difficult that only masters can attain them. Much of the philosophy of Java was to remove power from the hands of developers by making the String class final. But an interesting thing happened: building restrictions into the language didn’t make the poor developers any better, and it placed a governor on the best developers, making them jump through ridiculous hoops to get things done. The classic example playing out right now in Groovy concerns how to handle GStrings. The GString is the String class in Groovy that offers lots more features than the Java String. Because Groovy interacts so intimately with Java, it would be helpful to be able to use String and GString interchangeably, certainly in Groovy code that passes strings to Java code. But you can’t. Because the String class is declared as final, you can’t even subclass GStrings from Strings so that Java libraries can understand them. The existence of final is an admission of the language designers that they don’t trust the people using the language.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint