Difference between revisions of "Classification of Programming Languages"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Assembly Language)
(Overview)
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=Overview=
 +
===CraigNDave===
 +
<youtube>https://www.youtube.com/watch?v=yORSZkhNpZ4&index=1&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW</youtube>
 +
 +
https://www.youtube.com/watch?v=yORSZkhNpZ4&index=1&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW
 +
 +
===Computer Science Tutor===
 +
<youtube>HtUQzhTt3gE</youtube>
 +
 +
https://www.youtube.com/watch?v=HtUQzhTt3gE&list=PL04uZ7242_M6O_6ITD6ncf7EonVHyBeCm&index=15
 +
 +
===TRC Video===
 +
<youtube>https://www.youtube.com/watch?v=YsRmX3Lnb6M</youtube>
 +
 +
https://www.youtube.com/watch?v=YsRmX3Lnb6M
 +
 +
=Low Level vs High Level=
 +
 +
<youtube>https://www.youtube.com/watch?v=tl-96ZypmpQ&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW&index=2</youtube>
 +
 +
https://www.youtube.com/watch?v=tl-96ZypmpQ&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW&index=2
 +
 
=Low Level Languages=
 
=Low Level Languages=
  
 
==Machine Code==
 
==Machine Code==
Machine code is the basic binary information required for a computer to perform a function. It is classified as a 1st generation programming language. Each command is binary pattern, ie 100001 might be load, or 100010 might be add or 100011 might be store.  
+
Machine code is the basic binary information required for a computer to perform a function. It is classified as a '''1st generation''' programming language. Each command is binary pattern, ie 100001 might be load, or 100010 might be add or 100011 might be store.  
  
 
This is essentially writing a program by coding the binary. This provides direct access to the hardware and all programs are converted to machine code at some point.
 
This is essentially writing a program by coding the binary. This provides direct access to the hardware and all programs are converted to machine code at some point.
  
 
==Assembly Language==
 
==Assembly Language==
Assembly language is a low level, 2nd generation programming language, purposed towards fast execution and complete control over hardware. It replaces a binary pattern with a more readable mnemonic, ie a command word.
+
Assembly language is a low level, '''2nd generation''' programming language, purposed towards fast execution and complete control over hardware. It replaces a binary pattern with a more readable mnemonic, ie a command word.
  
 
One assembly language instruction is equivalent to one machine code instruction, and an assembler is used to convert the assembly language to machine code.
 
One assembly language instruction is equivalent to one machine code instruction, and an assembler is used to convert the assembly language to machine code.
Line 16: Line 38:
 
==Terms==
 
==Terms==
 
===Mnemonics===
 
===Mnemonics===
An identifiable text label for a particular command (rather than requiring a programmer write instructions in binary).
+
An identifiable text label for a particular command (rather than requiring a programmer to write instructions in binary).
  
 
===Source Code===
 
===Source Code===
Line 23: Line 45:
 
===Object Code===
 
===Object Code===
 
The object code is generated by the interpreter, compiler or assembler.
 
The object code is generated by the interpreter, compiler or assembler.
 +
 +
==Benefits of Low Level Languages==
 +
*Programs developed using low level languages are fast and memory efficient.
 +
*Programmers can utilise processor and memory in better way using a low level language.
 +
*There is no need of any compiler or interpreters.
 +
*They provide direct manipulation of computer registers and storage.
 +
*It can directly communicate with hardware devices.
  
 
=High Level Languages=
 
=High Level Languages=
Line 34: Line 63:
  
 
==Imperative==
 
==Imperative==
Imperative, or procedural, programming languages break down processes into functions or methods, which are all given mnemonics. A single statement of an imperative language is converted to multiple machine code instructions by a language translator (such as an interpreter or compiler), which are then executed in sequence. Imperative languages are part of the 3rd generation of programming languages. Examples of imperative languages include C++, Python and Visual Basic.
+
Your code focuses on creating statements that change program states by creating algorithms that tell the computer how to do things. It closely relates to how hardware works. Your code will make use of sequence, selection, and repetition.
  
==Object Oriented==
+
Imperative, or procedural, programming languages break down processes into functions or methods, which are all given command words.  
OOP languages are based on the emulation of real world '''''objects''''' and their relationships and interactions with each other. The basis of object oriented programming is situated on the re-usability and conservation of large scale code/programming structures; for example, a video game makes extensive use of object oriented programming by defining complex object hierarchies, such as:
 
  
:Object
+
A single statement of an imperative language is converted to multiple machine code instructions by a language translator (such as an interpreter or compiler), which are then executed in sequence.
::Sprite
 
:::PlayableSprite
 
::::MainCharacter
 
  
Note At This Point We Can Also Have Other Classes Inherit From Sprite
+
Imperative languages are part of the '''3rd generation''' of programming languages. Examples of imperative languages include C++, Python and Visual Basic.
  
