Code bloat can also be caused by inadequacies in the language in which the code is written, or inadequacies in the compiler used to compile the language. An example of this are some naïve implementations of the template system employed in C++. A naïve compiler implementing this feature can introduce versions of a templated function for every type it is used with. This in turns leads to compiled functions that may never be used, thus resulting in code bloat. More sophisticated compilers and linkers detect the superfluous copies and discard them, reducing the bloat. Thus template code can result in smaller binaries because a compiler is allowed to discard dead code.
Some examples of code bloat produced by naïve compilers include:
The difference in code density between various languages is so great that often less memory is needed to hold both a program written in a "compact" language (such as a domain-specific programming language, Microsoft P-Code, or threaded code), plus an interpreter for that compact language (written in native code), than to hold that program written directly in native code.
In many cases, when two programs implement the same functionality, the larger program will also run slower than the smaller program. There are a few cases where there is a space-time tradeoff -- in those cases, a larger program runs faster than a smaller program.
Some techniques for reducing code bloat include: