HOME

TheInfoList



OR:

In computer programming, a programming idiom or code idiom is a group of
code In communications and information processing, code is a system of rules to convert information—such as a letter, word, sound, image, or gesture—into another form, sometimes shortened or secret, for communication through a communication ...
fragments sharing an equivalent semantic role, which recurs frequently across software projects often expressing a special feature of a recurring construct in one or more programming languages or libraries. Developers recognize programming idioms by associating and giving meaning (semantic role) to one or more syntactical expressions within code snippets (code fragments). The idiom can be seen as a concept underlying a pattern in code, which is represented in implementation by contiguous or scattered code fragments. These fragments are available in several programming languages,
framework A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of. Framework may refer to: Computing * Application framework, used to implement the structure of an application for an op ...
s or even libraries. Generally speaking, a programming idiom's semantic role is a natural language expression of a simple task,
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
, or data structure that is not a
built-in Built-in, builtin, or built in may refer to: Computing * Shell builtin, a command or a function executed directly in the shell itself * Builtin function, in computer software and compiler theory Other uses * Built-in behavior, of a living organ ...
feature in the programming language being used, or, conversely, the use of an unusual or notable feature that ''is'' built into a programming language. Knowing the idioms associated with a programming language and how to use them is an important part of gaining fluency in that language, and transferring knowledge in the form of analogies from one language or framework to another. A common misconception is to use the
adverb An adverb is a word or an expression that generally modifies a verb, adjective, another adverb, determiner, clause, preposition, or sentence. Adverbs typically express manner, place, time, frequency, degree, level of certainty, etc., answering que ...
ial or adjectival use of the term as ''using a programming language in a typical way'', which really refers to idiosyncratic. For example, an idiosyncratic way to manage dynamic memory in C would be to use the
C standard library The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it was ...
functions ''malloc'' and ''free'', whereas idiomatic refers to dynamic memory allocation as recurring semantic role that can be achieved with code fragments ''malloc'' in C, or ''pointer = new type umber_of_elements' in C++. Common to both is that the code fragments are intelligible to somebody unfamiliar with C or C++, unless the code rationale is exposed to the developer.


Examples of simple idioms


Printing Hello World

One of the most common starting points to learn to program or notice the syntax differences between a known language and a new one. It has several implementations, among them the code fragments for
C++ C, or c, is the third letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''cee'' (pronounced ), plural ''cees''. History "C" ...
: std::cout << "Hello World\n"; For Java: System.out.println("Hello World");


Inserting an element in an array

This idiom helps developers understand how to manipulate collections in a given language, particularly inserting an element x at a position i in a list s and moving the elements to its right. Code fragments: For
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pr ...
: s.insert(i, x) For JavaScript: s.splice(i, 0, x); For Perl: splice(@s, $i, 0, $x)


See also

*
Algorithmic skeleton In computing, algorithmic skeletons, or parallelism patterns, are a high-level parallel programming model for parallel and distributed computing. Algorithmic skeletons take advantage of common programming patterns to hide the complexity of paral ...
* Embedded SQL (kind of "standard idiom" to use in any language) * Idiom


References


External links


programming-idioms.org
shows short idioms implementations in most mainstream languages.
C++ programming idioms
from Wikibooks. {{DEFAULTSORT:Programming Idiom