Feeds

Frameworks and the danger of a grand design

Hard-lesson learned

The essential guide to IT transformation

It's probably safe to say that we've all succumbed to the "grand-design mindset" at one stage or another. It's a critical stage in a developer's growth: the dawning awareness that design matters, an earnest desire to write good code but without the bitter lessons that the reality of an over-designed project will soon fling at you.

The developer at this stage hasn't yet learned the hard way, that you can get too much of a good thing. This isn't really something that can be taught, at least not in such a way that it really drums the lesson home. You have to experience the pain of creating an over-designed "framework for the sake of it", believing in all good faith that your grand design will help, not hinder, maintainability.

The grand design mindset isn't just the application of an anti-pattern, or even just the inappropriate use of a normally well-behaved design pattern. The mindset is the overuse of patterns, carefully cementing nano-thin layers of indirection atop each other like a process in a chip fabrication plant that can't be shut down. It's the naïve belief that if X is good then 100X must be better every time.

Luckily this mindset is easy to spot. Your team members will be busy creating a beautiful but over-designed system with enums, annotations, closures and all the latest language features, loosely coupled classes and several hundred pluggable frameworks when a well-placed isThisTheRightValue() method would probably have sufficed.

Picture a pluggable framework that only ever has one plug. You'll see a comment in the code like:

    // Later this could be applied to other parts of the system. 

If there's neither time nor a compelling reason to apply the pluggable framework to other parts of the system in this iteration, then it's likely the programmer going off on a design pattern hike - exploring their talents - and the framework should be struck out of the code. It's just more complexity to maintain.

Of course, some programmers will never learn: they like writing code too much. Lots of it, as if they're paid in lines of code, or reviewed that way. Or maybe it's a macho thing. Pursuing your own grand design will do that for you, but it's better to solve problems with little code. Less is more.

Modern refactoring tools make it way too easy to fall into the "grand design" trap, with developers encouraged to develop the design as they're coding it. The refactoring tools are fast and sweeping. Radical design changes are just a keyboard combo away.

It's nice to think of refactoring as "redesigning at the speed of thought". But it isn't, it's refactoring faster than the programmer can think about the design and reflect on its implications for the rest of the system. The programmer is too immersed deep-down in the code to really appreciate the design from a higher level. So grand designs emerge before the programmer realizes it.

To develop their own design skills beyond the stage of the grand design, programmers must recognize that any time they're creating reusable code, they're writing a framework. It could be a modest one-class framework, or a system-wide thing of great complexity (like a data access object layer or presentation layer, for example). The developer must then also twig some important things about frameworks:

1. A bad framework is far worse than no framework at all

2. Good frameworks are hard to get right

3. You probably don't want to be writing your own framework anyway (or even seeking out a third-party one, for that matter)

Sometimes, specific, non-reusable code just hits the spot, because it gets the job done with a minimum of complexity. But sometimes, you do want code to be re-usable because you can see exactly where it'll be re-used. Having an overall design and an understanding of the broad set of requirements helps to identify whether re-usable code is needed.

But without stumbling upon this hard-earned lesson - without that Eureka! moment - the well-meaning developer will be stuck with a grand-design mindset forever.®

Matt Stephens is co-author of Use Case Driven Object Modeling with UML: Theory and Practice, which illustrates how to drive functional tests and unit tests from use cases, using the Spring Framework, JUnit and Enterprise Architect.

Secure remote control for conventional and virtual desktops

More from The Register

next story
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
Mozilla's 'Tiles' ads debut in new Firefox nightlies
You can try turning them off and on again
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Endpoint data privacy in the cloud is easier than you think
Innovations in encryption and storage resolve issues of data privacy and key requirements for companies to look for in a solution.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Advanced data protection for your virtualized environments
Find a natural fit for optimizing protection for the often resource-constrained data protection process found in virtual environments.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.