Who I Am (a moment of clarity)

I recently have been thinking a lot about my own identity, and whether I care enough about the bigger picture to try to establish my own empire.  I work for a company that is very much in a Napoleonic march, and it has been a different experience for me.  I’m not one who would ever be called humble, but I am someone who enjoys being able to do something, reflect on the accomplishment, and move on to the next thing.  That’s probably why I change jobs so frequently, I have an affinity towards instant gratification and an impatience with things that take time without a clear deliverable.  And it’s why I have determined I like being a hands-on technologist as opposed to a business development-oriented technical manager.  I don’t think of myself as a computer scientist, but I do think of myself as someone who is well-equipped to solve problems - and that’s what I’m good at.

Continue Reading

Taking a New Job

I’ve decided to leave my current role at Medullan and head on over to Amadaeus, with the hope my life will be a bit more sane. Good luck Medullan, you guys are in the right place, just not the right place for me.

Leave the first comment

An Omniscient Learning Approach to Mock-based TDD

I recently posted about why I think mocks are simply the easiest way to get the most bang for your buck in automated software testing.  But integrating it as part of a process is hard, and teaching it is even harder.  Young developers seem to have a hard time grasping the idea of testing isolated units of code.  I’ll confess - for a long time, much of my unit testing involved setting up the appropriate test environments - Spring containers for persistence units, test databases, you name it.  It’s expensive to test this way, and there are only so many situations when integration tests are valuable.  On lean, agile teams - code coverage isn’t held in as high regard as having working software.  On lean, agile teams - tests are a driver towards design, but they do need to be rooted in some level of initial thought on how a problem needs to be solved.

So understanding how a unit test is traceable back to a technical design on an agile team is really a key differentiation between an approach that more closely resembles cowboy coding and an approach which is relatively holistic.  No scrum master, project manager, or even architect would advocate full designs in an agile environment - instead we opt for lighter weight approaches to technical design that provide a blueprint to the code.  For many teams, this is a CRC card - a simply way of documenting the various dimensions of an object-oriented unit.

What is a CRC, and how does it relate back to tests?

Class

The core unit of code that we will refer to is the class, but this can be really any aggregation - a function library even.  This represents a loose collection of related functionality that leverages common resources, represents a concept of actions or identity, or extends existing functionality.

Responsibilities

The responsibilities of the class form it’s raison d’etre. Commonly, we can analogize responsibilities with methods, but they may be more coarse grained - and our refactoring may indeed refine the level of detail with which we understand the functional responsibilities of the class.

Collaborators

From an interestingness perspective, particularly in the context of unit testing and mocking (or stubbing), collaborators really take the cake.  When we talk about dependency injection as the core pattern of test-driven development with mocks, collaborators are indeed what we are injecting into our class to power it.

I always ask my green developers to think about these things before starting any sort of development.  Once their CRC is done and we agree on the approach, I ask them to build the programming interface, stub the implementation, and then start writing tests.  A common example I like to use when I get that befuddled look is the idea of a car.  A car has a lot of complex stuff going on that if I needed to test dependent functions of the car against, I wouldn’t want to have to concoct all of the function they provide.  For instance, the engine is a complex piece of machinery - but if I solely want to to test how my transmission reacts to engine behavior - it’s the transmission class I want to ultimately test, and it’s reactions to different engine behavior.

Let’s bring it up a level and talk about a Car as the core class.  We want our car to be able to do two things - to have two responsibilities: accelerate and stop.

public interface Car {
   int accelerate(int additionalVelocity);
 
   void setTireGrip(int gripFactor);
 
   int stop(int overDistance) throws CannotStopException;
}
 
public interface Motorable {
   int injectGasoline(int mlOfFuel);
}
 
public interface Stoppable {
   int applyBrakes() throws PadException, RotorException, WetRoadException;
}

So we’ve defined 3 interfaces. Let’s say that I’m really interested in a case where I test how the car reacts to different stopping conditions. Now, I’m demonstrating this in Java, so I’ll use syntax similar to Mockito - but the rules are the same: I’m interested in testing the requirements of the car observing the expected behavior of the brakes in those conditions. When the grip is set low, we expect the braking system to respond negatively and lock up.

