Programming by permutation

Programming by permutation

Trying to approach a solution to a programming problem by iteratively making small changes (permutations) and testing each change to see if it behaves as expected is called "programming by permutation". This approach sometimes seems attractive when the programmer does not fully understand the code, and believes that one or more small modifications may result in code that is correct.

This tactic is rarely productive because:
* a series of small modifications can easily introduce bugs into the code, leading to a "solution" that is even less correct than the starting point
* many false starts and corrections usually occur before a satisfactory endpoint is reached
* it is rarely possible to measure, by empirical testing, whether the solution will work for all cases
* in the worst case, with poor code management, the original state of the code may be irretrievably lost

Programming by permutation gives little or no assurance about the quality of the code produced -- it is the polar opposite of Formal verification.

Programmers are often compelled to program by permutation when an API is insufficiently documented. This lack of clarity drives others to copy and paste from reference code which is assumed to be correct, but was itself written as a result of programming by permutation.

In some cases where the programmer can logically explain that exactly one out of a small set of variations must work programming by permutation leads to correct code (which then can be verified) and makes it unnecessary to think about the other (wrong) variations.

Example

For example, the following code sample in C (intended to find and copy a series of digits from a larger string) has several problems:

char* buffer = "123abc";char destination [10] ; int i = 0;int j = 0;int l = strlen(buffer);

while (i < l){ if (isdigit(buffer [i] )) destination [j++] = buffer [i++] ; i++;}

destination [j] = '


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Permutation — For other uses, see Permutation (disambiguation). The 6 permutations of 3 balls In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging) objects or values.… …   Wikipedia

  • Concatenative programming language — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurr …   Wikipedia

  • Generic programming — is a style of computer programming in which algorithms are written in terms of to be specified later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983. This… …   Wikipedia

  • Dynamic programming — For the programming paradigm, see Dynamic programming language. In mathematics and computer science, dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems. It is applicable to problems… …   Wikipedia

  • APL (programming language) — APL Paradigm(s) array, functional, structured, modular Appeared in 1964 Designed by Kenneth E. Iverson Developer Kenneth E. Iverson …   Wikipedia

  • Monad (functional programming) — In functional programming, a monad is a programming structure that represents computations. Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model. A defined monad allows the… …   Wikipedia

  • The Art of Computer Programming — [ [http://www cs faculty.stanford.edu/ uno/taocp.html The Art of Computer Programming ] ] is a comprehensive monograph written by Donald Knuth that covers many kinds of programming algorithms and their analysis. Knuth began the project, which was …   Wikipedia

  • Anti-pattern — For the book, see AntiPatterns. In software engineering, an anti pattern (or antipattern) is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.[1][2] The term was coined in 1995 by Andrew Koenig,[3]… …   Wikipedia

  • Antipatrón de diseño — Saltar a navegación, búsqueda Un antipatrón de diseño es un patrón de diseño que invariablemente conduce a una mala solución para un problema. Al documentarse los antipatrones, además de los patrones de diseño, se dan argumentos a los diseñadores …   Wikipedia Español

  • Fisher-Yates shuffle — The Fisher Yates shuffle, named after Ronald Fisher and Frank Yates, also known as the Knuth shuffle, after Donald Knuth, is an algorithm for generating a random permutation of a finite set in plain terms, for randomly shuffling the set. A… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”