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:
To medium:
To macro:
Is there a single, common definition for "programming idiom"? Since "programming idiom" is used in many scopes:
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?
So, in software engineering “idiomatic” means “conforming to the natural mode of expression in a given context”, where that context can be a programming language, like Kotlin or JS, or even a framework like React or RxJava.
For example, if you say you're feeling “under the weather,” you don't literally mean that you're standing underneath the rain. “Under the weather” is an idiom that is universally understood to mean sick or ill.
Idiomatic Python is what you write when the only thing you're struggling with is the right way to solve your problem, and you're not struggling with the programming language or some weird library error or a nasty data retrieval issue or something else extraneous to your real problem.
A programming language is a type of written language that tells computers what to do. Examples are: Python, Ruby, Java, JavaScript, C, C++, and C#.
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:
for (i=0; i<10; i++)
PHP will understand a similar construct:
for ($i = 1; $i <= 10; $i++)
But it is discouraged in PHP for looping over an array. In this case you would use:
foreach ($arr as $value)
Whereas in Ruby, you would use:
(1..10).each
for the loop, or:
array.each
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.
An "idiom" in (non-programming) language is a saying or expression which is unique to a particular language. Generally something which doesn't follow the "rules" of the langauge, and just exist because native speakers "just know" what it means. (for instance, in English we say "in line" but "out of line" -- that would be idiomatic)
Moving this to the programming arena, we get things like:
if(c=GetValue()) {...}
which actaually means:
c = GetValue(); if (c != 0) {....}
which every C/C++ programmer understand, but would totally baffle someone coming from a different programming language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With