The size of a code base is not the worst enemy of code.
My personal experiences with code bases large and small have given me the insight to realize that size of code is a terrible enemy but not our worst enemy. Our worst enemy is stupidity. Well, not out right stupidity but what I call the cognitive Gordian knot.
The larger a code base is the more material there is to create a knot. The smaller, the less material there is to create a mess with. So there is beauty in the small. I have been arguing for the decomposition of large projects into small reusable code units for most of my career.
Yet, I've seen examples at Coding Horror and The Daily WTF that show in a scant few lines some of the most impressive inability to think I have ever seen. These examples are not necessarily what we would consider mind numbingly, guffawingly, powerfully brutish idiocy but subtle brain warping WTF? These are the thought-knots we can't untie like that knot of legend the Gordian knot.
During my time over seas I have worked on code bases whose ages were measured in decades and sizes estimated in rough fractions of millions of lines. Code bases of this size are surely incomprehensible but the best can have inner structure that can be navigated and internal API that can be understood. The reader of this kind of code doesn't need to know what exactly each call does but only understand the local code and some specific libraries to work on it.
And then later in my career... oh the irony... I maintained a code base of a scant few hundred thousand lines of code whose internal structure shifted upon itself every few lines. Every few hundred lines a new API, a new convention, a re-written API, a half-refactor, a violation of another API. And so on the insanity folded over and over upon itself like a Lewis Caroll narrative without any beautiful onomatopoeia. All of it written by the same person over the course of five years.
Instead of a crystalline structure found in those majestic and old code bases whose patterns fold and unfold like a fractal thus leading the maintainer to an understanding of the whole from only a part... this newer... this smaller... this uglier code base contained no song and no resonance that my mind could fix upon. Instead it was a tangle of swamp weed coated in a toxic sludge that defied understanding and like "Alexander the great and the Gordian knot" I saw no other answer to my problems other than to cut it asunder. Bust it up, break it apart, make it small again.
No, I know better, size is not what kills code. It is the Gordian knot of superficial complexity that kills code. Instead of a crystalline pattern or an enforced internal structure the code is allowed to grow untamed. The key to long life in code is pulling out and separating concerns into libraries and frameworks.
You could argue this tactic constitutes removing some code from the main code base and creating small supporting projects that fit together to create a whole. You'd be right. That's what it is. That is what I mean by saying fractal, crystalline, or internally disciplined. The supporting libraries may be internal to the project but they may constitute sub-projects they divide and conquer the problems and keep the material from building to the point that it can accidentally tie itself in a knot.
You could achieve this using MVC, Services, or libraries. I've seen Domain Driven Designs and Spring annotations to enforce SoC that would work well. You could say this is how Linux and GNU work together to create a full operating system. You could say that is code reuse and proper object orientation. You could say this the weapon we have in the mix-in and dynamic language.
Whatever you call it. It makes code easier to understand because it has a logical structure and what I call a resonance or song. It means you can see part of a code base, understand it, and ignore the other concerns to focus on your particular problem.
If you can dive into one section of code and comprehend it without having to comprehend the whole thing then I say you have a good code base no matter how big or how small it is. The goal is to keep the knotty beast at bay for as long as possible using every trick we have.
Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts
2007-12-26
2007-07-11
The joy of symbolic links
I'm working with different versions of JBoss. My company has standardized on /usr/local/jboss as the home directory for JBoss. All JBoss servers will find their homes under /usr/local/jboss but we upgrade JBoss servers about once a year. As a developer often I'm swapping between production and test environments switching between JBoss versions.
For example today we are going to production with JBoss 4.0.5 but we are moving forward on JBoss 4.2.0 and I need to swap between the different versions for different projects. Now we already use symbolic links in production. Let me show you how those work.
The directory /usr/local/jboss is actually a symbolic link made like this:
$ sudo ln -s /usr/local/jboss-4.0.5 /usr/local/jboss
If we upgrade to jboss-4.2.0 I can simply remove the symbolic link and point it at the new directory like this:
$ sudo rm /usr/local/jboss && sudo /usr/local/jboss-4.2.0 /usr/local/jboss
And now my server is upgraded and there is an easy way to "fall back" should I need to.
But what if I'm a developer?
For my developer set up I'll head off to my home directory and then I'll make a JBoss directory where I'll keep all the various versions of JBoss that I'm using. I'll have a ~/jboss/jboss-4.0.5 and a ~/jboss/jboss-4.2.0 for example.
Next I'll make a symbolic link...
$ ln -s ~/jboss/jboss-4.2.0 ~/jboss/current
... and then I'll make one more symbolic link ...
$ sudo ln -s ~/jboss/current /usr/local/jboss
Now when I need to change my current working version of jboss...
$ rm ~/jboss/current && ln -s ~/jboss/jboss-4.0.5 ~/jboss/current
For example today we are going to production with JBoss 4.0.5 but we are moving forward on JBoss 4.2.0 and I need to swap between the different versions for different projects. Now we already use symbolic links in production. Let me show you how those work.
The directory /usr/local/jboss is actually a symbolic link made like this:
$ sudo ln -s /usr/local/jboss-4.0.5 /usr/local/jboss
If we upgrade to jboss-4.2.0 I can simply remove the symbolic link and point it at the new directory like this:
$ sudo rm /usr/local/jboss && sudo /usr/local/jboss-4.2.0 /usr/local/jboss
And now my server is upgraded and there is an easy way to "fall back" should I need to.
But what if I'm a developer?
For my developer set up I'll head off to my home directory and then I'll make a JBoss directory where I'll keep all the various versions of JBoss that I'm using. I'll have a ~/jboss/jboss-4.0.5 and a ~/jboss/jboss-4.2.0 for example.
Next I'll make a symbolic link...
$ ln -s ~/jboss/jboss-4.2.0 ~/jboss/current
... and then I'll make one more symbolic link ...
$ sudo ln -s ~/jboss/current /usr/local/jboss
Now when I need to change my current working version of jboss...
$ rm ~/jboss/current && ln -s ~/jboss/jboss-4.0.5 ~/jboss/current
Labels:
administration,
coding,
howto,
jboss,
linux
2007-06-18
Stuplexity
Stuplexity: A solution that is provided to solve a problem in an extremely non-obvious complex manner when a simple and obvious solution is readily available is said to possess stuplexity.
Example: "The stuplexity of this code is so amazing, I wonder if the programmer knew what a procedure was?"
Example: "The stuplexity of this code is so amazing, I wonder if the programmer knew what a procedure was?"
2007-06-11
By population...
I just happened to run across this statistic that makes me wonder what kinds of effects the additional one billion computers expected in the next five years will have if they are mostly owned by Asian users. Programming languages today are structured around western languages. In particular English. If you are not a native English speaker I wouldn't be surprised if some of the prevalent programming constructs aren't alien because they are tailored to an English speaking mind.
Labels:
coding,
languages,
programming,
society
2007-05-29
A year with Java 5 EE
I've spent the last year with Java 5 Enterprise Edition betas and I'm going to talk about my experiences with the Java environment as a relative newcomer to the Java landscape. My background is in C/C++ System V programming on Linux, Solaris, and Irix systems. It has been a hard year but one that I'm thankful for. I've learned a lot about how Service Oriented Architectures go together, why they work, and why they fail.
Labels:
coding,
j5ee,
Java5,
jee,
soa,
soap,
software culture,
Software Design,
xml
Subscribe to:
Posts (Atom)