Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Programming idiom

From Wikipedia, the free encyclopedia
Group of code fragments sharing an equivalent semantic role

Incomputer programming, aprogramming idiom,code idiom or simplyidiom is acode fragment having asemantic role[1] which recurs frequently acrosssoftware projects. It often expresses a special feature of a recurringconstruct in one or moreprogramming languages,frameworks orlibraries. This definition is rooted in the linguistic definition of "idiom".

The idiom can be seen bydevelopers as an action on a programming concept underlying a pattern in code, which is represented in implementation by contiguous or scatteredcode snippets. Generally speaking, a programming idiom's semantic role is anatural language expression of a simple task,algorithm, ordata structure that is not abuilt-in feature in the programming language being used, or, conversely, the use of an unusual or notable feature thatis built into a programming language.

Knowing the idioms associated with a programming language and how to use them is an important part of gainingfluency in that language. It also helps to transfer knowledge in the form of analogies from one language or framework to another. Such idiomatic knowledge is widely used incrowdsourced repositories to help developers overcome programming barriers.[2]

Mapping code idioms toidiosyncrasies can be a helpful way to navigate the tradeoffs between generalization and specificity. By identifying common patterns and idioms, developers can create mental models and schemata that help them quickly understand and navigate new code. Furthermore, by mapping these idioms to idiosyncrasies and specific use cases, developers can ensure that they are applying the correct approach and not overgeneralizing it. One way to do this is by creating a reference or documentation that maps common idioms to specific use cases, highlighting where they may need to be adapted or modified to fit a particular project or development team. This can help ensure that developers are working with a shared understanding of best practices and can make informed decisions about when to use established idioms and when to adapt them to fit their specific needs.

A common misconception is to use theadverbial oradjectival form of the term as "using a programming language in a typical way", which really refers to a idiosyncrasy. An idiom implies the semantics of some code in a programming language has similarities to other languages or frameworks. For example, anidiosyncratic way tomanage dynamic memory inC would be to use theC standard library functionsmalloc andfree, whereasidiomatic refers to manualmemory management as recurring semantic role that can be achieved with code fragmentsmalloc in C, orpointer = new type [number_of_elements] in C++. In both cases, the semantics of the code are intelligible to developers familiar with C or C++, once the idiomatic or idiosyncratic rationale is exposed to them. However, while idiomatic rationale is often general to the programming domain, idiosyncratic rationale is frequently tied to specific API terminology.

Examples

[edit]

Printing Hello World

[edit]
Main article:"Hello, World!" program

One of the most common starting points to learn to program or notice the syntax differences between a known language and a new one.[3]

It has several implementations, among them the code fragments forC++:

std::cout<<"Hello World\n";

ForJava:

System.out.println("Hello World");

Inserting an element in an array

[edit]

This idiom helps developers understand how to manipulate collections in a given language, particularly inserting an elementx at a positioni in a lists and moving the elements to its right.[4]

Code fragments:

ForPython:

s.insert(i,x)

ForJavaScript:

s.splice(i,0,x);

ForPerl:

splice(@s,$i,0,$x)

See also

[edit]

References

[edit]
  1. ^Allamanis, Miltiadis; Sutton, Charles (2014). "Mining idioms from source code".Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering. pp. 472–483.arXiv:1404.0417.doi:10.1145/2635868.2635901.ISBN 9781450330565.S2CID 2923536.
  2. ^Samudio, David I.; Latoza, Thomas D. (2022)."Barriers in Front-End Web Development"(PDF).2022 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC). pp. 1–11.doi:10.1109/VL/HCC53370.2022.9833127.ISBN 978-1-6654-4214-5.S2CID 251657931.
  3. ^"Print Hello World".www.programming-idioms.org.
  4. ^"Insert element in list".www.programming-idioms.org.

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Programming_idiom&oldid=1267438163"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp