Jump to content

Softcoding

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Robbak (talk | contribs) at 07:08, 28 May 2009 (Correcting 'magic numbers' link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Softcoding is a computer coding term that means abstracting a value or function into a container that is controllable external to the main function, like a configuration file, database table, or external registry. The term was coined as the opposite of the existing term, Hardcoding.

Avoiding hard-coding of commonly altered values is a good programming practice. Users of the software should be able to customize it to their needs, within reason, without having to edit the program's source code. Similarly, careful programmers avoid Magic Numbers in their code, to improve its readability, and assist maintenance. These practice are generally not referred to as 'softcoding'.

The term is generally used where Softcoding becomes an anti-pattern. Abstracting too many values and features can introduce more complexity and maintenance issues than would be experienced with changing the code when required. Softcoding, in this sense, was featured in an article on The Daily WTF.[1].

At the extreme end, soft-coded programs develop their own poorly-designed and implemented scripting languages, and configuration files that require advanced programming skills to edit. This can lead to the production of utilities to assist in configuring the original program, and these utilities often end up being 'softcoded' themselves.

To avoid 'softcoding', consider the value to the end user of any additional flexibility you provide, and compare it with the increased complexity and related ongoing maintenance costs the added configurability involves.

In feature design, softcoding has other meanings.

  • Hardcoding: feature is coded to the system not allowing for configuration
  • Parametric: feature is configurable via table driven, or properties files with limited parametric values
  • Softcoding: feature uses “engines” that derive results based on any number of parametric values (i.e. business rules in BRE); rules are coded but exist as parameters in system,written in script form

References