We’ll also assume for now that I’ve stubbed out a skeletal implementation of the Car interface (meaning that everything throws a NotImplementedException for the time being).

@Test
public void testWetRoadConditionsWithLowFriction() {
 
   // arrange
   Stoppable s = mock(Stoppable.class);
   Motorable m = mock(Motorable.class);
 
   Car c = new CarImpl();
   c.setStopAbility(s);
   c.setMotor(m);
   c.setGripFactor(3);
 
   when(s.applyBrakes()).thenThrow(new WetRoadException());
 
   try {
      // act and assert - no real assertion, we're expecting an exception
      c.stop(100);
      fail("Should have seen a CannotStopException - there's not a lot of grip for road when road conditions are wet");
   } catch(CannotStopException e) {
      // do nothing, we're a success!
   }
}

As you can see, we’re not actually testing the brakes - we’re testing that under the given conditions that when the Stoppable interface throws an exception that prevents our car from stopping successfully that we are throw our own CannotStopException in response. The stoppable interface is a collaborator; we are not interested in this case in unit testing it, we are interested in asuming a known behavior from it, and testing how the stop() ability of the Car implementation reacts to the WetRoadException that we have stubbed.

The alternative in the past would have been to actually create the implementation of Stoppable. But having to unit test both items makes it difficult to isolate implementation issues.

So ultimately young developers, your unit tests need to test a single responsibility and not the responsibility of your collaborators. You may eventually test how the two implementations interact - that is an integration test. Ultimately though, there is more value in testing each individual unit and ensuring that the code is built to the spec of your lightweight design. Then you can isolate integration issues and write tests that specifically address finding integration problems.

Leave the first comment

Piling on Praise for Apache Wicket

I think someone finally got a web framework for Java right.

While I’m still yet to try on some of the AJAX support - something that makes or breaks a web framework these days - Wicket’s clear separation of concerns and robust architecture for MVP (right, ‘P’, as in Model-View-Presenter) has really impressed me.  Generally speaking, I have not been one to embrace convention over configuration in frameworks like RoR, simply because it seems non-scalable.  But given it’s pure focus on UI and it’s total flexibility to do whatever the hell I want with my middle tier, I’m feeling that when restricted to the presentation layer - the paradigm works.  Wicket is pretty programmer-centric, so unlike RoR, you’re not going to get off the ground without some skills or a scaffolding framework like Wicketopia, but I’m not at all convinced this isn’t a bad thing.

There are a couple of things that I could get enthusiastic with around Wicket, were someone - including myself - to improve them.

  1. Documentation. Look, I hate documenting things as much as the next guy - but in as much as I’ve enjoyed the fruits of my labor in Wicket, I have not enjoyed chasing down information to all ends of the globe.  I love the fact that this is working software, and the curve isn’t too steep - but try finding stuff on form validation, or the entire concept of mounting URL paths.
  2. Callbacks, anyone? So, forms in Wicket generally appear to be processed by the onSubmit() method of the Form class.  You override this in your child class of form.  This is the very object-oriented way of doing things, but it seems a touch limiting out of the box to not be able to register callbacks on this method.  My Form class exists so that I can have more than one of these per page, no doubt (take THAT ASP.NET), but I still think that I’d like to be able to actually register callback handlers as I wish in each Page, thus allowing Forms to have different behaviors dependent on where they are used.  I’m pretty sure this isn’t the 80% use case, but I still am left with only one alternative out of the box, and that’s to keep extending the class hierarchy.  It’s nice to embrace strategy pattern and all, but to me this is where we really need an observer.

    So I was able to fudge this myself by creating a FormSubmitListener interface, subclass Form and implement it’s onSubmit() to call the formSubmitted() method from my new interface, it’s own implementation registered through the constructor on my Form subclass - but I think in an MVP or MVC framework, I still would like the ability to use OOP to handle the quirks of the page lifecycle (yeah, yeah - Wicket is unmanaged), but allow observers to actually handle pseudo-user events.

