Code bloat


In computer programming, code bloat is the production of program code that is perceived as unnecessarily long, slow, or otherwise wasteful of resources. Code bloat can be caused by inadequacies in the programming language in which the code is written, the compiler used to compile it, or the programmer writing it. Thus, while code bloat generally refers to source code size, it can be used to refer instead to the generated code size or even the binary file size.

Examples

The following JavaScript algorithm has a large number of redundant variables, unnecessary logic and inefficient string concatenation.

// Complex
function TK2getImageHTML ;

The same logic can be stated more efficiently as follows:

// Simplified
const TK2getImageHTML = => ;

Code density of different languages

The difference in code density between various computer languages is so great that often less memory is needed to hold both a program written in a "compact" language, plus an interpreter for that compact language, than to hold that program written directly in native code.

Reducing bloat

Some techniques for reducing code bloat include: