What is a programming idiom?

I see that the phrase "programming idioms" is ejected as if it is usually understood. However, in the search results and stackoverflow I see everything ...

From micro:

  • Variable increment
  • Infinite loop view
  • Change variable values

Average value:

In the macro:

Is there one general definition for a "programming idiom"? Because "idiom programming" is used in many areas:

  • Micro: syntactic nuance or general syntax
  • Medium: general style and patterns
  • Macro: programming paradigms as an idiom

Can I use a phrase in any of these areas? Answers still focus on syntactic idioms. Are others valid also?

+67
language-agnostic idioms
Nov 19 '08 at 16:21
source share
10 answers

A programming idiom is a common way to encode a task in a particular language. For example, a loop is often written in C:

for (i=0; i<10; i++) 

PHP will understand a similar construction:

 for ($i = 1; $i <= 10; $i++) 

But in PHP it is not recommended to loop through an array cyclically. In this case, you will use:

 foreach ($arr as $value) 

If in Ruby you use:

 (1..10).each 

for a loop or:

 array.each 

There are many possibilities to write a loop in these languages. Using an idiom makes it immediately identifiable by experienced readers. Then they can spend their time on more important issues.

+52
Nov 19 '08 at 16:49
source share

An “idiom” in a (non-programming) language is a statement or expression that is unique to a particular language. Actually, that does not follow the “rules” of langauge and simply exists, because native speakers “just know” what this means. (for example, in English we say “in line”, but “out of line” - this will be idiomatic)

Moving this to the programming arena, we get things like:

  if(c=GetValue()) {...} 

which usually means:

  c = GetValue(); if (c != 0) {....} 

which every C / C ++ programmer understands, but completely confuses those who come from another programming language.

+17
Nov 19 '08 at 16:31
source share

See http://en.wikipedia.org/wiki/Programming_idiom

A programming idiom is a template, algorithm, or method for structuring code. Talk about programming idioms - talk about those patterns that are often repeated in code or suggest new ones.

The benefits of getting to know idioms, especially large ones, are that when you look at the code you can see several lines of code, but since it is familiar with a specific idiom, you can mentally imagine and think of the code as the only idiom instead of having to read and understand each line individually.

To say that the code is not idiomatic is to say that it does not structure itself in such a way as to allow people readers to think effectively about the code.

+11
Nov 19 '08 at 16:24
source share

From WikiPedia : A programming idiom is a means of expressing a repeating construct in one or more programming languages.

I guess you were already on this road, though!

+2
Nov 19 '08 at 16:25
source share

Idiom is a term from linguistics. This is a group of words that literally do not mean what they say. For example, to say that someone is “under the weather” when they feel bad. This particular phrase came from sailors talking about passengers, passengers at sea followed the “weather” decks, where the movement of the ships was less. But most of us are not sailors and do not know the literal meaning of this phrase.

When programming, many even most instructions are not understood by the general public, even if they are English words. for example, for a loop. Although they make sense to programmers, they do not apply to most other people.

+2
Nov 19 '08 at 16:29
source share

An idiom is a pattern that can be identified in several places.

I would not say that this has anything to do with a particular programming language.

 Iterator foo; foo.reset(); while (foo.next()) { print(foo.value()); } 

This is a snippet of what I would call an “for every” idiom, which is slightly different in several languages.

Another great example of an idiom is Socket . All platforms that claim to have sockets all work conceptually the same, i.e. All of them have approximately the same interface.

+2
Jun 15 '09 at 12:12
source share

As large programs grow from small ones, it is imperative that we develop an arsenal of standard program structures whose validity we have verified — we call them idioms — and learn to integrate them into larger structures using proven organizational methods.

A programmer should get good algorithms and idioms.

Alan J. Perlis - SICP Foreword

+2
May 14 '13 at 4:35
source share

An idiom is a way of saying something special for a given language. For example, here are a few English idioms .

You can extrapolate this to apply the concept to programming.

+1
Nov 19 '08 at 16:33
source share

Get on track early: follow the same process in the same way. Accumulate idioms. Standardization. The only difference (!) Between Shakespeare and you was the size of his idiom list, not the size of his dictionary.

  • ALAN PERLIS, Epigrams in programming

http://www.cs.yale.edu/quotes.html

+1
Jan 13 2018-12-12T00:
source share

This comes from the idiomatic meaning of the word idiom in programming, can be expressed as a phrase that carries a meaning and a value that exceeds the sum of the words. In programming, most code snippets are actually idiomatic. "Related to or corresponding to the natural way of expressing a language"

The programming idiom can be considered descriptive for a class of solutions that can be carried over to different cases. Consider while { ... } versus do {} while , they are idiomatic, they contain the same words, but the order has an important difference. The exact wording will differ depending on the language, but the main meaning and meaning will differ; for example, do {} while will always be executed once, regardless of which language or operators are used to implement it. As an idiom, this is a portable form of an idea. It can be used in many circumstances and expressed in different words (statements / commands), but the fundamental result will always be the same.

0
Jun 20 '18 at 17:35
source share



All Articles