Timeless Laws of Software Development

This article was originally posted on Embedded Artistry.


I am always seeking the wisdom and insights of those who have spent decades working in software development. The experiences of those who came before us is a rich source of wisdom, information, and techniques.

Only a few problems in our field are truly new. Most of the solutions we seek have been written about time-and-time-again over the past 50 years. Rather than continually seeking new technology as the panacea to our problems, we should focus ourselves on applying the tried and tested basic principles of our field.

Given my point of view, it’s no surprise that I was immediately drawn to a book titled Timeless Laws of Software Development.

The author, Jerry Fitzpatrick, is a software instructor and consultant who has worked in a variety of industries: biomedical, fitness, oil and gas, telecommunications, and manufacturing. Even more impressive for someone writing about the Timeless Laws of Software Development, Jerry was originally an electrical engineer. He worked with Bob Martin and James Grenning at Teradyne, where he developed the hardware for Teradyne’s early voice response system.

Jerry has spent his career dealing with the same problems we are currently dealing with. It would be criminal not to steal and apply his hard-earned knowledge.

I recommend this invaluable book equally to developers, team leads, architects, and project managers.

Table of Contents:

  1. Structure of the Book
  2. The Timeless Laws
  3. What I Learned
  4. Selected Quotes
  5. Buy the Book

Structure of the Book

The book is short, weighing in at a total of 180 pages, including the appendices, glossary, and index. Do not be fooled by its small stature, for there is much wisdom packed into these pages.

Jerry opens with an introductory chapter and dedicates an entire chapter to each of his six Timeless Laws (discussed below). Each law is broken down into sub-axioms, paired with examples, and annotated with quotes and primary sources.

Aside from the always-useful glossary and index, Jerry ends the book with three appendices, each valuable in its own right:

  • “About Software Metrics”, which covers metrics including lines of code, cyclomatic complexity, software size, and Jerry’s own “ABC” metric
  • “Exploring Old Problems”, which covers symptoms of the software crisis, the cost to develop software, project factors and struggles, software maintenance costs, superhuman developers, and software renovation.
  • “Redesigning a Procedure”, where Jerry walks readers through a real-life refactoring exercise

“Exploring Old Problems” was an exemplary chapter. I highly recommended it to project managers and team leads.

My only real critique of the book is that the information is not partitioned in a way that makes it easily accessible to different roles – project managers may miss valuable lessons while glossing over programming details. Don’t give in to the temptation to skip: each chapter has valuable advice no matter your role.

The Timeless Laws

Jerry proposes six Timeless Laws of software development:

  1. Plan before implementing
  2. Keep the program small
  3. Write clearly
  4. Prevent bugs
  5. Make the program robust
  6. Prevent excess coupling

At first glance, these six laws are so broadly stated that the natural reaction is, “Duh”. Where the book shines is in the breakdown of these laws into sub-axioms and methods for achieving the intent of the law.

Breakdown of the Timeless Laws

  1. Plan before implementing
    1. Understand the requirements
    2. Reconcile conflicting requirements
    3. Check the feasibility of key requirements
    4. Convert assumptions to requirements
    5. Create a development plan
  2. Keep the program small
    1. Limit project features
    2. Avoid complicated designs
    3. Avoid needless concurrency
    4. Avoid repetition
    5. Avoid unnecessary code
    6. Minimize error logging
    7. Buy, don’t build
    8. Strive for Reuse
  3. Write clearly
    1. Use names that denote purpose
    2. Use clear expressions
    3. Improve readability using whitespace
    4. Use suitable comments
    5. Use symmetry
    6. Postpone optimization
    7. Improve what you have written
  4. Prevent bugs
    1. Pace yourself
    2. Don’t tolerate build warnings
    3. Manage Program Inputs
    4. Avoid using primitive types for physical quantities
    5. Reduce conditional logic
    6. Validity checks
    7. Context and polymorphism
    8. Compare floating point values correctly
  5. Make the program robust
    1. Don’t let bugs accumulate
    2. Use assertions to expose bugs
    3. Design by contract
    4. Simplify exception handling
    5. Use automated testing
    6. Invite improvements
  6. Prevent excess coupling
    1. Discussion of coupling
    2. Flexibility
    3. Decoupling
    4. Abstractions (functional, data, OO)
    5. Use black boxes
    6. Prefer cohesive abstractions
    7. Minimize scope
    8. Create barriers to coupling
    9. Use atomic initialization
    10. Prefer immutable instances

What I Learned

I’ve regularly referred to this book over the past year. My hard-copy is dog-eared and many pages are covered in notes, circles, and arrows.

I’ve incorporated many aspects of the book into my development process. I’ve created checklists that I use for design reviews and code reviews, helping to ensure that I catch problems as early as possible. I’ve created additional documentation for my projects, as well as templates to facilitate ease of reuse.

Even experienced developers and teams can benefit from a review of this book. Some of the concepts may be familiar to you, but we all benefit from a refresher. There is also the chance that you will find one valuable gem to improve your practice, and isn’t that worth the small price of a book?

The odds are high that you’ll find more than one knowledge gem while reading Timeless Laws.

Here are some of the lessons I took away from the book:

  1. Create a development plan
  2. Avoid the “what if” game
  3. Logging is harmful
  4. Defensive programming is harmful
  5. Utilize symmetry in interface design

Create a Development Plan

We are all familiar with the lack of documentation for software projects. I’m repeatedly stunned by teams which provide no written guidance or setup instructions for new members. Jerry points out the importance of maintaining documentation:

Documentation is the only way to transfer knowledge without describing things in person.

One such method that I pulled from the book is the idea of the “Development Plan”. The plan serves as a guide for developers working on the project. The plan describes the development tools, project, goals, and priorities.

As with all documentation, start simple and grow the development plan as new information becomes available or required. Rather than having a large document, it’s easy to break the it up into smaller, standalone files. Having separate documents will help developers easily find the information they need. The development plan should be kept within the repository so developers can easily find and update it.

Topics to cover in your development plan include:

  • List of development priorities
  • Code organization
  • How to set up the development environment
  • Minimum requirements for hardware, OS, compute power, etc.
  • Glossary of project terms
  • Uniform strategy for bug prevention, detection, and repair
  • Uniform strategy for program robustness
  • Coding style guidelines (if applicable)
  • Programming languages to be used, and where they are used
  • Tools to be used for source control, builds, integration, testing, and deployment
  • High-level organization: projects, components, file locations, and naming conventions
  • High-level logical architecture: major sub-systems and frameworks

Development plans are most useful for new team members, since they can refer to the document and become productive without taking much time from other developers. However, your entire team will benefit from having a uniform set of guidelines that can be easily located and referenced.

Avoid the “What If” Game

Many of us, myself included, are guilty of participating in the “what if” game. The “what if” game is prevalent among developers, especially when new ideas are proposed. The easiest way to shoot a hole in a new idea is to ask a “what if” question: “This architecture looks ok, but what if we need to support 100,000,000 connections at once?”

The “what if” game is adversarial and can occur because:

  • Humans have a natural resistance to change
  • Some people enjoy showing off their knowledge
  • Some people enjoy being adversarial
  • The dissenter dislikes the person who proposed the idea
  • The dissenter does not want to take on additional work

“What if” questions are difficult to refute, as they are often irrational. We should always account for realistic possibilities, but objections should be considered only if the person can explain why the proposal is disruptive now or is going to be disruptive in the future.

Aside from keeping conversations focused on realistic possibilities, we can mitigate the ability to ask “what if” with clear and well-defined requirements.

Logging is Harmful

I have been a long-time proponent of error logging, and I’ve written many embedded logging libraries over the past decade.

While I initially was skeptical of Fitzpatrick’s attitude toward error logging, I started paying closer attention to the log files I was working with as well as the use of logging in my own code. I noticed the points that Jerry highlighted: my code was cluttered, logs were increasingly useless, and it was always a struggle to remove outdated logging statements.

You can read more about my thoughts on error logging in my article: The Dark Side of Error Logging.

Defensive Programming is Harmful

Somewhere along the way in my career, the idea of defensive programming was drilled into me. Many of my old libraries and programs are layered with unnecessary conditional statements and error-code returns. These checks contribute to code bloat, since they are often repeated at multiple levels in the stack.

Jerry points out that in conventional product design, designs are based on working parts, not defective ones. As such, designing our software systems based on the assumption that all modules are potentially defective leads us down the path of over-engineering.

Trust lies at the heart of defensive programming. If no module can be trusted, then defensive programming is imperative. If all modules can be trusted, then defensive programming is irrelevant.

Like conventional products, software should be based on working parts, not defective ones. Modules should be presumed to work until proven otherwise. This is not to say that we don’t do any form of checking: inputs from outside of the program need to be validated.

Assertions and contracts should be used to enforce preconditions and postconditions. Creating hard failure points helps us to catch bugs as quickly as possible. Modules inside of the system should be trusted to do their job and to enforce their own requirements.

Since I’ve transitioned toward the design-by-contract style, my code is much smaller and easier to read.

Utilize Symmetry in Interface Design

Using symmetry in interface design is one of those points that seemed obvious on the surface. Upon further inspection, I found I regularly violated symmetry rules in my interfaces.

Symmetry helps us to manage the complexity of our programs and reduce the amount of knowledge we need to keep in mind at once. Since we have existing associations with naming pairs, we can easily predict function names without needing to look them up.

Universal naming pairs should be used in public interfaces whenever possible:

  • on/off
  • start/stop
  • enable/disable
  • up/down
  • left/right
  • get/set
  • empty/full
  • push/pop
  • create/destroy

Our APIs should also be written in a consistent manner:

  • Motor::Start() / Motor::Stop()
  • motor_start() / motor_stop()
  • StartMotor() / StopMotor()

Avoid creating (and fix!) inconsistent APIs:

  • Motor::Start() / Motor::disable()
  • startMotor / stop_motor
  • start_motor / Stop_motor

Naming symmetry may be obvious, but where I am most guilty is in parameter order symmetry. Our procedures should utilize the same parameter ordering rules whenever possible.

For example, consider the C standard library functions defined in string.h. In all but one procedure (strlen), the first parameter is the destination string, and the second parameter is the source string. The parameter order also matches the normal assignment order semantics (dest = src).

The standard library isn’t the holy grail of symmetry, however. The stdio.h header showcases some bad symmetry by changing the location of the FILE pointer:

int fprintf ( FILE * stream, const char * format, ... );
int fscanf ( FILE * stream, const char * format, ... );

// Better design: FILE is first!
int fputs ( const char * str, FILE * stream );
char * fgets ( char * str, int num, FILE * stream );

Keeping symmetry in mind will improve the interfaces we create.

Selected Quotes

I pulled hundreds of quotes from this book, and you will be seeing many of them pop up on our Twitter Feed over the next year. A small selection of my highlights are included below.

Any quotes without attribution come directly from Jerry.

Intentionally hiding a bug is the greatest sin a developer can commit.

Failure is de rigueur in our industry. Odds are, you’re working on a project that will fail right now.
— Jeff Atwood, How to Stop Sucking and Be Awesome

Writing specs is like flossing: everybody agrees that it’s a good thing, but nobody does.
— Joel Spolsky

Documentation is the only way to transfer knowledge without describing things in person.

Robustness must be a goal and up front priority.

Disorder is the natural state of all things. Software tends to get larger and more complicated unless the developers push back and make it smaller and simpler. If the developers don’t push back, the battle against growth is lost by default.

YAGNI (You ain’t gonna need it):
Always implement things when you actually need them, never when you just foresee that you need them. The best way to implement code quickly is to implement less of it. The best way to have fewer bugs is to implement less code.

— Ron Jeffries

Most developers write code that reflects their immediate thoughts, but never return to make it smaller or clearer.

The answer is to clear our heads of clutter. Clear thinking becomes clear writing; one can’t exist without the other.
— William Zinsser

Plan for tomorrow but implement only for today.

Code that expresses its purpose clearly – without surprises – is easier to understand and less likely to contain bugs.

Most developers realize that excess coupling is harmful but they don’t resist it aggressively enough. Believe me: if you don’t manage coupling, coupling will manage you.

Few people realize how badly they write.
— William Zinsser

To help prevent bugs, concurrency should only be used when needed. When it is needed, the design and implementation should be handled carefully.

Sometimes problems are poorly understood until a solution is implemented and found lacking. For this reason, it’s often best to implement a basic solution before attempting a more complete and complicated one. Adequate solution are usually less costly than optimal ones.

I’ve worked with many developers who didn’t seem to grasp the incredible speed at which program instructions execute. They worried about things that would have a tiny effect on performance or efficiency. They should have been worried about bug prevention and better-written code.

Most sponsors would rather have a stable program delivered on-time than a slightly faster and more efficient program delivered late.

It’s better to implement features directly and clearly, then optimize any that affect users negatively.

Efficiency and performance are only problems if the requirements haven’t been met. Optimization usually reduces source code clarity, so it isn’t justified for small gains in efficiency or performance. Our first priorities should be correctness, clarity, and modest flexibility.

Implementation is necessarily incremental, but a good architecture is usually holistic. It requires a thorough understanding of all requirements.

Buy the Book

If you are interested in purchasing Timeless Laws of Software Development, you can support the website by using our Amazon affiliate link:

 

 

A Poem on Transformation: Ode to the Drum

Gazelle, I killed you  
for your skin's exquisite  
touch, for how easy it is  
to be nailed to a board  
weathered raw as white  
butcher paper. Last night  
I heard my daughter praying  
for the meat here at my feet.  
You know it wasn't anger  
that made me stop my heart  
till the hammer fell. Weeks  
ago, I broke you as a woman  
once shattered me into a song  
beneath her weight, before  
you slouched into that  
grassy hush. But now  
I'm tightening lashes,  
shaping hide as if around  
a ribcage, stretched  
like five bowstrings.  
Ghosts cannot slip back  
inside the body's drum.  
You've been seasoned  
by wind, dusk & sunlight.  
Pressure can make everything  
whole again, brass nails  
tacked into the ebony wood  
your face has been carved  
five times. I have to drive  
trouble from the valley.  
Trouble in the hills.  
Trouble on the river  
too. There's no kola nut,  
palm wine, fish, salt,  
or calabash. Kadoom.  
Kadoom. Kadoom. Ka-  
doooom. Kadoom. Now  
I have beaten a song back into you,  
rise & walk away like a panther.

by Yusef Komunyakaa

Hear Yusef Read His Poem

Source

“Ode to the Drum” can be found in Thieves of Paradise.

Deep Nutrition

Author: Catherine Shanahan
Rating: 10/10
Last Read: July 2018

Deep Nutrition is a book which explains the negative effects that our modern diets are having on our bodies. Dr. Shanahan provides background and reasoning for the traditional “human diet”, which is as close as we can get to the way our great-great-great grandparents ate. She explains why the traditional diet is essential and walks through the damage that vegetable oils and sugars are causing. She also discusses the modern diet’s impact on fetal/childhood development and modern diseases.

Much of the book is dedicated to the link between our nutrition and our health, as well as making the argument that the modern diet of highly processed foods is harming us and destroying our genetic momentum. The book also contains recipes, meal planning guides, and a FAQ section to help you transition as easily as possible.

We completely changed our eating habits as a result of reading Deep Nutrition, and we have never felt better. We’ve replaced all of our cooking oils and condiments, reduced our carb intake to < 50g on most days, started fermenting food, improved the quality of our food purchases, and started eating in a more nose-to-tail style. We’ve also found ourselves less interested in eating out at restaurants, especially since most of them use cheap and highly processed cooking oils (canola, cottonseed, soy, corn, safflower, etc.).

I can’t deny it. We are believers.

My Highlights

I am still working on processing our book highlights. We thought this book was so important that we needed to share our recommendation right away.

Buy the Book

If you are interested in purchasing this book, you can support the website by using our Amazon affiliate link.

 

 

Chuang-tzu’s Parable of the Ox

Prince Wen Hui’s cook
Was cutting up an ox.
Out went a hand,
Down went a shoulder,
He planted a foot,
He pressed with a knee,
The ox fell apart
With a whisper;
The bright cleaver murmured
Like a gentle wind.
Rhythm! Timing!
Like a sacred dance,
Like “The Mulberry Grove,”
Like ancient harmonies!
“Good work!” the Prince exclaimed.
“Your method is faultless!”
“Method?” said the cook,
Laying aside his cleaver.
“What I follow is Tao,
Beyond all methods!

“When I first began
To cut up oxen
I would see before me
The whole ox,
All in one mass.

“After three years,
I no longer saw this mass.
I saw the distinctions.

