From Esolang
Jump to: navigation, search

A nop (sometimes spelled no-op or noop) is an operation in a programming language that does nothing.

While nops are generally useless in most "serious" programming languages (except very low-level ones like machine language, where they can affect timing), they can come in very valuable in esoteric programming languages, often to allow an arbitrary effect at an arbitrary point.

For example, SMITH can only simulate loops by copying code forward, so nops can come in handy as padding. Many character-based languages, such as Brainfuck, consider unrecognized characters to be nops, which allows them to be used for comments (though in this case, they could just as well be considered as whitespace).

Nops are also indispensable in many two-dimensional languages, also as padding; some sort of padding is needed in many programs in order to cause the rows of the program to line up correctly (or the columns, depending on how you look at it). Two-dimensional languages typically consider spaces and any printable characters not otherwise defined to be nops. Exceptions include ADJUST, which has no valid nop instruction, and 1L_a, which has a nop instruction only when travelling rightwards or downwards.

In multithreaded languages, especially those that work in terms of program counters taking turns, nops are useful for timing purposes.

The term nop is also used to refer to any sequence of operations that, taken together, do nothing; for example, the sequence +- in Brainfuck. <> is usually a nop in Brainfuck, but would be illegal if the data pointer is on the first memory cell; similarly, +- would be illegal in an 8-bit non-wrapping implementation that forbids incrementing 255, if the current cell is 255.

See also