These two things aside, I feel pretty at peace with Wicket as my web framework for Java projects going forward (sorry Seam).

Another note - I’m really interested in the possibilities of packaging all of the resources for the web project in the JAR file.  While WAR’s are fine for deployment, JAR’s make the application open for truly modular design.

Now to refresh my memory on getting JTA running in a pure servlet container…

Leave the first comment

Mocks - the only thing separating complex TDD from value-added TDD

About two years back when I started getting completely fascist about test-driven development, the complexity was always “gee, i have an application container and I need to involve it in my unit tests so that I can get full test coverage !!111oneeleventy.”

This typically meant providing a real collaborator, like a PersistenceUnit in Java, so that I could test trivial operations like persisting an entity.  At the time, I challenged a manager on this:

What are we really testing?  Are we testing OUR requirement, or are we testing something we should reasonably expect Hibernate to do on the basis of our initial technology selection?

Code coverage I believe is pretty overrated.  No one cares whether or not you can prove your method to persist an entity works because the developers of Hibernate/TopLink/LINQ to SQL have already proved this through their unit tests. What you are building when you write a test that actually checks the database to see if your middleware used a pre-packaged object-relational manpping framework correctly is an integration test.  There’s certainly value to integration testing with data access layers, particularly when difficult to test components of your middleware (like stored procedures and triggers) are involved.  Saving that however, the focus of test-driven development - namely unit tests, should be on the business logic that is proprietary to your applicatiom, be it the front-end or the middle tier.

Now, suffice to say that to a good number of developers and architects this isn’t news, but if you really want to isolate the code which you wrote that is specific to your business rules and requirements - mocking frameworks are the way to go.  Particularly in an Agile project where we can readily identify certain injected dependencies (like an EntityManager, for example) as a collaborator of the class under test, your unit test is really interested in asking the question based on this interaction with this external component, how should I expect my logic to react?

In these scenarios of course, I mock or stub the EntityManager.  In the past, a fool like me would have tried to load a container within my unit test environment.  This is actually an integration test, in addition to the fact that it is costly and doesn’t add the value a truly isolated unit test which focuses on the code you wrote does.

In .Net, RhinoMocks is scalding hot with it’s supprt for mocking through lambda’s.  In JEE, I’ve fallen in love with Mockito.

So, stop worrying about how you can get JBoss running so that your CI environment can execute inside of it.  Instead, use mocks to give your code the resources it needs to vet out the conditions in your own code that you want to test.

One comment so far, add another

Diving back into Java, and liking it (mostly)

So for various reasons, I’ve pulled Eclipse Ganymede down and decided to check in on where Java has gone during my year-long mental hiatus in Redmond.  I have certain biases now from the land of .Net, and god help the Java world if it angers me after seeing the things I’ve seen in the last year.

All in all, I’m very pleased.

The m2eclipse plugin is marvelous, finally.

The day has finally come where I’m no longer fighting Eclipse to build projects using Maven, as it should be.  Maven ties far too many niceties of the world together, and to not have it as the underlying, portable build tool within the IDE has always frustrated me.  The ability to quickly start a new Maven project, apply an archetype and go is fantastic.  The fact that it doesn’t require special jazz to get a WTP project up and running is even better.

Hey look, working with my database and some JPA implementation is really easy!

…well, almost easy.  I created a project for my middleware just using the quickstart archetype.  I was just going to throw Spring on top of it and avoid spoiling the good experience so far with EJB insanity.  The next thing I wanted to do was load up my database tables as ORM classes via Hibernate.

For whatever reason, this was cool on my Mac.  Project Properties…JPA Tools…Generate entities.  This is somehow not the way to do it over in windows.  So instead I tried to add JPA as a project facet.

My first problem was that I didn’t have Hibernate set up as my default JPA provider.  Unfortunately, you can only do this through the Maven-managed dependencies.  It has to be an Eclipse user library.  So I download the Entity Manager and wire it up into Eclipse.  Add the Java Facet (somehow not a default, probably Maven’s fault), added the JPA Facet (and am told I need to add the Utility Facet, so I do that).