:::EnemySprite
+
==Declarative==
::::BossMonster
+
Often referred to as '''4th generation''' Languages, Declarative languages allow the programmer to specify what they want to produce, without having to say how to achieve it.
::::BufferMonster
 
:::StaticSprite
 
::::Block
 
::::TreasureChest
 
etc...
 
  
Note that inheritance isn't just a fancy way to structure classes; OOP also allows for methods, variables, anonymous functions etc. to be passed on down the chain, for example if the base class Sprite is given a default integer (health) and a Method() (Death), any class which inherits from sprite will automatically have these instance members defined at declaration. Furthermore inherited classes can override base methods and variables, and call methods or variables higher up on the inheritance chain (using the base/super method). for Example:
+
For example SQL is declarative, you say what you want to select, where to select it from, and what conditions apply. The SQL server will then execute your request according to its coding and provide you with the results.
  
<tabber>
+
==Benefits of High Level Languages==
C#=
+
*They are programmer friendly (easy to write, debug and maintain).
<syntaxhighlight lang="csharp" line>
+
*Higher level of abstraction, one command equates to many machine code instructions.
 +
*It is machine independent language.
 +
*Easy to learn.
 +
*Less error prone, easy to find and debug errors.
 +
*Better programming productivity
  
struct Rect {
+
=Quiz=
    public Rect(int x, int y, int w, int h) {
+
<quiz display=simple>
        this.X = x, this.Y = y, this.width = w, this.height = h;
 
    }
 
  
    public Int32 X, Y, width, height;
+
{ What is the only First generation language?
}
+
| type=" () " }
 +
- SQL
 +
|| SQL is actually a fourth generation language.
 +
- PHP
 +
|| PHP is an example of a third generation language.
 +
+ Machine Code
 +
|| Correct, it consists of only binary values.
 +
- Assembly language
 +
|| Assembly language is based off of a first generation language, but it isn't one.
  
class Sprite : object { // reference to base "Object" Unnecessary As All Classes Originate From "Object"
+
{ Which of these is an imperative programming language?
    public Sprite() {  
+
| type="()" }
        this.ID = Sprite.spriteCount.ToString().PadLeft(5, '0');
 
        Sprite.spriteCount += 1;
 
    } // If No ID Given
 
  
    public Sprite(String spriteID) {
+
- SQL
        this.ID = spriteID;
+
||Incorrect.
        Sprite.spriteCount += 1;
+
- Prolog
    }
+
||Incorrect.
 +
+ C++
 +
||Correct.
  
    public void Dead() {
+
{ Which generation does not use mnemonics?
        // Do Some Stuff When Dead
+
| type="()" }
    }
 
  
    public String ID;
+
+ Gen 1
    public Int32 Health = 100;
+
||Correct.
    public Rect position;
+
- Gen 2
    public bool IsDead { get { return (this.Health == 0); } }
+
||Incorrect.
 +
- Gen 3
 +
||Incorrect.
 +
- Gen 4 and above.
 +
||Incorrect.
  
    public static Int32 spriteCount = 0;
+
{What generation of programming language is C++?
}
+
| type="()"}
 +
- 1st
 +
- 2nd
 +
+ 3rd
 +
- 4th
  
class PlayableSprite : Sprite {
+
{What level of programming language is harder for the user to understand?
    public PlayableSprite(Rect pos) : base() { // creates new constructor & calls base constructor
+
| type="()"}
        this.position = pos;
+
+ Low level language
    }
+
- High level language
  
    public PlayableSprite(String id, Rect pos) : base(id) { // calls base constructor with passed parameter
+
{Which of the following are higher level 3rd generation languages?
        this.position = pos;
+
| type="[]"}
    }
+
- C
 +
+ VB
 +
- C++
 +
+ Python
 +
- Assembly Language
  
    public void CheckInput(KeyboardState kb) {
+
{What is the relationship between assembly language and machine code?
        // Loads of movement code, tied to user keypress
+
| type="()"}
    }
+
+ 1 line of assembly language = 1 line of machine code
}
+
- 1 line of assembly language = 2 line of machine code
  
class EnemySprite : Sprite {
+
{When should you use low level languages
    public void Move() {
+
|type="[]"}
        // Loads of movement code, tied to mathematical algorithm
+
+In time critical situations.
    }
+
-In college to look good.
}
+
+In error critical situations.
 +
-Everyday use.
  
</syntaxhighlight>
+
{ Why are Low level languages still used?
</tabber>
+
|type="()" }
 +
- Why not?
 +
- Prevents damage to the computer.
 +
+ Allows low level access to the PC hardware.
  
In The Above example both PlayableSprite & EnemySprite are siblings and possess all the same instance members as Sprite.
+
</quiz>
 
 
<tabber>
 
C#=
 
<syntaxhighlight lang="csharp" line>
 
 
 
PlayableSprite protag = new PlayableSprite("00000", new Rect(0, 0, 100, 100)); // calls overridden constructor
 
 
 
