| «« Seeing the Forest for the Tests | Thinking About the Sweet Spot »» |
|
About
I'm Ryan Lowe, a Software Engineering graduate living in Ottawa, Canada. I like agile software development and Ruby on Rails.
I write this blog in Canadian English and don't use a spell checker. Typos happen.
Projects
» Full-time Ruby on Rails freelancer
» Full-time with Rails since May 2005 » Former committer for RadRails (now Aptana) » I also have a few Rails side-projects in development: 1. wheretogoinTO.com Toronto nightlife 2. Hey Heads Up! TODO list and sharing 3. Layered Genealogy family history research 4. foos for foosball scoring 5. fanconcert for music fans (on hold) Hiring Rails developers? I can telecommute by the hour from Ottawa, Canada »» Email: rails AT ryanlowe DOT ca
BulletBlog
Now hosted on Hey! Heads Up -- check it out!
Syndication
Pings
Recent
Derek Lowe's (Ryan's older brother) words at Ryan's funeral
blog@ryanlowe.ca no more Forging Email Headers: Good, Bad or Ugly? Sarcastic Dictionary (Part 1 of Many) Tags Hierarchies Twisting Rails is Risky Business Risky Business? My Take on Early Alphas Whoa, it's August 2007 Closing Comments A Postscript to "Growth at the grassroots" »» All Blog Posts
Linkage
del.icio.us/ryanlowe
technorati/ryanlowe.ca/blog Aurora Roy Jim Andrew Trasker Travis Kibbee Karen Dr. Unk Ayana Van Bloggers Joel Spolsky Robert Scoble Tim Bray Dave Winer Raymond Chen James Robertson Ruby/Rails Bloggers rubyonrails.org weblog David Heinemeier Hansson Dave Thomas James Duncan Davidson Mike Clark Jamis Buck Signal vs. Noise Tobias Luetke Amy Hoy: (24)slash7 Jeremy Voorhis Eclipse Bloggers Planet Eclipse EclipseZone Luis de la Rosa Eclipse Foundation Kim Horne Billy Biggs Ian Skerrett Mike Milinkovich Bjorn Freeman-Benson Denis Roy
Archives
|
Does Java Need a Higher Level Pattern Validation?
After reading this interview with Charles Simonyi, I wondered: What if there was a design pattern language built on top of Java? Java code is verified by the Java compiler and maybe as it is written in an IDE like Eclipse. The Java programming language is quite flexible and generally portable. If you wanted an object to represent part of a design pattern, couldn't you do it in a language built on top of Java which would verify that the class was properly structured to represent that pattern after it compiled correctly? In a regular or legacy Java compiler these high language directives would be ignored. Simple examples would be immutable objects and singletons. For immutable objects, the design pattern verifier would ensure that all of the members variables were private final, and that they were set only by a constructor and had the proper get accessor methods. Otherwise, you'd get warning or error. For singleton classes it would ensure that the constructor was private, there was a private static member variable representing the singleton in the class and that a static getInstance() method was present. The logical extension of this system would then be wizards that pump out immutable objects and singletons, based on a few pieces of information. The design pattern verifier enforces the design pattern contract you are trying to use, or at the very least warns you when you go astray. It might also make it easier to refactor one design pattern to another: going from a singleton class to a factory class, for example. Some people might be saying "so what? I can already write my patterns in Java". You're right, you can. The power comes from the machine verification of the design pattern. If the patterns are rigidly enforced, quality of the code will improve because you're no longer breaking basic pattern contracts and abstractions needed to assemble larger systems. However, building it on top of Java ensures that the parts of the patterns that need implementing can be done in a flexible way and in a language that many people are familiar with.
What would a "language" like this look like? Well obviously it would have to be in Java comments so that it could be safely ignored by standard issue Java compilers. It might look something like Javadoc. Who's going to build it? Do we wait for Sun to step up to the plate or start a community effort? Posted at February 20, 2004 at 10:16 AM ESTLast updated February 20, 2004 at 10:16 AM EST Comments
So CodePro But that's different from storing and emitting the patterns. At worst, I could picture attaching meta-information in a javadoc comment at the end of the file: /**
*/ I think I would prefer something like XML, so that you can parameterize it... after all, sometimes you want "a Factory of Five Wuzzits", which means that both Five and Wuzzit need to be definable. Alternately, I guess, you could do a CPP-style preprocessor. WussitFactory.jpp { expands into the full pattern for the compiler. Is that desirable? I'm not sure. Danyel » Posted by: Danyel Fisher at February 20, 2004 05:46 PMYeah, my emphasis was more on pattern validation than generation. Generating general skeleton code with hooks for a pattern would be a fairly simple task -- and it's very easy to break this code once you start playing with it and implementing the hooks. Nothing prevents you from destroying the skeleton. Instead the validation would take the pattern you want to do and look for 1) code that violates the pattern or 2) code that is missing to satisfy the pattern. The validation would be a harder to implement but it would also keep the programmer or software engineer on track with the pattern they ultimately want to produce, keeping important contracts in place for larger design considerations that depend on patterns. That's a good point about parameterizing, though I'm not sure if it belongs in the pattern itself. Maybe it could be a constant or a passed parameter. For example you might want a thread pool of 12 threads to be initialized, which is sort of factory-like. But later on you might want to change the pool to 24 or something when your server requirements change. The pattern hasn't changed though, just the number of threads or wuzzits. » Posted by: Ryan at February 20, 2004 09:06 PMIncidently, I did have something in the javadoc involving angle brackets... (pattern type = "factory") I see what you mean about validation. Perhaps a different model is to look at VEP Could we go one step further, and actually extract whether it's still the real pattern or not? I'm not sure. The other thing that comes to mind is that with JDK 1.5 and some clever reflection, it might be possible to make pattern abstract classes. ThingFactory{X} gives you a bare XFactory. (Those are angle brackets around the X.) public MyXFactory extends ThingFactory { gives you an XFactory that also frobles. » Posted by: Danyel Fisher at February 21, 2004 03:08 PMIsn't the VEP for GUI builders? Something I forgot was namespaces. For example, I could use my own org.audioman.Immutable but Sun may have their own com.sun.Immutable or another organization. Then the validator would know which thing to validate. Most importantly if the patterns were standardized somewhere programmers/architects could trust they'd follow the same rules every time, rather than have to create custom patterns every time. Custom patterns would be relatively rare. » Posted by: Ryan at February 23, 2004 10:25 AM |