| Line 1: |
Line 1: |
| − | A '''programming language''', sometimes called a '''scripting language''', is an artificial [[language]] used mainly for giving instructions to [[computer]]s; a secondary use is for the precise specification of [[algorithm]]s. A group of instructions for a particular purpose is known as a [[computer program]] (or script). | + | A '''programming language''', is an artificial [[language]] used mainly for giving instructions to [[computer]]s; a secondary use is for the precise specification of [[algorithm]]s. A group of instructions for a particular purpose is known as a [[computer program]]. |
| | | | |
| | When compared with human languages (e.g. English, French, Spanish, etc.), programming languages are very much smaller, much simpler, and are also more precise. Most programming languages consist of a mixture of English words and mathematical notation; very few programming languages have a base vocabulary exceeding 60 words, although they may also have utility libraries with hundreds of entries which provide optional extra functionality. | | When compared with human languages (e.g. English, French, Spanish, etc.), programming languages are very much smaller, much simpler, and are also more precise. Most programming languages consist of a mixture of English words and mathematical notation; very few programming languages have a base vocabulary exceeding 60 words, although they may also have utility libraries with hundreds of entries which provide optional extra functionality. |
| Line 10: |
Line 10: |
| | The meaning or [[semantics]] of any particular construct in a programming language is most commonly described in fairly precise English. Several unsuccessful attempts have been made to find a useful and formal way of describing the semantics. | | The meaning or [[semantics]] of any particular construct in a programming language is most commonly described in fairly precise English. Several unsuccessful attempts have been made to find a useful and formal way of describing the semantics. |
| | | | |
| − | The more important programming languages have an internationally agreed official standard (ISO is the international standards organisation, ANSI is the standards body in the United States). In theory, programs which conform to the relevant standard should be usable on most types of computer; this works in practice most of the time, provided that the programmers have been careful to avoid machine dependencies. Such agreed standards are usually revised every 5 to 15 years, often with new features being added, and sometimes with old features being either removed or marked as obsolete. | + | The more important programming languages have an internationally agreed official standard (ISO is the international standards organization, ANSI is the standards body in the United States). In theory, programs which conform to the relevant standard should be usable on most types of computer; this works in practice most of the time, provided that the programmers have been careful to avoid machine dependencies. Such agreed standards are usually revised every 5 to 15 years, often with new features being added, and sometimes with old features being either removed or marked as obsolete. |
| | | | |
| | Very few programmers learn a programming language directly from the formal definition, which exists primarily as a reference which can be consulted in cases of doubt. There are usually plenty of books and training courses for the more common programming languages. | | Very few programmers learn a programming language directly from the formal definition, which exists primarily as a reference which can be consulted in cases of doubt. There are usually plenty of books and training courses for the more common programming languages. |
| Line 20: |
Line 20: |
| | | | |
| | ==Classifying programming languages== | | ==Classifying programming languages== |
| − | The initial distinction is between '''low-level languages''' and '''high-level languages'''.
| + | Some programming languages are called '''scripting languages''', or '''command languages''', when they are interpreted by an operating system shell or as a way of programming other applications. However, the distinction between languages described with these different terms is largely arbitrary. Although scripting and command languages are usually interpreted and have a smaller grammers than other programming languages, there is nothing inherent about them that prevents them from being compiled instead of interpreted. Nor do they always act as an adjunct to other software as some of them can be used to write stand-alone programs. Further, some languages not labelled as "scripting languages", such as [[BASIC programming language|BASIC]], are interpreted, and versions of BASIC and Pascal have been used as scripting adjuncts to other software. In other words, the distinction is primarily one of usage and nothing inherent to the language itself. The most common languages used primarily for scripting are [[JavaScript]], [[PHP]], and Lua. |
| | + | |
| | + | ==Low-level vs High-level== |
| | + | Programming languages can be categorized by whether they are low-level or high-level. They can also be referred to by "generation". 1st-generation languages are the machine code of the [[CPU]]. 2nd-generation languages are the assembly languages. 3rd-generation languages are what most programmers use in the modern world and include such things as BASIC, C++, Pascal, and PHP. 4th-generation languages are domain-specific and offer productivity gains for programmers in those domains, but their narrow focus makes them unsuitable for solving problems outside of their specific domain. 1st- and 2nd-generation languages are categorized as low-level, while 3rd- and 4th-generation are categorized as high-level. Each generation abstracts the programming concepts further away from the hardware that runs the program. However, concepts and capabilities often cross these generational boundaries over time. |
| | + | |
| | + | Here's an example of some 3rd-generation (Pascal) code and what the equivalent code looks like in 2nd-generation (assembly): |
| | + | |
| | + | In Pascal: |
| | + | <pre> |
| | + | P := Pos( HT, S ) + 1 ; |
| | + | while( S[ P ] <> HT ) do inc( P ) ; |
| | + | </pre> |
| | + | |
| | + | In assembly: |
| | + | <pre> |
| | + | lea eax,[ebp-$918] |
| | + | mov edx,[ebp-$10] |
| | + | call @UStrFromLStr |
| | + | mov edx,[ebp-$918] |
| | + | mov ecx,1 |
| | + | mov eax,$62f890 |
| | + | call Pos |
| | + | inc eax |
| | + | mov [ebp-$8],eax |
| | + | jmp A |
| | + | loop: |
| | + | inc dword ptr [ebp-8] |
| | + | A: |
| | + | mov eax,[ebp-$10] |
| | + | mov edx,[ebp-8] |
| | + | cmp byte ptr [eax+edx-1],9 |
| | + | jnz loop |
| | + | </pre> |
| | | | |
| | ===Low-level languages=== | | ===Low-level languages=== |
| − | Low-level languages are generally referred to as '''assembly''' languages. Most instructions in such languages equate directly to a single machine instruction. Each machine architecture has its own assembly language, so programs written in such languages are generally very machine-specific and are not portable. The instructions in such languages are usually fairly cryptic, often using abbreviations such as ADD, JNE, LR, LI, etc. In the early days of computing (up to about late 1950's) most programming was done in [[assembly language]], partly due to the limited power and memory capacity of early computers. | + | Low-level languages are generally referred to as '''assembly''' languages. Most instructions in such languages equate directly to a single machine instruction. Each machine architecture has its own assembly language, so programs written in such languages are generally very machine-specific and are not portable to different hardware. The instructions in such languages are usually fairly cryptic, often using abbreviations such as ADD, JNE, LR, LI, etc. In the early days of computing (up to about late 1950's) most programming was done in [[assembly language]], partly due to the limited power and memory capacity of early computers. |
| | | | |
| | ===High-level languages=== | | ===High-level languages=== |
| − | High-level languages generally use a mixture of English words and simple mathematical notation, and are often available with little or no change on many different types of computers, depending on what [[compiler]]s are available on which computers. These are often referred to as 3rd-generation languages (the 1st generation was raw binary machine code, the 2nd was assembly language). A single high-level statement may be equivalent to using 3 to 10 assembly language statements, so programming in a high-level language can be much more productive. One of the key reasons for the success of high-level languages is that they provide a level of abstraction (sometimes several such levels). which means that a programmer can concentrate more on the problem to be solved and less on the detail of how to solve it. | + | High-level languages generally use a mixture of English words and simple mathematical notation, and are often available with little or no change on many different types of computers, depending on what [[compiler]]s are available on which computers. A single high-level statement may be equivalent to using 3 to 10 assembly language statements, so programming in a high-level language can be much more productive. One of the key reasons for the success of high-level languages is that they provide a level of abstraction (sometimes several such levels). which means that a programmer can concentrate more on the problem to be solved and less on the detail of how to solve it. |
| | | | |
| | There are a variety of different programming paradigms (styles of writing programs). Some programming languages really only support a single paradigm while others may support several. Possible paradigms include: imperative, declarative, procedural, functional, event-driven, object-oriented, list processing, and automata-based. | | There are a variety of different programming paradigms (styles of writing programs). Some programming languages really only support a single paradigm while others may support several. Possible paradigms include: imperative, declarative, procedural, functional, event-driven, object-oriented, list processing, and automata-based. |
| Line 38: |
Line 70: |
| | | | |
| | ====Imperative programming==== | | ====Imperative programming==== |
| − | This is the most common type of programming language, and many of the other paradigms are derived from or build on this. When using an imperative language, the programmer is responsible for giving precise instructions as to exactly what has to be done and in what order. Note that some programs may have a random element included so that the results of a program are not necessarily predictable.
| + | Also known as '''Procedural Programming''', this is the most common type of programming language, and many of the other paradigms are derived from or build on this. When using an imperative language, the programmer is responsible for giving precise instructions as to exactly what has to be done and in what order. Note that some programs, such as games, may have a random element included so that the results of a program are not necessarily predictable. |
| | | | |
| | Early high-level programming languages were often intended for use in a particular problem domain: | | Early high-level programming languages were often intended for use in a particular problem domain: |
| Line 64: |
Line 96: |
| | Programs which have been completely converted to machine code prior to use may easily run 10 times faster than programs which are interpreted. | | Programs which have been completely converted to machine code prior to use may easily run 10 times faster than programs which are interpreted. |
| | | | |
| − | There are no fixed rules as to which programming languages are processed in which way, and indeed most languages can be handled in any of these three ways. Many languages have been implemented in two or more of these ways. Traditionally compilers have been used for languages where performance is important (e.g. Fortran, '''C'''), interpreters have been used for languages where convenience of use is important (e.g. most scripting and command languages), and translation to intermediate code has been used when machine-independence is considered to be important (e.g. Java). | + | There are no fixed rules as to which programming languages are processed in which way, and indeed most languages can be handled in any of these three ways. Many languages have been implemented in two or more of them. Traditionally compilers have been used for languages where performance is important (e.g. Fortran, '''C'''), interpreters have been used for languages where convenience of use is important (e.g. most scripting and command languages), and translation to intermediate code has been used when machine-independence is considered to be important (e.g. Java, C#). |
| | | | |
| | ==Assorted Languages== | | ==Assorted Languages== |
| Line 80: |
Line 112: |
| | :[[C]] | | :[[C]] |
| | :[[C++]] | | :[[C++]] |
| − | :C# | + | :[[C Sharp|C#]] |
| | :[[Java]] | | :[[Java]] |
| | :[[Javascript]] | | :[[Javascript]] |
| Line 99: |
Line 131: |
| | | | |
| | :[[FORTRAN]] showed that a useful high-level language was possible. | | :[[FORTRAN]] showed that a useful high-level language was possible. |
| − | :COBOL provided a language especially for business use. | + | :[[Cobol|COBOL]] provided a language especially for business use. |
| − | :LISP provided a language suitable for symbol processing. | + | :[[Lisp|LISP]] provided a language suitable for symbol processing. |
| | :Algol 60 was the first block-structured language and set a new standard in language definition (Backus-Naur form). | | :Algol 60 was the first block-structured language and set a new standard in language definition (Backus-Naur form). |
| | ::Algol 60 was described by Edsger Dijkstra, as "a great improvement on many of its successors". | | ::Algol 60 was described by Edsger Dijkstra, as "a great improvement on many of its successors". |
| Line 107: |
Line 139: |
| | :[[C]] showed that operating systems and compilers could be written in a high-level language. | | :[[C]] showed that operating systems and compilers could be written in a high-level language. |
| | | | |
| − | ==Programming Concepts== | + | ==Basic Programming Concepts== |
| | Certain concepts and constructs are common to most, if not all, programming languages. The exact syntax and semantics will vary from language to language, but the basic concepts remain the same. All languages support reserved keywords which define the vocabulary of the language. Identifiers are user-specified words that can be used to name variables, functions, constants, and more. | | Certain concepts and constructs are common to most, if not all, programming languages. The exact syntax and semantics will vary from language to language, but the basic concepts remain the same. All languages support reserved keywords which define the vocabulary of the language. Identifiers are user-specified words that can be used to name variables, functions, constants, and more. |
| | | | |
| Line 117: |
Line 149: |
| | | | |
| | ===Data Types=== | | ===Data Types=== |
| − | [[Data type|Data types]] indicate both how much data is stored as well as how that data can be processed and represented. Some languages (such as [[PHP]]) are typeless, indicating that variables can store any type of data. Other languages (such as [[C++]]) are strictly typed, indicating that each variable can only store data of a given type. | + | [[Data type|Data types]] indicate both how much data is stored as well as how that data can be processed and represented. Some languages (such as [[Python (programming language)|Python]]) are typeless, indicating that variables can store any type of data. Some (such as [[PHP]]) are loosely typed, which means that variables can be given a defined type, but this is not always strictly enforced. Other languages (such as [[C++]]) are strictly typed, indicating that each variable can only store data of a given type. |
| | | | |
| | ===Literals=== | | ===Literals=== |
| Line 171: |
Line 203: |
| | ===Pragmas/Directives=== | | ===Pragmas/Directives=== |
| | Pragmas (aka directives) provide a way of changing options associated with a compiler. For instance, a pragma may alter the memory alignment of data. Conditional compilation is also provided by directives that enable or disable the inclusion of code depending upon external conditions (such as the platform that the program is being compiled upon). | | Pragmas (aka directives) provide a way of changing options associated with a compiler. For instance, a pragma may alter the memory alignment of data. Conditional compilation is also provided by directives that enable or disable the inclusion of code depending upon external conditions (such as the platform that the program is being compiled upon). |
| | + | |
| | + | ==Advanced Programming Concepts== |
| | + | |
| | + | ===Synchronous vs. Asynchronous=== |
| | + | Most programs operate in a synchronous manner: each statement is executed before the next statement is executed. However, some languages have asynchronous abilities built into the language (such as Node.js) or there are optional libraries that can provide asynchronous behavior for other languages. An asynchronous program is one that executes more than one statement concurrently. The mechanism that provides the ability is sometimes called co-routines or, more often, threads. A synchronous program is "single-threaded", while an asynchronous program is "multi-threaded". Multiple threads can execute in parallel which can provide a performance benefit if used correctly. For instance, while one thread is accepting input from the user, another thread can be writing data to a file, and yet another thread can be calculating the display of graphics. Such an approach cannot be accomplished with synchronous code since each of these tasks must complete before the next one can start. |
| | + | |
| | + | Multi-threading can provide benefits, but it also requires far more thought in program design, the use of exclusivity mechanisms (such as mutexes, spinlocks, and/or critical sections) to protect data from being updated at the same time by multiple threads, and multi-threaded code can be exceedingly difficult to maintain and debug. |
| | | | |
| | ==Prescient Quotes on Police State Programming Surveillance== | | ==Prescient Quotes on Police State Programming Surveillance== |
| Line 181: |
Line 220: |
| | [[Category:Information Technology]] | | [[Category:Information Technology]] |
| | [[Category:Computer Science]] | | [[Category:Computer Science]] |
| | + | [[Category:Programming Languages|*]] |