Software Development Resources
Create account | Log in | Log in with OpenID | Help

Code bloat

From DocForge

Code bloat is the concept of excessive source code and computer instructions. Code is generally deemed bloated when it is unnecessarily long or wastes resources.

When a system is limited in resources efficient use of those resources is a high priority. As system resources grow larger, the problem of code bloat is often considered less of a priority. For example, as hard disks grow larger and cheaper and processors get faster there is less incentive to remove unnecessary files and computing cycles. Over time, however, there can be negative repercussions, such as complicating maintenance and a lack of portability.

[edit] Examples

Code bloat is somewhat subjective, as each person might have a different opinion on what is excessive. There are a wide variety of common examples of code bloat:

  • Operating systems with excessive or unused libraries or other binaries; for example:
    • Some hardware vendors place applications on their systems for marketing or financial purposes without asking the end user. This can leave applications installed or running on a computer regardless of the desire of the user, wasting storage space and CPU cycles. The end user must then take actions to remove the bloat.
    • An operating system may be distributed with executables for every supported CPU, as opposed to a separate distribution for each. This simplifies distribution for both the producer and user, but leaves large amounts of unused code on the computer.
    • When installing printer drivers from Hewlett Packard on Mac OS X, unnecessary applications are left running in the background, providing no features over the operating system's management of the drivers and the printer. Leaving the operating system alone to manage the printing system would remove bloat.
  • Multiple duplicate drivers which effectively overlap, such as a PHP's 3 extensions for connecting to a MySQL database
  • Programming with excessive, unnecessary use of object-oriented structures
  • Sub-optimal compiler optimizations

[edit] Causes

Some causes of code bloat are inherent in the design or desired functionality of a system.

  • Backwards compatibility - continued support of legacy software often requires libraries or runtime environments to linger within a system, eventually going unused.
  • As programming languages become more generalized and abstracted from machine code it becomes more difficult for compilers and runtimes to be programmed to be efficient. Generally, the more specialized a system the more optimized each component and tool can be made. It also requires more education for a programmer to know how to optimally design their code so it correlates with compiler and runtime optimizations.
  • Use of system abstractions, such as virtual machines

Other causes are lack of education or insight on the part of the developer.

  • Misuse or overuse of design patterns - following best practices is obviously positive, but some design patterns are excessive in certain situations, or can be used for the wrong reasons
  • A "copy-and-paste" mentality by a programmer, instead of following the best practices of code reuse
  • Lack of flexibility in programming paradigms; for example, a developer only familiar with object-oriented programming may try to solve every problem with objects, which can create unnecessary overhead or extra code in some situations.

[edit] Cures

The solutions to code bloat are very dependent on the system.

  • During initial design and development, plan for code reuse, creating new libraries or using others as needed. Assume that some components of new software might be useful to other systems later, and therefore can be modularized from the start.
  • Following initial development, refactoring of code is usually a good solution when the problem is contained within one isolated system or component. For example, take separate code with identical functionality and combine them into one routine.
  • Dropping support for legacy software, while not always possible, will often allow the removal of old code from underlying systems.
  • Building software for its most specific use using the most efficient tools will help prevent code bloat. This choice is sometimes a trade-off with features and portability. For example, cross-platform software will often require code specific to each platform.

Discuss