Friday, May 15, 2015

Scientific Method as a Software Development Methodology

Many different software development methodologies have been created over the years. Most of them work fairly well. But they all really kind of derive from the Scientific Method.

The scientific method is roughly as follows:
1) Ask a question.
2) Gather information about the question.
3) Create a hypothesis that explains the observations.
4) Test the hypothesis through experimentation and then refine and retest it.
5) Publish the results.
6) Continue to test the results and refine the hypothesis incorporating external input.

In software we have a method that is often referred to as code and fix.

If you look at the scientific method it would be more or less.

1) Ask a question.
2) Create a hypothesis.
5) Publish the results.
6) Refine the hypothesis incorporating external input.

Which kind of works but is frankly an insult to anyone using the software. In a lot of ways it is a lot like religious dogma. Except that in religion refinement based on external input is almost never done or if it is the step of gathering information and testing the hypothesis are steps that tend to be skipped.

Getting back to the scientific method as applied to software.

All reasonable processes have ideas like stating the problem, gathering requirements, creating a specification, testing, documentation, and finally publication followed by iterative refinement.

Most software usability and other issues are caused by not spending enough time observing and testing. And often publication is done in a hurry, which also occurs in the scientific community as well, but less often due to the stigma of publishing something that is subsequently shown to be incorrect.

In software the rigor that is often associated with the scientific method tends to be fairly rare. There is a pressure to perform. Not many years ago there was the idea of "Internet Time" which led to a plethora of buggy software. Getting your software to market before anyone else has been something that many companies embraced as the best way to succeed.

However, over time we have observed that fast an speedy doesn't always win. The tortoise and hare children's story is a classic example of how this lesson was learned, repeated, and well know. However, there still remains a segment of society that embraces the idea that being fast at the start is the way to win.

Long term we find that software companies that embrace quality and continuous rigorous improvement of quality win in the long term. This is a common theme in successful businesses as well.

In the end we don't need some new software development process. Every one of the good software development methods are really just an application of the scientific method with a lot special words attached that tend to disguise the underlying methodology in an effort to make it seem new and different.

Tuesday, March 3, 2015

Zero Defects is Possible in Software

I make the claim in the title for two reasons. First, it sound's like an arrogant and unreasonable viewpoint. Which is more to draw you in than for any other reason.

More importantly my reason is that if you don't believe that you can write defect free code you will never be able to.

Let us start with understanding some ground rules of my claim.
  • There is an implicit assumption that the computer you are running on is not subject to an out of spec environment, such as excessive heat or solar flares and that all the hardware is functioning properly.
  • Second there is an assumption that the operating system is bug free with respect to the code you are writing.
  • Further, it is assumed that the compiler you are using generated correct bug free code with respect to the software you are writing.
It is clear that in some cases the above may not be true. Which results in a quality ceiling that is potentially out of your control. However, given a take no prisoners approach to bug fixing at the level of the compiler and the OS, there is no reason that the second two conditions need to exist. Plus there are plenty of cases where as far as your software is concerned there are no bugs at those levels to deal with.

When you write code you will almost certainly introduce bugs. Occasionally, I write a small amount of code that is bug free. Just as you can type words that are spelled correctly that form grammatically correct sentences it is possible to write multiple lines of code that are bug free without modification.

Take this with an aggressive stance on bug fixing and testing and you should be able to write small  amounts of code that are bug free after only a few iterations.

An approach that I find that works is to fix every bug in code that I'm designing from scratch. The quicker I do this the faster the code becomes solid. It can be harder if you are a maintainer of code to do this as it means that you need to understand both what the code is doing and what the writer of the code intended. It is very difficult to determine intent if you don't have written requirements.

Written requirements are sometimes hard because they often change as you write code. This is due to the discovery process inherent in writing code to solve a problem that you don't fully understand at the start. It can be hard to develop the discipline to update requirements as they change over time. Creating a process with independent testing can help to make this happen. Even so some things will likely fall through the cracks.

The good news though is that even though not having a requirement makes determining the intent of the writer of the code hard to determine, it is often possible to determine based on how the code is used and using engineering judgment.

But, our goal is to leave the software we write in a bug free state when it is complete and for whatever reasons we move on to something new and leave the maintenance to someone else. If this happens the maintainers job is an easy one as they should never need to update the software because it just plain works.

More than likely if the software needs to be updated it would be to extend functionality which builds on the already solid core, which makes the maintainers job a lot easier.

At this point I imagine that you are probably still not convinced that it is possible to write bug free software.

If you can't believe that you can write bug free software you never will.

Unfortunately, I cannot lay claim to having zero defects in all the software I have written. But I can claim that some of the software I have written has zero defects and that over the years I have gotten better at writing software with zero defects.

Obviously, some things cannot be fixed quickly, or are inherited from the underlying system. While this is unfortunate, at the very least one can document that the defect exists so that a user of your software can make an informed decision about how to handle the problem.

This probably sounds overly idealistic. But there are things that over the years have led to countless problems in software.

In the end while I don't expect that you or I will deliver all software with zero defects. I do think that we can deliver some software with zero defects and for the software that has defects we can continue to fix the problems as they are discovered and with time iterate it to zero defects.

The problem with a less idealistic approach is that it leads inexorably to a point where you are spending all of your time fixing bugs in old code you wrote and not fixing bugs in new code. Bug debt or technical debt of this sort has a compounding effect which can only be corrected by either paying down the debt or by declaring technical bankruptcy and abandoning the debt laden code.

I hope that this inspires you to at least improve the quality of the code you write.



Technical Bankruptcy

Technical debt or bug debt is an insidious side effect of writing low quality code.

The technical debt that one engineer can accumulate in a career of programing can easily require 2 or more careers of other engineers to pay down.

A pay as you go policy says that you fix all bugs as they are discovered before writing new code. While this lowers your productivity initially. It helps you to develop better habits that introduce bugs at a lower rate. Plus it makes your software more appealing to customers.

All things being equal customers will pick the higher quality software over lower quality software. Which means higher sales. More sales may allow you to under cut your competition by dropping your price leading to more sales. Or you could say that our software is better so we charge more. This can also potentially have a positive impact on sales because people often do believe that higher prices correlate to better quality.

When you have more money coming in you can hire more and better engineers to write more high quality software.

If you go the other way and cut quality in an effort to reduce the time to market, which only really works when you are near the end of a development cycle. You negatively impact your income, assuming you have the competition of better software. In any case if you are the only producer of some software and it is profitable you will eventually find that someone will start competing based on quality.

At some point bad software can get so bad that one should consider declaring personal technical bankruptcy and move on. This may be a job change or if you are lucky only the cancellation of your project.