HOME

TheInfoList



OR:

In
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
, a programming idiom or code idiom is a group of code fragments sharing an equivalent semantic role, which recurs frequently across
software Software is a set of computer programs and associated software documentation, documentation and data (computing), data. This is in contrast to Computer hardware, hardware, from which the system is built and which actually performs the work. ...
projects often expressing a special feature of a recurring construct in one or more
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s or
libraries A library is a collection of Document, materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or electronic media, digital access (soft copies) materials, and may be a ...
. 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, frameworks 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 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 adverbial 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 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++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
: std::cout << "Hello World\n"; For
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
: 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 (pro ...
: s.insert(i, x) For
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
: s.splice(i, 0, x); For
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
: 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 parall ...
* 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