Programing

프로그래밍 관용구 란 무엇입니까?

crosscheck 2020. 11. 12. 07:56
반응형

프로그래밍 관용구 란 무엇입니까?


나는 "프로그래밍 관용구"라는 문구가 일반적으로 이해되는 것처럼 던져지는 것을 본다. 그러나 검색 결과와 stackoverflow에서 모든 것을 볼 수 있습니다 ...

마이크로에서 :

  • 변수 증가
  • 무한 루프를 나타냄
  • 변수 값 바꾸기

중간으로 :

매크로로 :

"프로그래밍 관용구"에 대한 하나의 공통된 정의가 있습니까? "프로그래밍 관용구"는 많은 범위에서 사용되기 때문에 :

  • 마이크로 : 구문 뉘앙스 또는 공통 구문
  • 중간 : 일반적인 스타일 및 패턴
  • 매크로 : 패러다임을 관용구로 프로그래밍

이러한 범위에서 구를 사용하는 것이 유효합니까? 지금까지 답변은 구문 관용구에 중점을 둡니다. 다른 것들도 유효합니까?


프로그래밍 관용구는 특정 언어로 작업을 코딩하는 일반적인 방법입니다. 예를 들어 루프는 종종 C에서 다음과 같이 작성됩니다.

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

PHP는 유사한 구조를 이해합니다.

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

그러나 PHP에서는 배열을 반복하는 것이 권장되지 않습니다. 이 경우 다음을 사용합니다.

foreach ($arr as $value)

반면 Ruby에서는 다음을 사용합니다.

(1..10).each

루프 또는 :

array.each

이러한 언어로 루프를 작성할 수있는 많은 가능성이 있습니다. 관용구를 사용하면 숙련 된 독자가 즉시 식별 할 수 있습니다. 그런 다음 더 중요한 문제에 시간을 할애 할 수 있습니다.


(비 프로그래밍) 언어의 "관용구"는 특정 언어에 고유 한 말 또는 표현입니다. 일반적으로 언어의 "규칙"을 따르지 않고 원어민이 의미하는 바를 "그냥 알고"있기 때문에 존재하는 것입니다. (예를 들어, 영어에서는 "in line"이라고 말하지만 "out of line"은 관용적입니다.)

이것을 프로그래밍 분야로 옮기면 다음과 같은 결과를 얻게됩니다.

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

이것은 실제로 다음을 의미합니다.

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

모든 C / C ++ 프로그래머는 이해하지만 다른 프로그래밍 언어에서 온 사람을 완전히 당황하게합니다.


http://en.wikipedia.org/wiki/Programming_idiom 참조

A programming idiom is a pattern, algorithm or way of structuring code. To talk about programming idioms is to talk about those patterns that recur frequently in code or to propose new ones.

The benefits of being familiar with idioms, particularly the larger ones, is that when looking at code you can see several lines of code but because it is familiar as a particular idiom you can mentally represent and think about the code as that single idiom instead of having to necessarily read and comprehend each line individually.

To say that code isn't idiomatic is to say that it doesn't structure itself in ways that allow human readers to think about the code effectively.


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!


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.


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

I wouldn't say it has anything to do with a particular programming language.

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

That is a snippet of what i would call the 'for each' idiom which is expressed slightly different in a number of languages.

Another excellent example of an idiom is Socket. All platforms that claim to have sockets, all work in conceptually the same way, that is, they all have roughly the same interface.


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


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.


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


It comes from idiomatic the meaning of the word idiom in programming can be summed up as phrase that carries meaning and implications that is more than the sum of the words. In programming most code snippets are actually idiomatic. 'Pertaining or conforming to the natural mode of expression of a language'

A Programming idiom can be considered descriptive of a class of solutions that is transferable to different cases. Consider while { ... } vs do {} while these are idiomatic, they contain the same words but the ordering carries an important distinction. The exact phrasing will differ by language, but the fundamental meaning and implications will differ; for example do {} while will always be executed once, no matter what language or statements are used to implement it. As an idiom it is transferable shape of an idea. It could be used in many circumstances, and expressed with different words (statements/commands) but the fundamental result will always be the same.

참고URL : https://stackoverflow.com/questions/302459/what-is-a-programming-idiom

반응형