What is a programming idiom?

后端 未结 10 2036
一向
一向 2020-12-04 06:42

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:

<
相关标签:
10条回答
  • 2020-12-04 07:07

    Since large programs grow from small ones, it is crucial that we develop an arsenal of standard program structures of whose correctness we have become sure -- we call them idioms -- and learn to combine them into larger structures using organizational techniques of proven value.

    A programmer should acquire good algorithms and idioms.

    Alan J. Perlis - SICP Foreword

    0 讨论(0)
  • 2020-12-04 07:10

    Get into a rut early: Do the same process the same way. Accumulate idioms. Standardize. The only difference(!) between Shakespeare and you was the size of his idiom list – not the size of his vocabulary.

    • ALAN PERLIS, Epigrams in Programming

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

    0 讨论(0)
  • 2020-12-04 07:14

    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.

    0 讨论(0)
  • 2020-12-04 07:15

    An idiom is a way of saying something that is particular to a given language. For example here are a handful of english idioms.

    You can extrapolate this to apply the concept to programming.

    0 讨论(0)
  • 2020-12-04 07:19

    Idiom is a term from linguistics. It is a group of words that do not literally mean what the say. For example saying someone is "under the weather" when they are not feeling well. That particular phrase came from sailors talking about passengers, seasick passengers would go below the "weather" decks where the ships motion was less. But most of us are not sailors and don't know the literal meaning of the phrase.

    In programming many, even most of the instructions are not understood by the general public even though they are English words. for example "for loop". While they make sense to programmers, they don't to most other people.

    0 讨论(0)
  • 2020-12-04 07:21

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

    I'm guessing you've already been down that road though!

    0 讨论(0)
提交回复
热议问题