Search |
|||
API BlogsPosted by timboudreau on August 5, 2008 at 11:38 AM PDT
»
Related Topics >>
J2SE Comments
Comments are listed in date ascending order (oldest first)
Submitted by mrmorris on Tue, 2008-08-05 13:55.
Software architecture is the single most fascinating and difficult aspect (apart perhaps from dealing with users) within our industry. We have gotten far with sound principles, rules of thumb, conventions, patterns and anti-patterns... but to truly assist in usability and productivity I think we need some stronger abstractions at our disposal, directly in the language, to mitigate the layers of indirection we're so dependent on in Java.
I'm thinking of constructs which would address the issue of versionability, resource management and type safety. I'm still hoping we will see such things as properties, extension methods and akin to C#'s using statement (Bloch's ARM proposal) but it does not seem to be very popular. Not sure I understand why this is though, seems to me the Java 5 Enum addition have done wonders in improving API usability and type safety, even if it took 10 years to get it. Perhaps with a little more leeway, we would not see so much become hidden inside string tokens of annotations which makes us say bye-bye to type safety.
And now, about to open up the package from Amazon containing Practical API Design by Jaroslav Tulach.
Submitted by timboudreau on Tue, 2008-08-05 15:54.
I have some (slim) hopes that the JDK 7 module system JSR will address versionability - OSGi and the NetBeans Module System already do, and it's actually difficult to write these things and have to leave out the fact that you can, say, separate API and SPI into separate JARs so client APIs can be entirely final classes as an API client can be completely isolated from even potentially touching the SPI.
Re type safety, the capability pattern provides a nice way to add extensibility to a final class without requiring casts or violating API/SPI separation. In its essence it is simply
T getCapability (Class type);
Re general verbosity, I think there is great room for improvement without significant changes to the language. That's not to say Ruby is not less verbose. But, I think many common Java APIs are designed in such a way that they require much more verbosity than is strictly necessary. In other words, while there is some case for arguing that Java is verbose, we Java programmers share a good bit of the blame.
-Tim
Submitted by mrmorris on Tue, 2008-08-05 16:46.
I assume the capability pattern is similar to the description of the lookup API in your RCP book? I now use that a lot along with an SPI approach, thanks for broadining my horizon! But strictly speaking, isn't that counter-productive to the type system, in that it gets hard to really say anything concrete about interactions and behavior within the system. Taken to the extreme, we would end up using Martin Fowler's dynamic properties pattern (where everything is effectively a Map).
It solves some problems in larger long-lived frameworks (same level as OSGi/JSR-277 operates on) but I don't really see it compete with that of finer grained constructs readily at hand to the floor level programmer, who do not necessarily know the GoF book by heart. Perhaps my notion of API usability is just different. I do find the example of extension methods and/or mixins catering to usability, probably caused by having seen too many projects with each their own version of a DateUtils, StringUtils with no leverage between them all.
Submitted by koupsalla on Tue, 2008-08-05 17:23.
Seems to me there are some great topics to discuss. I am especially interested in an observer pattern discussion. For an architect there are always several suitable solutions for a problem. Since a decision of an architect can affect years of development this decisions are really hard to make. So any standards or rules of behavior are big time savers even if there are not effective in each situation.
The versioning strategy for a big software and API landscape that develops over time and has many different versions of the same API’s and the same products would be a great topic too.
And to say something on the OSGI <-> SUN Topic. Basically what SUN People told to me on the last CeBit:
• IBM, eclipse, Equinox no good. (Well nothing new. And the IBM people are talking the same language)
• JSR277 will rule OSGi and make it a dead end.
• OSGI will not work well in the EE world.
Addressing module system is not enough. I think that we need a standard. OSGi is really successful in the moment. You hear allot about NetBeans RCP too, but no one speaks about the module system of Netbeans. The ‘easy to use’ and the ‘swing’ arguments bringing a lot of folks to Netbeans RCP in the moment but NetBeans RCP with OSGI would be a killer Technology. Well just some thoughts…
-Pavel-
Submitted by timboudreau on Tue, 2008-08-05 18:31.
Re the observer pattern, you really want to read my friend Jarda Tulach's book at http://apidesign.org - he specifically uses it as an example of applying some of the ideas he presents there.
Re the module system wars, I prefer to stay mostly on the sidelines - they are all addressing the same problem, in mostly similar ways. If you want to use the NB module system that way, in NetBeans just create a module "suite" and exclude just about everything but the module system API and its dependencies.
Submitted by timboudreau on Tue, 2008-08-05 18:36.
mmorris: The capability pattern is a simplification of Lookup (i.e. no collections and no listening for changes). I don't quite see how either is counter to the type system, since both are type-safe.
Agree completely about there being far to many DateUtils and StringUtils types of things out there.
Submitted by mrmorris on Tue, 2008-08-05 18:49.
> I don't quite see how either is counter to the type system, since both are type-safe.
I should rephrase, it's still all statically typed of course, but interrelationships and dependencies are no longer readability available. So you really start having to rely on tools to handle this, as NetBeans does so well with the use of layer files. It's the same level of indirection added by the observer pattern, it becomes more complicated to reason about what's going on, which I guess is why NetBeans feels obliged to lock down all the event handling and prevent the programmer from touching. That's definitely one usability aspect of NetBeans I don't agree with, that you have to go behind NetBeans back to refactor a name of an event handler callback or remove one.
Submitted by timboudreau on Tue, 2008-08-05 20:30.
Layer files aren't pretty or terribly manageable; at least the META-INF/services injection method is somewhat better. But whenever you're doing loose coupling via some sort of dependency injection, there is going to be some place outside Java code where that injection happens, and outside Java code is outside of the world of type-safety. Ideally you enforce this at compile time, and you can definitely fail at runtime before a caller is handed an object of an unexpected type.
Any layer of indirection comes at a price - but without layers of indirection, we'd all still be building direct video and disk read/write into our software.
As far as locking down event handling, this has more to do with the myriad anti-patterns in the listener pattern - there are simply better ways to do that sort of thing. My next post will discuss that.
Submitted by mrmorris on Wed, 2008-08-06 06:36.
I realize there's an item in Bloch's latest "Effective Java" that can be bend to apply to this scenario as well. "Item 37: Use Marker interfaces to define types." In this case both the marker annotation and the getCapability pattern helps us out by simulating an is-a relationship with a has-an. All I am saying is that I don't think doing this scales very well at the micro-level within a class hierachy. Between components and modules is quite another matter and it has obviously proven useful in NetBeans.
Looking forward to your next post, particularly if it will address this silly marketing whitepaper.
http://java.sun.com/docs/white/delegates.html
Submitted by timboudreau on Wed, 2008-08-06 08:53.
I don't think it will. Let me set expectations here: I'm attempting to express some useful ideas I know, in the hope that we can thrash some out. I do not intend be the Voice Of Sun here :-)
Submitted by fabriziogiudici on Wed, 2008-08-06 10:10.
"And now, about to open up the package from Amazon containing Practical API Design by Jaroslav Tulach."
Thank you for pointing out it has been published, I was waiting for it. Just ordered.
Submitted by koupsalla on Wed, 2008-08-06 16:30.
Perhaps I don’t really understand what your post is about but I thought you wonted to start a discussion about some global software architecture question. I have to check my budget to know how many more Java books I can afford this year (I already have a bunch of Netbeans and RCP books here). But before that: several days before, I’ve posted a question on the dev@openide.netbeans.org and got no answer. What I basically wanted to know is what role the lookup and the module API are playing in a RCP transition scenario where the old app used other patterns.
So I have an app which is relatively strict build with the MVC – Observer Patterns in mind. We have a DataModel (xml half binding) we have a LogicModel and we have a lot of Views passing information to the Model over the specific Controllers. Well so far we have the one way the over way is done over the observer pattern. So the views observe the LogicModel. If some part of the model is changed the Observers listening to this part of the model are informed and update themselves. So 2-3 Sentences on the role of the lookup API in this scenario would be great. What do you think?
Submitted by mrmorris on Thu, 2008-08-07 06:15.
> Thank you for pointing out it has been published, I was waiting for it. Just ordered.
Sure thing, it's a unique read, more philosophical and personal than most design books and with some controversial remarks (simplicity and elegance might not not be a goal by itself, but to me it sure is a quality attribute worth keeping in mind). Interestingly, it appears he invites us readers to participate in a dialog: http://wiki.apidesign.org/wiki/Blogs
/Casper
|
|||
|
|