I see the phrase ‘programming idiom’ thrown around as if it is commonly understood. Yet, in search results and stackoverflow I see everything…
From micro:
- Incrementing a variable
- Representing an infinite loop
- Swapping variable values
To medium:
To macro:
- Programming paradigm or common library features as idiom
- Process model as idiom
- A collection of idioms equals a new paradigm
Is there a single, common definition for ‘programming idiom’? Since ‘programming idiom’ is used in many scopes:
- Micro: syntactic nuance or common syntax
- Medium: common style and patterns
- Macro: programming paradigms as idiom
Is it valid to use the phrase in any of these scopes? The answers so far focus on syntactic idioms. Are the others valid as well?
A programming idiom is the usual way to code a task in a specific language. For example a loop is often written like this in C:
PHP will understand a similar construct:
But it is discouraged in PHP for looping over an array. In this case you would use:
Whereas in Ruby, you would use:
for the loop, or:
There are many many possibilities to write a loop in those languages. Using the idiom makes it immediately identifiable by experienced readers. They can then spend their time on more important problems.