written by owen on 2005-Jan-26.
It is important to understand why some programmers write code differently from other programmers and the reasoning behind each block or section of code. This article is not directed at any particular language or style of programming, it is a discussion of the differences computer code which is written to solve various problems. The patterns may overlap but nothing is ever defined specifically and are to be considered as a general overview.
At some point code may be written in order to reduce errors that may arise at a later point in time. In a computer program an error can arise at any point, in any time and for any random reason. In order to reduce the effects of such an occurrence some parts of a program might be written in order to reduce or eliminate such errors or reduce its effects on the rest of the system.
The code is written so that it is easy to read by anybody that may happen to decide to read/maintain it at some point in the future. Sometimes also referred to as clean code. However, clean code is also relative to the experience of the reader and clean code is analogous with code that is well written.
The code is written so that it can make the best use of computer resources. This does not necessarily mean it is fast, easy to read or reduces possible errors. But at that point in time being efficient is paramount to the success of the rest of the system.
Falls under 2 forms speed of execution and speed of development. Speed of execution involves writing the program(or parts there of) so that it can run as fast as possible in the expected operating environment. Speed of development means it is written so the application can evolve or change at a high rate. There often is a balance between these 2 things.
The code is written so that it is simple. Simplicity is relative but usually it spreads rapidly. Simple to read, update, integrate, extend etc.
The code is written so that it does not crash easily either by internal or external forces. Usually maximizing scalability and robustness. Minimizing edge cases.
The code is written so that it can not only be used to solve the current problem but many future problems as well.
Code usually falls into 2 forms programmer friendly and user friendly. The first form is code written in order to make it easier to re-write or update. While the second form is directed towards code written in order to improve user interface efficiency. Code can also be language friendly, hardware friendly, etc.
Often times code is written so that it is very dependent or very independent for whatever reason. (Update 2014: industrialization )
The patterns outlined are usually mutually exclusive and it is often hard to maintain a any throughout an application (without falling into a trap). For example the more efficient your code the harder it will be to read. As to whether a pattern is more advantageous than another is dependent on the situation. One has to be able to recognize (at a macro level) what code warrants a certain approach.