Further configuration required.

Ok.  So I click into this further configuration and it reasonably wants to know how I connect to the database.  Fair enough.  I do all this, and it still won’t let me apply the change.

Eventually, it appears you need to add the Java project facet first, and then and only then can I reopen the properties page and apply the JPA facet.  A frustration point, but I figured it out.

Hey, nothing special to get a project with the Wicket archetype running in WTP.

I start a separate web project and use the Wicket archetype, interested in tackling what looks to be a nice, lightweight UI package for Java (though it looks like Spring integration isn’t trivial - which is basically unacceptable these days).  I start the project, I add a server configuration, and deploy…

Holy crap, it works out of the box!

I have a ways to go, but things feel more turnkey with Eclipse than I’ve ever experienced.  I did up some JUnits with Mockito, and that was easy, indicating that if I were to set up Cruise or some other CI tool, I could quickly get going with a full Agile project.  Exciting stuff.

2 comments so far, add yours

Some free advice to independent software contractors

I saw a post on Craigslist this morning for a software gig that made me shake my head.

“I have been outsourcing and modifying an Open Source project. There is about 50-100hrs of scoped development. Let me know your availability and rate.”

Jobs like this one are poison that really puts all of the burden on your shoulders.  I’ve been a consultant for several firms, and have lead delivery of many large and small projects.  Here are a few tips to make it so that you maximize the shared risk in a project, maximize your revenue, and ensure the highest possible customer satisfaction.

Always Price on Your Own Estimates

You’re the one doing the work, and you know how long it might take you to complete a given project.  If a potential client hands you an amount of scope and a timeline (like the real-world example above), I would always request to assess the scope yourself and provide your own estimate before committing to anything.  If the prospect is amenable to this, then it serves you well to give them a good faith estimate and some solutions in the case that your estimate is different.  If the prospect is time sensitive, then work with them on adjusting the scope.  If the scope is driving the project, then encourage them to consider an additional investment of time to ensure the completion of the full scope.  Be willing to make concessions on your rate in these cases - flexibility from the client should be greeted mutually with your ability to discount your own rate.

If the client is not going to be flexible, then your best bet is to walk away or mitigate your risk through a more premium rate.  Likely even in the latter case, a less saavy contractor will underbid you and find themselves in trouble.  Better them than you.

Avoid Fixed Price/Fixed Time Projects

Clients love fixed price/fixed time projects.  It removes almost all of their risk in the project and places you in the position of likely pulling quite a few late nights and reducing your hourly rate.  Large consulting shops, particularly offshore ones - have the ability to enter into these arrangements and blend their rate accordingly to account for the need for additional resources in the case that the project falls behind schedule.  For them, the cost of working a project beyond the deadline is significantly higher than it is to simply add more horsepower.  Project management and technical oversight adds overhead in the project, and vendors are more than happy to not keep them on an engagement any longer than they need to.

That said, time and materials (hourly) arrangements are the best for the independent contractor.  They place all of the burden to manage scope upon the client, and the client has to trust the vendor to report hours accordingly and honestly.  Always aim for these projects, but do be honest with your client about hours and estimates around the cost of the engagement to them.  Be willing to discount when your estimates are inaccurate.

Another option is a middle ground called target cost, but these types of projects are typically the result of significant trust between client and vendor.  Simply put, you bill at your hourly rate for the agreed upon scope and any additional scope, and a discounted rate for defects and enhancements.  This typically keeps both parties honest.  Clients look to control scope for the same reasons they do in T&M, and it’s in your interest to finish on time as to avoid continuing work at a discounted rate (when you could be taking on new projects at your standard rate).

Request Right of First Refusal

Clients are fickle.  No matter how good your work is, when times are tight (as they are now), they will search for less expensive options.  Many times when negotiating with clients, I have asked for right of first refusal in whatever contract we agree to as to ensure exclusivity.  This makes you the preferred vendor and allows you to take all work that you are interested in before it is made available to competing contractors.  Often times, this will require that you discount your rate.  Additionally, this is usually only received well once you have established a track record of delivery with a client.  But if you can negotiate this clause, it can go a long way to ensure you a consistent revenue stream and source of work.

