What is a programming language?: Difference between revisions

From Computer Science Wiki
(11 intermediate revisions by the same user not shown)
Line 3: Line 3:
A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.<ref>https://en.wikipedia.org/wiki/Programming_language</ref>
A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.<ref>https://en.wikipedia.org/wiki/Programming_language</ref>


== Fundamental operations of a computer ==
== Essential features of a programming language ==
 
The most basic instructions a computer can be given are:
 
* ADD
* COMPARE
* RETRIEVE
* STORE
 
== Compound operations ==
 
Compound operations are composed of very large numbers  of fundamental operations. For example, if we wanted to multiply, we would simply add groups of numbers until we had found our solution.
 
If we ask a simple question: what is the biggest item on this list, we might use '''complex''' code like this:
 
<syntaxhighlight lang="php">
$list_of_numbers = [12,1,54,8,19,4,13,21,12,89,-1,6]
 
echo max($list_of_numbers);
 
</syntaxhighlight>
 
But the computer (using '''fundamental operations''') will process the above instructions like this:
 
<syntaxhighlight lang="assembly">
LOAD register 00001
ADD 12
STORE result
COMPARE result to register 0002
 
(...and so on until the largest number has been found and stored)
 
</syntaxhighlight>
 
== Review the ALU ==
In order to really understand this material, we must understand the ALU - the "brain" of the computer.
 
<html>
<iframe width="560" height="315" src="https://www.youtube.com/embed/1I5ZMmrOfnA?list=PLME-KWdxI8dcaHSzzRsNuOLXtM2Ep_C7a" frameborder="0" allowfullscreen></iframe>
</html>
 
== An example ==
Below is an example of a program language designed to communicate instructions to a machine. The piano is "fed" instructions which enable it to play a simple song. The song is an example of a program. Can you imagine how difficult it might be to "write" these instructions?!?


== Do I understand essential features? ==
<html>
<html>
<iframe width="560" height="315" src="https://www.youtube.com/embed/-ZVc7trWRYw" frameborder="0" allowfullscreen></iframe>
<iframe src="https://assess.computersciencelearning.org/h5p/50/embed" width="846" height="310" frameborder="0" allowfullscreen="allowfullscreen"></iframe><script src="https://assess.computersciencelearning.org/modules/h5p/vendor/h5p/h5p-core/js/h5p-resizer.js" charset="UTF-8"></script>
</html>
</html>


== Explain the need for higher level languages. ==
If you are still stuck, or you have other questions, you may want to [https://discuss.computersciencewiki.org/ '''ask a question on our discussion board'''].
 
If you have watched the example above, you might immediately realize '''it would be crazy''' to write a complex piano piece by punching holes in a piece of paper. This is why we use high-level languages.
 
We need high level languages because programs are highly complex. Even a simple conditional statement would take many hours to write in assembly. Debugging our code would be almost impossible and understanding the code would be almost impossible.
 
== Essential features of a programming language ==


=== Fixed vocabulary ===
=== Fixed vocabulary ===
Line 67: Line 20:
Instructions must be clear. Instructions should not be foggy or fuzzy (ambiguous). For example, if I want to return the absolute value of a number, I would use the instructions below:
Instructions must be clear. Instructions should not be foggy or fuzzy (ambiguous). For example, if I want to return the absolute value of a number, I would use the instructions below:


<syntaxhighlight lang="python">
<syntaxhighlight lang="Python">
# the built-in function for absolute value is abs().  
# the built-in function for absolute value is abs().  


abs(-212)
abs(-212)


</syntaxhighlight>  
</syntaxhighlight>


=== Consistent grammar & syntax ===
=== Consistent grammar & syntax ===
Line 79: Line 32:
For example, a conditional statement must always be formatted the same way. In python the use of whitespace is always the same.
For example, a conditional statement must always be formatted the same way. In python the use of whitespace is always the same.


<syntaxhighlight lang="python">
<syntaxhighlight lang="Python">


if x > 0:
if x > 0:
Line 89: Line 42:
</syntaxhighlight>
</syntaxhighlight>


== Do you understand this? ==


== The basics of programming languages  ==
In order to really understand this material, we must understand the ALU - the "brain" of the computer.
<html>
<iframe width="560" height="315" src="https://www.youtube.com/embed/RU1u-js7db8" frameborder="0" allowfullscreen></iframe>
</html>
== An example ==
Below is an example of a program language designed to communicate instructions to a machine. The piano is "fed" instructions which enable it to play a simple song. The song is an example of a program. Can you imagine how difficult it might be to "write" these instructions?!?
<html>
<iframe width="560" height="315" src="https://www.youtube.com/embed/-ZVc7trWRYw" frameborder="0" allowfullscreen></iframe>
</html>
== Explain the need for higher level languages. ==
If you have watched the example above, you might immediately realize '''it would be crazy''' to write a complex piano piece by punching holes in a piece of paper. This is why we use high-level languages.
We need high level languages because programs are highly complex. Even a simple conditional statement would take many hours to write in assembly. Debugging our code would be almost impossible and understanding the code would be almost impossible.
]


== Standards ==  
== Standards ==  

Revision as of 21:23, 26 April 2020

Programming basics[1]

A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.[2]

Essential features of a programming language[edit]

Do I understand essential features?[edit]

If you are still stuck, or you have other questions, you may want to ask a question on our discussion board.

Fixed vocabulary[edit]

Instructions for operations do not change. For example, the command print will always print. We do not use instructions like "display" or "show" or "put on screen", we always use the same vocabulary. Each programming language has it's own vocabulary, but this vocabulary must be consistent throughout the language.

Unambiguous meaning[edit]

Instructions must be clear. Instructions should not be foggy or fuzzy (ambiguous). For example, if I want to return the absolute value of a number, I would use the instructions below:

# the built-in function for absolute value is abs(). 

abs(-212)

Consistent grammar & syntax[edit]

Throughout the programming language, the way we declare and use language features must be the same. Again, instructions must be very clear. For example, a conditional statement must always be formatted the same way. In python the use of whitespace is always the same.

if x > 0:
    print('X is greater than zero')
else:
    print(' X is equal or greater than zero')


The basics of programming languages[edit]

In order to really understand this material, we must understand the ALU - the "brain" of the computer.

An example[edit]

Below is an example of a program language designed to communicate instructions to a machine. The piano is "fed" instructions which enable it to play a simple song. The song is an example of a program. Can you imagine how difficult it might be to "write" these instructions?!?

Explain the need for higher level languages.[edit]

If you have watched the example above, you might immediately realize it would be crazy to write a complex piano piece by punching holes in a piece of paper. This is why we use high-level languages.

We need high level languages because programs are highly complex. Even a simple conditional statement would take many hours to write in assembly. Debugging our code would be almost impossible and understanding the code would be almost impossible. ]

Standards[edit]

  • State the fundamental operations of a computer.
  • Distinguish between fundamental and compound operations of a computer.
  • Explain the essential features of a computer language.
  • Explain the need for higher level languages.
  • Outline the need for a translation process from a higher level language to machine executable code.

References[edit]