Saturday, May 26, 2007

Is Your Framework Adding Value?

Trust me, this is going somewhere...

Pre-fab or Field-fit?

A friend of mine is a drilling engineer. He has traveled around the globe and has many interesting stories he has shared with me. One involved an experience he had while working in the former Soviet Union around 1993. He and some co-workers toured a factory where pre-fabricated apartments were being built. The idea was that the major components, such as walls, would be built in the factory and trucked to the site where they could be assembled, simplifying the construction process.

Sounds great in theory, but my friend noticed a flaw in the implementation. The walls were made by pouring concrete into large rectangular wooden forms. These forms had internal forms for windows. While the forms were precisely measured and designed to fit, the corners of the internal frames were not braced and as the concrete was poured, they shifted, and what should have been a rectangular shaped window in the middle of the wall wound up being a parallelogram with non-right angles for corners. What should have simplified construction in the field wound up creating more work than starting from scratch, as each section had to be "field fit".

When asked about the problem, the factory workers shrugged and indicated that since it wasn't their problem, they didn't feel any need to change what they were doing. Of course, it didn't matter, since the window glass never fit anyway. When they assembled the buildings, the panes of glass were often overlapped.

The Liquid Foundation

While watching the History Channel, I saw an interesting program about an earthquake in Kobe, Japan in 1995. It turns out that the Japanese have taken to creating artificial land to help ease the real-estate shortage that they are experiencing. This is done by dredging soil from the ocean floor and depositing in other water-filled areas until it forms artificial land ready-made for the construction of houses, businesses, and highways.

Unfortunately, when the earthquake hit, an unexpected state change, known as soil liquefaction, occurred in this artificial land. As the shocks occurred, the land acted, for all intents and purposes, like a liquid, flowing and oozing all over the place. Anything built on top of this now liquid foundation was destroyed.

Software as Architecture

It is fashionable to compare the creation of software with the creation of buildings. We go so far as to call many members of the software industry "architects". While I am not crazy about this metaphor, it does work at times.

Software organizations often attempt to go the prefab route by building frameworks composed of common utilities that can be "trucked" to different developments. The thought is that the framework provides a pre-fabricated foundation (to stick with the metaphor) on which to build the application.

Sounds great in theory. Hmmm, where have we heard that before? At issue is the quality of said framework. Were the architects of the framework familiar with good API design? Were there any architects or is the framework simply an amalgamation of code fragments gathered from other developments? Is the goal of the framework to provide the basics or does it represent a grand attempt to boil the ocean? And most importantly, does the framework simplify application development or does it complicate the application and leave it with "window frames" that are field-fit and "panes of glass" that overlap?

These are important questions for a development organization to ask when it assesses whether to go the prefabricated framework route. Not only is there a risk of wasting development effort (and slowing time to market) trying to fit an application into an awkward architecture, but after this occurs, the resulting product is now built on a shaky foundation that may liquefy at any time, but of course it will wait to do so until deployed at a large customer site.

I am not saying that frameworks in and of themselves are bad. At issue is how the framework was constructed and whether it truly provides the value its use implies. We can look to the open source communities for examples of frameworks that work. Spring, Hibernate, Commons Logging... solid and designed for easy integration.

I told you I was going somewhere.

Sunday, May 06, 2007

No Fluff Just Stuff, Spring 2007

NFJS, Spring 2007

This is the second year in a row I have attended the Denver leg of the No Fluff Just Stuff tour. Jay Zimmerman and crew have outdone themselves. The speakers were excellent, the topics were relevant, the venue was nice, and the food was good!

Due to budget issues, my company was not able to spring for the registration fee this year. So I paid for attendance out of my own pocket. It is that good! Kudos to Linda for supporting the financial decision.

I started out the seminar attending Venkat Subramaniam's Annotation Hammer talk. Annotations are near and dear to my heart, as they were the basis for my own talk on Hibernate with Annotations. It turns out Venkat doesn't feel that this is an appropriate use of annotations.

He made the distinction of intrinsic versus extrinsic metadata. According to Venkat, an intrinsic feature, which is one in which the semantics of the metadata are expressed in the code itself, is a good candidate for annotation use. Extrinsic features, in which the metadata expressed by the annotation is not expressed in the code itself, is not a good candidate for annotation use. Venkat believes that persistence semantics, such as in Hibernate, fall into the latter category. He also believes that using annotations with Spring and Hibernate results in vendor lock-in. I can buy into the extrinsic argument to some extent (but still like Hibernate annotations for small apps). I agree that Spring annotations result in vendor specific implementations. I disagree that annotations in Hibernate are vendor specific, since they are based on the JPA. If you don't like Hibernate, you can switch to another JPA provider (such as Ibatis). That's not lock-in where I come from.

Other interesting take aways from the talk include some info on Java 6, which will expand the use and support of annotations In Java 6, annotation processing is built in. For Java 5, the external Annotation Processing Tool is needed for pre-processing. A new annotation in J6, @WebService, provides all the scaffolding to support a web service without the need to write code.

