[go: nahoru, domu]

Jump to content

Programming idiom: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m v1.43 - WP:WCW project (Heading should begin with "=")
inline EXT -> ref, linksm ref sect, un -> refimp
Line 1: Line 1:
{{unreferenced|date=May 2016}}
{{refimprove|date=May 2016}}
A '''programming idiom''' (AKA Code Idiom) is expressing a special feature of a recurring construct in one or more [[programming language]]s. Developers recognize programming idioms by associating and giving meaning to one or more code fragments. The idiom can be seen as a concept underlying a pattern in code, which is represented in implementation by contiguous or scattered code fragments. These fragments are available in several programming languages, frameworks or even libraries. Generally speaking, a programming idiom is a natural language expression of a simple task, [[algorithm]], or [[data structure]] that is not a built-in feature in the programming language being used, or, conversely, the use of an unusual or notable feature that ''is'' built into a programming language. Furthermore, the term can be used more broadly, to refer to complex algorithms or [[programming design pattern]]s in terms of implementation and omitting design rationale.
A '''programming idiom''' or '''code idiom''' is expressing a special feature of a recurring construct in one or more [[programming language]]s. [[Software developer|Developers]] recognize programming idioms by associating and giving meaning to one or more [[code snippet|code fragment]]s. The idiom can be seen as a concept underlying a pattern in code, which is represented in implementation by contiguous or scattered code fragments. These fragments are available in several programming languages, [[software framework|framework]]s or even [[library (computing)|libraries]]. Generally speaking, a programming idiom is a natural language expression of a simple task, [[algorithm]], or [[data structure]] that is not a [[built-in type|built-in]] feature in the programming language being used, or, conversely, the use of an unusual or notable feature that ''is'' built into a programming language. Furthermore, the term can be used more broadly, to refer to complex algorithms or [[programming design pattern]]s in terms of implementation and omitting design rationale.


Knowing the idioms associated with a programming language and how to use them is an important part of gaining [[fluency]] in that language, and transferring knowledge in the form of analogies from one language or framework to another.
Knowing the idioms associated with a programming language and how to use them is an important part of gaining [[fluency]] in that language, and transferring knowledge in the form of analogies from one language or framework to another.


==Examples of simple idioms==
==Examples of simple idioms==
===Printing Hello World===
{{main|"Hello, World!" program}}
One of the most common starting points to learn a program or notice the syntax differences between a known language and a new one.<ref>http://www.programming-idioms.org/idiom/1/print-hello-world</ref>


It has several implementations, among them the code fragments for [[C++]]:
===[http://www.programming-idioms.org/idiom/1/print-hello-world Printing Hello World]===
One of the most common starting points to learn a program or notice the syntax differences between a known language and a new one.

It has several implementations, among them the code fragments for C++:
<source lang=C++>
<source lang=C++>
#include <iostream>
#include <iostream>
Line 15: Line 15:
</source>
</source>


For Java:
For [[Java (programming language)|Java]]:
<source lang=Java>
<source lang=Java>
System.out.println("Hello World");
System.out.println("Hello World");
</source>
</source>


===Inserting an element in an array===
=== [http://www.programming-idioms.org/idiom/44/insert-element-in-list Inserting An Element In An Array] ===
This idiom helps developers understanding how to manipulate collections in a given language, particularly inserting an element '''x''' at a position '''i''' in a list '''s''' and moving the elements to its right.
This idiom helps developers understanding how to manipulate collections in a given language, particularly inserting an element '''x''' at a position '''i''' in a list '''s''' and moving the elements to its right.<ref>http://www.programming-idioms.org/idiom/44/insert-element-in-list</ref>


Code fragments for Python:
Code fragments for [[Python (programming language)|Python]]:
<source lang=Java>
<source lang=Java>
s.insert(i, x)
s.insert(i, x)
</source>
</source>


For JavaScript:
For [[JavaScript]]:
<source lang=Java>
<source lang=Java>
s.splice(i, 0, x);
s.splice(i, 0, x);
</source>
</source>


For Perl:
For [[Perl]]:
<source lang=Perl>
<source lang=Perl>
splice(@s, $i, 0, $x)
splice(@s, $i, 0, $x)
Line 39: Line 39:


== See also ==
== See also ==
* [[Idiom (language structure)]]
* [[Algorithmic skeleton]]
* [[Algorithmic skeleton]]
* [[Idiom (language structure)|Idiom]]

==References==
{{Reflist}}


== External links ==
== External links ==

Revision as of 17:54, 22 February 2018

A programming idiom or code idiom is expressing a special feature of a recurring construct in one or more programming languages. Developers recognize programming idioms by associating and giving meaning to one or more code fragments. The idiom can be seen as a concept underlying a pattern in code, which is represented in implementation by contiguous or scattered code fragments. These fragments are available in several programming languages, frameworks or even libraries. Generally speaking, a programming idiom is a natural language expression of a simple task, algorithm, or data structure that is not a built-in feature in the programming language being used, or, conversely, the use of an unusual or notable feature that is built into a programming language. Furthermore, the term can be used more broadly, to refer to complex algorithms or programming design patterns in terms of implementation and omitting design rationale.

Knowing the idioms associated with a programming language and how to use them is an important part of gaining fluency in that language, and transferring knowledge in the form of analogies from one language or framework to another.

Examples of simple idioms

Printing Hello World

One of the most common starting points to learn a program or notice the syntax differences between a known language and a new one.[1]

It has several implementations, among them the code fragments for C++:

#include <iostream> 
std::cout << "Hello World\n";

For Java:

System.out.println("Hello World");

Inserting an element in an array

This idiom helps developers understanding how to manipulate collections in a given language, particularly inserting an element x at a position i in a list s and moving the elements to its right.[2]

Code fragments for Python:

s.insert(i, x)

For JavaScript:

s.splice(i, 0, x);

For Perl:

splice(@s, $i, 0, $x)

See also

References