At the end of the day, your client’s satisfaction will be the best way to maintain business and build a stable relationship built on trust.  Be open and flexible, but protect your position and never take on more risk than is neccessary, regardless of how desperately you want to land a gig.

Leave the first comment

Java Still Has Some Respect

A colleague sent along a note about how Dave Rosenberg feels that Sun Doesn’t Respect Java. As I noted in a post from yesterday, I think there are some things to like about JAX-RS.  But as a decent JEE architect, I have some thoughts on whether Java actually is exciting anymore.

  1. Has Java gotten boring?  If you’re a web developer, Java has always been like 6AM - too early to really be interesting, too late to convince you to go back to sleep;
  2. Java’s middle tier absolutely blows anything else out of the water.  I like LINQ, but comparables like ActiveRecord for RoR or PHPYii simply can’t do the things that JPA can do;
  3. IoC/DI in Java, open source or JEE, is still better than anything anyone is doing today - Castle included.

Dave points out that the “write-once, run anywhere” paradigm may have lost out to virtualization.  Call me when virtualization is native to all of the major OS’s, Dave.  Until then, the JVM is still the closest thing we have to a platform independent environment.

I’ve looked at the EE6 spec, and he’s right though.  Omitting things like Web Beans is certainly a disappointment.  The fact that we still don’t have great native dependency injection in the EE platform leaves us always falling back upon Spring.  All of these things are rather frustrating.

JavaFX - just terrible.  Adobe did it right with AIR, even if adoption is seemingly limited to hundreds of Twitter clients.

If Sun wants to start pushing the envelope instead of follwoing the leader - how about embracing a cloud computing platform through JEE?  JAX-RS is promising, but why not unify the JAX-WS and JAX-RS spec to provide a single platform for all web-based SOA?  At the very least, that would put them on par with WCF.

Leave the first comment

Unification of Java Weeds in a Standards Garden

After my post the other day in relation to building proper web UI architecture in PHP, my brain reverted to thinking about the complexities of web application development in Java and how in spite of standards, the amount of organic homegrown stuff that’s out there has muddied the water to the extent that it’s difficult to separate the wheat from the chaffe.  Sun has tried it’s darndest to follow the elephant and clean up behind it, but there is an increasingly sordid history of great ideas (Hibernate, Spring) that gained enough community momentum where Sun felt that these innovative platforms and their imitators should be unified behind a single standard.  In fact, it’s increasingly difficult to find parts of Java that were invented by Sun.

I haven’t been architecting Java solutions for a living in nearly a year now, and last I checked the state of the world was more or less:

  • EJB had assimilated Hibernate and other ORM solutions as something now called JPA, which was neccesary and useful to standardize;
  • EJB had also taken elements of Spring to invert the once ubiquitous locator pattern and adopt dependency injection as the standard for satisfying collaborator relationships.  Of course, the Sun solution aimed to solve specific problems in EJB, and had less interest in solving the more general need for standardization around DI-based application frameworks;
  • JSF was crashing and burning in the web tier, with Gavin King once again trying to pick up the pieces and simplifying the entire stack through Web Beans.

So to distill it down - middleware in Java was actually a pleasurable place to work, and the web tier was still a torture chamber.

Note: I’m leaving Velocity, Struts, Spring, and Tapestry out of the mix here.  That’s not to say that there isn’t value in some of these frameworks.  Tapestry was architecturally sound but hinders rapid development.  Struts and Spring both require siginificant configuration, and Velocity is…like Smarty for PHP.  All of them did so many things differently that it would be difficult to standardize around any one of them.  Additionally, the only one that could arguably be standardized within the exiting JEE stack is Spring - which attempts to solve many of the problems of front and middle-tier integrations.