Venkat showed some examples of junit 4.0 annotations. I really couldn't see any reason to use them over the standard junit API. No real value add.

Venkat concluded with a couple of observations: annotations "leak into" your code and can be hard to get rid of later. I don't like XML is not a good reason to favor annotations.

I'm guilty of the last one...

The next talk I attended was Neal Ford's 10 Ways to Improve Your Code. Neal used an interesting tool for his preso, MindManager, which is a mind mapping tool used for brainstorming and, it turns out, for making presentations.

Some key take-aways from this talk (some of them are "duhs", but still):

Version control and continuous integration are fundamental. An automated build machine should not have development tools on it.

Static code analysis should be favored over a compiler as the first step of testing. He mentioned FindBugs and a tool called PMD. PMD has a feature called "copy paste detector" that is useful for finding common code that can be refactored.

Singletons are glorified global variables. Overusing static classes is a sign of a procedural mindset

Persistent state is the enemy of unit testing. Keep your object state valid at all times. As an example, we discussed an Address class, with address, city, state, and zip fields. Neal argued that it made no sense to have setters for each field, since an address without a city makes no sense. Instead, he recommended using a constructor that takes all fields as arguments. I asked about a UI that might need to change the object. He suggested an update method. This is a great idea that I plan to use in my code.

Test driven development, avoiding feature creep, and analyzing dependencies (using a tool called JDepend) were discussed. He also presented an algorithm developed by an associate of his that used code coloring to identify code that provides the maximum business value. It was a bit complicated but looked like it could be useful if applied rigorously.

He touched on Domain Specific Languages (DSLs). This looks very interesting but we didn't get into much depth here, but the gist is that you should write APIs and name components using terminology that fit the domain.

Neal touched on a topic he calls Polyglot Programming, which was also the topic of his keynote talk. Summarizing, he argues that developers should use the most appropriate language for the task at hand and that it is acceptable to mix and match languages in a product. Given that there are 25 different languages that run on the JVM now, this is starting to make a lot of sense (see my discussion later on Java 6 for more on this).

The other critical argument Neal made in his keynote, and one that I whole-heartedly buy into, is that for software development to truly be considered an engineering discipline, the practitioner's of the discipline must embrace and commit to testing as the underpinning of everything the developer does. Neal is a test-driven development zealot. I am quickly becoming a convert. Of course it will take me some time to get good at it, but I have a goal.

The next talk I attended was OSGI: A Well Kept Secret, present by Venkat. OSGI is a component management platform that protects an application from "classpath hell". After hearing what this tool does, the first question the pops up is, "Why isn't this baked into the JVM". It turns out there are plans to do this, but there are two competing standards, JSR 277 and JSR291. And neither of thee standards appear to be learning from the OSGI team! So I'm not holding my breath. Like all Venkat talks, the demos were detailed and really showed the power of the product. I don't currently have need for this product, but it was good to get an introduction to it. Probably worth mentioning that OSGI is baked into apps like Eclipse.

Start of Day 2, first talk I attended was Build Teams, Not Products, presented by Jared Richardson. As a dev lead on a Scrum project, team building is a very important aspect of my job, and, in all honesty, not one of my strengths. So this was a relevant topic. I got some good ideas that I plan to try with my current team...

As the dev lead, it is important for me to share my own impediments so that other team members will be willing to do the same.

Focus on interactions, which will maximize human bandwidth.

Encourage informal code reviews as both a learning tool and a way to kick-start interactions. Verbalizing design decisions helps the whole team.

Randomize the order that the scrum reports in every day.

It was interesting to find that Jared worked at SAS, which rumor has it is the utopia of companies to work for if you are a software engineer. Jared dispelled this rumor a bit saying that, in regard to the work, there are good and bad areas within the company, just like any other company. Figures. He did say the bennies and culture were nice.

I followed this talk with another by Jared, Continuous Integration with Cruise Control. In keeping with my goal of getting better at TDD, I wanted to learn more about this tool so that I could use it more effectively. It was a good talk, with a great demo of the product. Nothing earth shattering but good review of what is available in the tool.

Neal's keynote got me to thinking and i decided it was time to look at Ruby again, so I attended his talk on JRuby. I'm still not sold on it. I really like Neal and respect a lot of his opinions, but he seems to be a bit hypocritical when it comes to Ruby. He spent a lot of time in the keynote discussing the warts in Java. During his Ruby talk, he glossed over similar issues in Ruby. One example is that arrays in Java being zero-based is bad, but when we run into this in a Ruby example, it is glossed over. Hmmm.

Neal stated that in Python, there is only one way to do something, while in Ruby, there are ten ways to do the same thing. He went on to argue this is a strength of Ruby. So put ten programmers in a room with Ruby and they will do the same task ten different ways. The maintenance team is gonna love that!

