# Java: Complexity is your enemy

## Complexity is to software as Heat is to Chips

Much of programming is about reducing software complexity. Entire software movements such as structured programming and object-oriented programming can be viewed as techniques to control complexity.

Complexity can be seen as similar to the problem of heat in integrated circuits. Limits on what are practical are imposed by certain constraints -- typically heat in an integrated circuit, and complexity in a program. Exceed those limits and the the component will fail. The complexity issue isn't one of physics however - it's about about human brains.

## Complexity and the human brain

Complexity is not about how well programs run on a machine, but about how well humans can read and understand a program. The machine has no problems with complexity -- the CPU dumbly picks up the next instruction and does what that instruction says. Then the next instruction, etc. The CPU never needs to understand what the program does, humans do.

The sad fact is that human minds are limited in their ability to deal with complexity. Everyone loves to quote Miller's Law: A person can only keep 7 plus or minus 2 items in mind at one time. It isn't much to base programming design on, but it supports the idea that there are real mental limits. Why can't we keep 100 things in short term memory, or 100,000?

You will discover, if you haven't already, that there are large differences in the ability of different programmers to deal with complexity. I certainly don't rank at the top in being able to deal with complexity, but I've worked with programmers who could juggle an amazing number of items at the same time. My "weakness" has forced me to produce simpler designs because I don't have a choice. The result, curiously, has often lead to better programs. Simpler is better, but as Albert Einstein said, "Make things as simple as possible -- but no simpler".

This constant battle against complexity takes place at every level, from choosing a variable name to organizing a large number of cooperating classes. Many of the best programming practices are directly aimed at controlling complexity.