Per my post from the other day, I really feel that the age of the server-based Web UI framework is dead.  MVC will always be a necessity, but re-usable controls and architectures that try to solve all of the world’s problems with different delivery mechanisms be it HTML or JSON are at a dead end - it’s simply not scalable.  So my attention turned to an article by James Strachan about JSR-311 and how he feels it could be the standard to solve much of the worlds problems.  JSR-311 addresses the JAX-RS standard for delivery of RESTful services.  This has long been needed from Sun given the narrow nature of the JAX-WS spec, but James has the right idea.

…Having had a horrid time using Tapestry and Hibernate together on some projects in the past, I’m kinda over the whole concept of server side UI web frameworks personally (I’m putting my flame-proof suite on now). I kinda think if you want to do complex rich web UIs, use wizards or complex flows, just use GWT or JavaScript on the client (or Flex/Flash for video or crazy highly graphical widgets) and keep the server side fairly simple and very RESTful….

So, I’m not the only crazy one out there.  That’s comforting.  But is a standard that serves as the foundation for tools to deliver RESTful services the answer?  From an architecture perspective, I’ve always been of the mindset that RESTful services, particular with its HTTP metaphors is just a DAO pattern exposed as services.  This is a pretty fine grain for me, but as Seam in Java and LINQ in .Net are beginning to prove - the value of coarse grained business services as provided typically by Session Beans in EJB may be a bit overstated.  So, does it make sense to build web frameworks that are really geared towards SaaS, and allow frameworks like Spring or Velocity or, hell even simple XSLT - take the helm when more traditional request-response mechanisms are needed?

And even more so, a cursory review of the JAX-RS doesn’t really present any options for consuming the services produced by implementers.  That’s somewhat understandable given that the product is typically vanilla XML or JSON or Text or whatever.  When I wrote my own RESTful service implementation using Spring a few years back, I made sure that XSD was attached and available when the service was XML.  This made it easy to write JAXB clients if your consumer was another Java application.  Slowing down development by forcing homogeneous consumers to parse the response as DOM seems like a likely outcome of not having SOME way of addressing this issue.

Taken together, I’m on board with the idea that JSR-311 could be a good foundation for a web framework that treats the client as being smart, rather than the dumb terminal approach of the past.

Leave the first comment

PHP Prado, Yii, and Building UI Architecture in the Right Place

I’ve been spending a minuscule amount of time as of late scrutinizing PHP frameworks - largely because it’s so damn difficult to build anything that can be deployed to a cheap hosting provider in Java or .Net.  In my travels these last few years, my conclusion is that Java is just terrible at handling web UI architecture and that the servlet architecture is horribly broken.  But you already knew that.

ASP.Net is fascinating in that it really tries to port good classic MVP modeling to a web architecture.  But we live in a world today that needs two models of web application development - one that focuses intently on transactional operations and can adhere to the infrastructure that ASP.Net or even Java Server Faces provide, or one that is totally dependent on the faclities of the browser.  Where Microsoft and Sun/JBoss/OSS have gone totally off the deep end is in the latter case by trying to solve client side issues on the server.

So I looked at PHP Prado the other day, and saw that it’s more or less a direct port of the ASP.Net architecture.  Fair enough.  I can’t see how it can be performant or scale - it’s taking the pig of ASP and adding a significant hassle in backing it with a scripting language.  But as I dove deeper and tried to find out how it supported AJAX, I saw that it made the same mistakes that ASP and JSF had made by trying to adapt the server-supported client UI architecture into a model where the server really had very little to do with the presentation.

I’m now off and looking for a PHP framework that doesn’t attempt to solve the problem in this way.  Microsoft has already figured out that it’s incredibly complicated to accomodate both paradigms of web development throug a UI architecture that was initially developed to run from the server and has built ASP.Net MVC and WCF to support a model where the coupling is much looser.  Maybe someday, Java will get it (though I will cop to not knowing what people in the Spring world are doing, and they tend to be a bit ahead of the curve in these matters).  I’m now looking at PHP Yii, and it looks like another dreaded rails-inspired framework.  However, if it’s not trying to boil the ocean with complex UI architecture and tell the browser to handle things as it may, perhaps I can be won over to the rails-religion yet.

4 comments so far, add yours