EnemySprite boss = new EnemySprite("00000") {
 
    position = new Rect(1000, 1000, 100, 100); // Set Base Member Instance Variable
 
};
 
 
 
while (!protag.IsDead && !boss.IsDead()) { // Accessing Base Member Instance Variable
 
    // Game Run Until either player or enemy is dead
 
}
 
 
 
</syntaxhighlight>
 
</tabber>
 
 
 
The above example doesn't in any part do anything, but it does showcase the simple and intuitive way of decompressing complex code into simple classes.
 
 
 
==Declarative==
 

Latest revision as of 08:37, 23 August 2023

Overview

CraigNDave

https://www.youtube.com/watch?v=yORSZkhNpZ4&index=1&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW

Computer Science Tutor

https://www.youtube.com/watch?v=HtUQzhTt3gE&list=PL04uZ7242_M6O_6ITD6ncf7EonVHyBeCm&index=15

TRC Video

https://www.youtube.com/watch?v=YsRmX3Lnb6M

Low Level vs High Level

https://www.youtube.com/watch?v=tl-96ZypmpQ&list=PLCiOXwirraUDJYD-VxmztyhsDP0QM2BHW&index=2

Low Level Languages

Machine Code

Machine code is the basic binary information required for a computer to perform a function. It is classified as a 1st generation programming language. Each command is binary pattern, ie 100001 might be load, or 100010 might be add or 100011 might be store.

This is essentially writing a program by coding the binary. This provides direct access to the hardware and all programs are converted to machine code at some point.

Assembly Language

Assembly language is a low level, 2nd generation programming language, purposed towards fast execution and complete control over hardware. It replaces a binary pattern with a more readable mnemonic, ie a command word.

One assembly language instruction is equivalent to one machine code instruction, and an assembler is used to convert the assembly language to machine code.

Relationship Between Machine Code & Assembly Language

One machine code instruction will create one assembly language instruction. Remember assembly language is essentially replacing a binary pattern with a command word.

Terms

Mnemonics

An identifiable text label for a particular command (rather than requiring a programmer to write instructions in binary).

Source Code

The source code is a program as written by the programmer.

Object Code

The object code is generated by the interpreter, compiler or assembler.

Benefits of Low Level Languages

  • Programs developed using low level languages are fast and memory efficient.
  • Programmers can utilise processor and memory in better way using a low level language.
  • There is no need of any compiler or interpreters.
  • They provide direct manipulation of computer registers and storage.
  • It can directly communicate with hardware devices.

High Level Languages

The main characteristics of a high level language are:

  • It is easier for the programmer to identify what a command does (English words)
  • High level languages need to be translated
  • One command in a high level language represents many lines of code in assembler or machine code
  • They are portable between systems
  • More straight forward to program
  • Wider variety of data structures

Imperative

Your code focuses on creating statements that change program states by creating algorithms that tell the computer how to do things. It closely relates to how hardware works. Your code will make use of sequence, selection, and repetition.

Imperative, or procedural, programming languages break down processes into functions or methods, which are all given command words.

A single statement of an imperative language is converted to multiple machine code instructions by a language translator (such as an interpreter or compiler), which are then executed in sequence.

Imperative languages are part of the 3rd generation of programming languages. Examples of imperative languages include C++, Python and Visual Basic.

Declarative

Often referred to as 4th generation Languages, Declarative languages allow the programmer to specify what they want to produce, without having to say how to achieve it.

For example SQL is declarative, you say what you want to select, where to select it from, and what conditions apply. The SQL server will then execute your request according to its coding and provide you with the results.

Benefits of High Level Languages

  • They are programmer friendly (easy to write, debug and maintain).
  • Higher level of abstraction, one command equates to many machine code instructions.
  • It is machine independent language.
  • Easy to learn.
  • Less error prone, easy to find and debug errors.
  • Better programming productivity

Quiz

1. What is the only First generation language?

SQL
SQL is actually a fourth generation language.
PHP
PHP is an example of a third generation language.
Machine Code
Correct, it consists of only binary values.
Assembly language
Assembly language is based off of a first generation language, but it isn't one.

2. Which of these is an imperative programming language?

SQL
Incorrect.
Prolog
Incorrect.
C++
Correct.

3. Which generation does not use mnemonics?

Gen 1
Correct.
Gen 2
Incorrect.
Gen 3
Incorrect.
Gen 4 and above.
Incorrect.

4. What generation of programming language is C++?

1st
2nd
3rd
4th

5. What level of programming language is harder for the user to understand?

Low level language
High level language

6. Which of the following are higher level 3rd generation languages?

C
VB
C++
Python
Assembly Language

7. What is the relationship between assembly language and machine code?

1 line of assembly language = 1 line of machine code
1 line of assembly language = 2 line of machine code

8. When should you use low level languages

In time critical situations.
In college to look good.
In error critical situations.
Everyday use.

9. Why are Low level languages still used?

Why not?
Prevents damage to the computer.
Allows low level access to the PC hardware.

Your score is 0 / 0