What is code bloat?
Code bloat is code that is purportedly too long or too slow on most computer systems. While the term usually refers to source code that is too long, it can also refer to executable files that are considered to be excessively large.
The causes of the perceived code bloat could lead to the use of object-oriented programming techniques, where procedural techniques would make inappropriate use of design patterns, declarative programming, and looping. Bloat solutions can include refactoring and eliminating redundant computations.
Code bloat is a problem in software development where the length of the source code is assumed to be too long. The term usually refers to the length of the source code itself, but it can also be applied to the size of the executable files generated by a compiler when using a compiled language such as C.
Code bloat is often in the eye of the beholder, but it can cause real problems. Long, obscure code can be difficult to read and maintain. Programs that are too large run slowly.
Code bloat can be caused by inadequate language capabilities resulting in exaggerated code, use of object-oriented design principles where they are not needed, and use of design patterns that are inappropriate for the problem being solved. Using declarative programming techniques that guarantee object-oriented or imperative techniques can also make the code too large. Loop-unwinding, which reduces instructions controlled by a loop, is a programming technique that can speed up execution while causing code bloat.
Fortunately, there are solutions to code bloat. The first is to avoid them by using minimalist programming techniques, perhaps with software methods like agile programming. The other is careful refactoring, which changes a program's source code while keeping its external functionality intact. Another good option is software reuse by simply programming libraries.