Neal argues for very clear concise class, method, and variable names, but the fact that the Ruby to string method is called to_s is not pointed out as a problem. Worse yet, there is Perl-like syntax that has crept into the language. How is this a clear, understandable piece of code:

list = ArrayList.new
%w(Red Green Blue).each { |color| list.add(color) }

%w? Give me a break. If I knew nothing else about the language, this would send me running... away!

Another Ruby annoyance is the suffixed if as opposed to the Java prefixed if.I am willing to concede that to some extent, this one is a learning curve, can't teach an old dog new tricks issue. Guilty as charged. But I'm still gonna use Groovy as my dynamic language of choice!

I should note that I really enjoy Neal's talks. He is intelligent, has a great sense of humor, is way smarter than I am, and does get me to look at things from a different angle. I just can't get excited about Ruby/JRuby.

I finished the day attending a talk, Making Architecture Work through Agility, presented by Mark Richards. Mark is an architect with IBM... and it shows. I am not very happy with the term architecture in software development. I really like Martin Fowler's essay Who needs an architect?. Mark's presentation reinforced this opinion. He showed a typical, "boil the ocean", eye-chart caliber architecture document and proceeded to discuss how an architect could get teams to implement the architecture in pieces. But this occurs "after" the architecture is delivered from on high. It is probably a bit better than what happens now, but I would argue that a better approach would be to use an agile process, and start implementing a product immediately, using refactoring to evolve the system over time as new features are identified and operation of the system is better understood. I attended this session hoping to change my mind abotu architecture, but instead, I find my opinion has been reaffirmed.

On the final day, I started by attending the Java 6 talk presented by Venkat. I knew that J6 was out there, but hadn't heard much about it. I hadn't heard anything about it that seemed like a must have or even a nice to have feature.

Java 6 is defined in JSR 270. It is currently available for Windows and Linux, but not for the Mac (a developer release is available). It turns out that both the developer Mac version and the Windows version running under Vista have problems. Linux users, you know who you are, this is your cue to start the heckling...

The most impressive new feature in J6 is its support for more than just Java. There are something like 25 languages that run on the JVM now and J6 provides a mechanism, called the ScriptEngineManager, that allows processing of these languages in Java code. This feature becomes very important with Neal's polyglot programming paradigm. J6 has a tool, jrunscript, that allows interactive testing for different scripting code.

J6 also provides built-in support for web services including a small webserver. Venkat feels that this feature is too little, too late. As a person who doesn't know web services very well, I might be able to take advantage of this feature.

J6 provides some tools to support monitoring and programmer support. JHAT provides some cool monitoring tools, JavaCompilerTool provides programmatic access to compiler, and there is built in annotation support, using -processor option on javac to specify annotation pre-processor.

J6 also provides localized UI support, splashscreen support (your splashscreen can be displayed BEFORE the JVM starts), console support, and integrated JDBC support. Venkat didn't go into these features in detail, but it is good to know they exist.

At lunch, there was a speakers panel. The speakers like to pick on Ted Neward, who seems to eat it up. They seem to have a lot of fun. Ted seems to enjoy taking the opposing side to the rest of the group. In particular, he made a comment that with careful programming, unit testing was not necessary. I was surprised that the rest of the group didn't hang him from the nearest tree. I later heard him mention that compilation WAS a weak from of unit testing. I think he likes the controversy. I hope so, because he seems like an intelligent guy in other respects.

The rest of the afternoon was spent in, here is the funny part, talks by Ted! He had a series on some quasi-basic stuff that I have never gotten around to looking into much. I took this opportunity to fix this.

The first one was on monitoring and debugging. Ted argues, effectively, that monitoring is more important because it proactively prevents errors, alleviating
the need to debug.

He presented some tools that come with Java that allow monitoring to occur. To demonstrate, he used a demo program available from sun called swingset2, which demonstrates many features of swing and is worth a look just for grins.

He started by looking at garbage collection, using the gc command line option, -verbose:gc, followed by a demo of jconsole to see the same information in a graphical format. He also demonstrated JMX hooks into the JDK logging libraries. which are cool. Unfortunately, they are not supported in log4j, which we use at work. The only criticism I had for this session is that towards the end, it got a little windoze-centric.

The last two sessions dealt with Reflection and Class Loaders. Lots of good technical information was imparted. Very information dense. My head hurt afterward. I'm not sure any of it is directly applicable to me right now, but it will be nice to have this background if I ever do run into uses of them.

The last thing I should mention is that I intentionally avoided talks by Scott Davis, but not because he is a bad speaker, which couldn't be further from the truth. Because he runs the Boulder JUG, which I attend regularly, I get to hear him talk on a regular basis. Were this not the case, I would probably attend everyone of his talks. Yup, he is that good! Wanted to put a plug in for him in case you haven't heard Scott talk and have the opportunity! Attend if you can... you won't regret it!

This blog is a short summary of a long weekend, but hopefully gives you a flavor of what the weekend was like. If you ever get the chance, I highly recommend attending a NFJS event.