Programming idiom

Common way to code a relatively small construct


title: "Programming idiom" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["programming-idioms"] description: "Common way to code a relatively small construct" topic_path: "general/programming-idioms" source: "https://en.wikipedia.org/wiki/Programming_idiom" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Common way to code a relatively small construct ::

In programming and in code, an idiom describes a commonly-used way to code a relatively small construct in a particular programming context (i.e. programming language). Many such constructs are found in multiple programming contexts yet tend to vary by context. Like a linguistic idiom, a programming idiom is a commonly-used way to express a concept in a language that exists outside the definition of the language yet is constrained by it.

Similar to a software design pattern, an idiom is a template to be followed, not code that can be copy-and-pasted into a codebase. In this sense, an idiom is a pattern, yet software design pattern is a classification reserved for significantly larger-scale functionality; usually involving the interaction of multiple objects.

Using the idioms for a programming context (instead of using idiosyncratic constructs) helps a team work together since they lower the cognitive load of the resulting code. Such idiomatic use is common in crowdsourced repositories to help developers overcome programming barriers.

Examples

Writing to standard output

Writing to standard output is generally something covered early when learning a language; it is often presented through the task of writing a hello world program.

A common idiom in C++ like: ::code[lang=C++] std::println("Hello World"); ::

For Java: ::code[lang=Java] System.out.println("Hello World"); ::

For Rust: ::code[lang=Rust] println!("Hello World"); ::

Using dynamic memory

In C, use the C dynamic memory allocation functions such as malloc() and free().

In C++, use the and operators. The C dynamic memory allocation functions are usable in C++, but would generally be considered idiosyncratic.

References

References

  1. (2014). "Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering".
  2. (2022). "2022 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC)".
  3. "Print Hello World".

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

programming-idioms