|
Val's Blog
Lots of stuff for Web 2.0 freaks and Java addicts
|
|
|
Albert Einstein: "Intellectuals solve problems: geniuses prevent them." |
[ Login ] |
|
Ever wondered whether Java lets you play around with method "pointers" as C or C++ do? The Java Reflection API provides the necessary support for handling any high-level Java construct (class, method, field, etc) as a normal Java object that you can inspect and manipulate. A couple of days ago, David Shay explained how he came to know about this technique and commented on the runtime overhead due to reflection. I won't go into that, I just would like to show one concrete example of how method pointers could be used in practice. Since every problem usually has many solutions, the code example I'm going to discuss below is also implementable without reflection, of course :) For this example, I have been inspired by Lars Haendel's tutorial on C/C++ function pointers. The code shown in the table below is an equivalent Java implementation of his code with some enhancements that I describe hereafter.
The goal of the
Personally, I have very seldomly encountered the case where I needed to pass references to
TrackBacks[0]
Comments[0]
Posted by val on June 9, 2004 12:30:39 PM CEST
During the last three years, many different aspect-oriented technologies (AspectJ, AspectWerkz, JBoss AOP and Co) have been developed and some of them have started gaining a broad community and industry acceptance. While the benefits of using AO techniques in conjunction with existing paradigms, such as OO, become clear to more and more people everyday, there are still "tiny details" (code invasiveness, over-modularization, performance, security, complexity, etc) that prevent AO technologies from being fearlessly and widely deployed and used. I'm pretty confident that in the future IDEs will leverage best practices and patterns to provide developers with better support for dealing with these issues. It is pretty safe to say that the success of AOP heavily depends on outstanding tool support and is only a matter of time now. On the other hand, there are some big actors that we haven't heard of much. While IBM has announced that they officially back AOP, that BEA supports AspectWerkz and that Sun has decided to host an AOP panel at JavaOne 04, one could wonder where Microsoft stands on the AOP scene, and if they are even interested in AOP... If you browse a little on Microsoft's website, all you will find is a link to an old, yet interesting, article titled "AOP Enables Better Code Encapsulation and Reuse" by Dharma Shukla, Simon Fell, and Chris Sells published in the March 2002 edition of the MSDN magazine. On Microsoft Research's website, you can also dig out the Aspect.NET project, which aims at providing a AOP framework for .NET. Apart form that, not much to report under Microsoft's sun (no pun intended). However, it is no secret that Intentional Software Corp., founded by Microsoft's former Chief Architect Charles Simonyi and AspectJ's lead developer Gregor Kiczales, is "active" in the AOP arena. It might be interesting to see what comes out of that venture. Recently, Dion Almaer published a blog entry titled Anders Hejlsberg and AOP which actually hints that Microsoft is not just "knowing" the path but might also be willing to walk it. It would be cool to see what comes out of those "discussions".
TrackBacks[0]
Comments[2]
Posted by val on June 7, 2004 10:32:01 AM CEST
When I published my somewhat critical review of "Hardcore Java", I kind of expected that the author would drop into the Book Reviews forum at Javaranch.com to have a friendly discussion about the book. During the discussion, I have found that Robert Simmons Jr is indeed a very nice guy who is truly open to critics and gladly accepts *constructive* comments, which is not true of all authors out there. An author's openness to critics and comments is undoubtedly an important fact to take into account when reviewing a book. Unfortunately, you often get to know the man after reading his first book... In the discussion, Robert said that he would include a chapter on classloaders, another on package management and some other cool stuff in the second edition, should there be one. I'm trully looking forward to reading that new stuff :) In the meantime, Vivek has opened the good old debate on the final keyword... You are welcome to share your thoughts about that.
TrackBacks[0]
Comments[2]
Posted by val on June 2, 2004 9:02:25 AM CEST
For those of you who intend to take the AOP pill sooner or later, it is important to know that there are two main trends out there, namely solutions that achieve AOP by:
When AOP adoption is at stake, choosing one or the other solution may not be as straightforward as it seems. In this blog, I will try to make an objective, yet non-exhaustive, comparison between the two of the biggest actors on the AOP scene, namely, AspectJ and AspectWerkz.
The AspectJ community has created a seamless extension to the Java language with a bunch (> 20) of new keywords (
In AspectWerkz, aspects are Java classes (+ attribute If you decide to go with the first solution, you will need to integrate the AspectJ compiler into both your development environment and process. Moreover, you will have to learn the new syntax and semantics AspectJ adds to the Java language. While AspectJ provides several modules that you can plug into your favorite IDEs, it might not always be the best solution depending on how open your company is when it comes to adopting new tools and/or languages. In contrary, AspectWerkz allows one to define aspects using conventional Java syntax and semantics, i.e., all aspect-related code is declared using javadoc-like attributes written in class, field and method comments which might lower the learning curve necessary to get your first advanced HelloWorld running.
Now, I am going to discuss an example (shown in Figure 1 below) taken from the AspectJ Programming Guide that I have sort of re-implemented with AspectWerkz in order to provide a very basic comparison between both solutions. Of course, the example is pretty academic and not really complicated, but it's a good start... Also, note that the
The first thing that comes to mind when seeing this figure is that the AspectJ code is more concise. For instance, there is a code overhead in AspectWerkz's
I don't mind the Mixin stuff for implementation introductions, but the supplementary line for retrieving the context variables in the advice do bother me actually. Why AspectWerkz does not consider letting one specify the pointcut context variables as parameters to the advice method? This would be quite equivalent to AspectJ: we would be able to keep the JoinPoint parameter (AspectJ's
Another thing that kind of annoys me is that AspectWerkz has only a conceptual notion of abstract pointcuts. In AspectWerkz's example on Aspect inheritance, we can see that the abstract aspect
AspectJ also provides other inter-type declarations( I have been using AspectJ since the first beta versions and I have always been quite happy with it. However, even though AspectJ excels at type-based crosscutting, I still think that it lacks proper techniques for achieving *true* instance-based crosscutting. JBoss AOP and Spring (which I haven't talked about in this blog) are said to achieve this goal but I'm not completely satisfied with those solutions. I'm still looking into how AspectWerkz could provide a better solution to my problem. I'll probably write an update about this problematic in the near future. As a conclusion I would like to stress that my goal was neither to promote one solution over the other nor to provide an exhaustive comparison between AspectJ and AspectWerkz. There are many other details about both technologies that I haven't talked about. I just wanted to highlight some differences and similarities that I have found between both solutions. Finally, if any information that I have stated in this blog is innacurate, please do let me know.
Update: Thanks to Jonas Bonér for spotting one mistake in the AspectWerkz code.
TrackBacks[0]
Comments[4]
Posted by val on June 1, 2004 12:45:42 PM CEST
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Content © Val | Powered by Pebble 1.9.1 |