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 ana ...
, 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 Software is a set of computer programs and associated documentation and data. This is in contrast to hardware, from which the system is built and which actually performs the work. At the lowest programming level, executable code consists ...
projects often expressing a special feature of a recurring
construct Construct, Constructs or constructs may refer to: * Construct (information technology), a collection of logic components forming an interactive agent or environment ** Language construct * ''Construct'' (album), a 2013 album by Dark Tranquillity ...
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 materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
. Developers recognize programming idioms by associating and giving meaning (semantic role) to one or more syntactical expressions within
code snippet Snippet is a programming term for a small region of re-usable source code, machine code, or text. Ordinarily, these are formally defined operative units to incorporate into larger programming modules. Snippet management is a feature of some text ...
s (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 Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
, or
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
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 organis ...
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 Fluency (also called volubility and eloquency) is the property of a person or of a system that delivers information quickly and with expertise. Language use Language fluency is one of a variety of terms used to characterize or measure a person ...
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 ...
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 wa ...
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 List ...
: 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 Website, websites use JavaScript on the Client (computing), client side ...
: 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 offici ...
: 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 Embedded SQL is a method of combining the computing power of a programming language and the database Data Manipulation Language, manipulation capabilities of SQL. Embedded SQL statement (programming), statements are SQL statements written inline wi ...
(kind of "standard idiom" to use in any language) *
Idiom An idiom is a phrase or expression that typically presents a figurative, non-literal meaning attached to the phrase; but some phrases become figurative idioms while retaining the literal meaning of the phrase. Categorized as formulaic language, ...


References


External links


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