“But now, I see nothing
With the eye. My whole being
Apprehends.
My senses are idle. The spirit,
Free to work without plan,
Follows its own instinct,
Guided by natural line.
By the secret opening, the hidden space,
My cleaver finds its own way.
I cut through no joint, chop no bone.

“A good cook needs a new chopper
Once a year – he cuts.
A poor cook needs a new one
Every month – he hacks!

“I have used this same cleaver
Nineteen years.
It has cut up
A thousand oxen.
Its edge is as keen
As if newly sharpened.

“There are spaces in the joints;
The blade is thin and keen.
When this thinness
Finds that space,
There is all the room you need!
It goes like a breeze!
Hence I have this cleaver nineteen years,
As if newly sharpened!

“True, there are sometimes
Tough joints, I feel them coming,
I slow down, I watch closely,
Hold back, barely move the blade,
And whump! The part falls away
Landing like a clod of earth.

“Then I withdraw the blade.
I stand still
And let the joy of the work
Sink in.
I clean the blade
And put it away.”

Prince Wen Hui said,
“This is it! My cook has shown me
How I ought to live
My own life!”

Translated by Thomas Merton

Death Poem of Uesugi Kenshin

Even a life-long prosperity is but one cup of sake;
A life of forty-nine years is passed in a dream;
I know not what life is, nor death.
Year in year out-all but a dream.
Both Heaven and Hell are left behind;
I stand in the moonlit dawn,
Free from clouds of attachment.

Uesugi Kenshin
1530-1578

Source

This poem comes from the Samurai Archives.

More Japanese Death Poems

Interested in Japanese death poems? Check out Japanese Death Poems: Written by Zen Monks and Haiku Poets on the Verge of Death.

 

 

The Martian

Author: Andy Weir
Rating: 7/10
Last Read: October 2015

The Martian is a relatively well-known book about an astronaut who is abandoned on Mars after his companions thought he was dead. He tries to stay alive and establish contact with Earth, hoping they can figure out how to get him back home. The novel is told from the point of view of multiple characters, but focuses primarily on the astronaut and his struggle to live.

I enjoyed The Martian and thought it was a decent sci-fi novel. The book is clearly targeted at engineers, so the details and explanations and jokes are perhaps nerdier than other sci-fi novels.

My Highlights

Chuck shrugged. “Never occurred to us. We never thought someone would be on Mars without an MAV.”
“I mean, come on!” Morris said. “What are the odds?”
Chuck turned to him. “One in three, based on empirical data. That’s pretty bad if you think about it.”

“How’d I do today?” Venkat asked.
“Eeeh,” Annie said, putting her phone away. “You shouldn’t say things like ‘bring him home alive.’ It reminds people he might die.”
“Think they’re going to forget that?”
“You asked my opinion. Don’t like it? Go fuck yourself.”
“You’re such a delicate flower, Annie. How’d you end up NASA’s director of media relations?”
“Beats the fuck out of me,” Annie said.

Irene carefully formed her answer before speaking. “When facing death, people want to be heard. They don’t want to die alone. He might just want the MAV radio so he can talk to another soul before he dies.”

“Jesus, what a complicated process,” Venkat said.
“Try updating a Linux server sometime,” Jack said.
After a moment of silence, Tim said, “You know he was telling a joke, right? That was supposed to be funny.”
“Oh,” said Venkat. “I’m a physics guy, not a computer guy.”
“He’s not funny to computer guys, either.”

I started the day with some nothin’ tea. Nothin’ tea is easy to make. First, get some hot water, then add nothin’. I experimented with potato skin tea a few weeks ago. The less said about that the better.

Buy the Book

If you are interested in purchasing this book, you can support the website by using our Amazon affiliate link:

 

The Martian

By Andy Weir

 

Death Poem of Tokugawa Ieyasu

Whether one passes on or remains is all the same.
That you can take no one with you is the only difference.
Ah, how pleasant! Two awakenings and one sleep.
This dream of a fleeing world! The roseate hues of early dawn!

Tokugawa Ieyasu
1542-1616

Source

This poem comes from the Samurai Archives.

More Death Poems

Interested in Japanese death poems? You can find more in Japanese Death Poems: Written by Zen Monks and Haiku Poets on the Verge of Death.