2 Programming Languages and Eviroments

advertisement
Higher Computing
Software Development
Development Languages and
Environments
I Power
Int 2
Machine Code
As we know computers only understand
binary numbers.
The instructions made up of binary are
called machine code.
Programs written in machine code run very
fast but are difficult for humans to
understand.
Int 2
High Level languages
To make it easy for programmers, code can
be written in a high level language.
High level language describes any language
that uses English commands. E.g.
Print/Repeat.
Because computers only understand
Machine code the computer must translate
the High Level Language into machine code
which slows the computer down.
Int 2
Text Editors
High Level languages can be written in a
Text Editor.
Text editors (notepad) allow us to:
enter the code
Edit the code
Copy/Paste – Search/Replace
Indent the code
Some text editors assist us by colouring
keywords and predicting the text.
Int 2
Translators
In order for the computer to understand the
High level language that we have been
programming in we the code must first be
translated into machine code.
The two translators that we need to know
about are:
Compilers.
Interpreters.
Int 2
Compilers
The whole program (the source code) is translates
into machine code at once creating a new file (the
object code).
The source code can be translated from many
different platforms to produce different object files.
Once translated the object code can be executed
many time without being translated again.
This means that the execution of the program will
be faster as there is no need to load the translator
into RAM.
The disadvantage is the object code will not run if
there are any syntax errors in the code.
Int 2
Interpreters
The whole program file is translated and
executed each line at a time.
No object code is created.
The translator must be loaded into RAM
every time the code is executed making the
program slow.
The code can be translated on a number of
platforms if different translators are used.
The interpreter will run part of the code if
there are syntax errors in it.
Int 2
What we will learn
Types of Programming Languages.
Types of translators.
Module Libraries.
Int 2
Types of Programming Language
When Programming it is important to
choose a suitable program for the task
given.
There are several different types of
categories that we must know about.
Int 2
Categories
Procedural Languages.
Declarative Languages.
Event Driven Languages.
Scripting Languages.
Higher
Procedural languages (imperative
languages).
Theses are high level languages that use
command and key words for instructions.
Normally a sequence of instructions with a
clear start and end.
Higher
Procedural Example
10 Print “What is your Name?”
20 Input Name$
30 Print “Hello “;Name$
40 End
Higher
Declarative Languages
These are a collection of facts and rules
which describe a problem.
The user would type in a query and the
program will match it with the program and
return any missing information it may
know.
Higher
Declarative Example
Male (John).
Male (Robert).
Parent (John,Ruth).
Father (X,Y) :Parent (X,Y), Male (X).
Higher
Event-Driven Languages
These are similar to procedural languages,
the difference is the way that they are
designed to run.
Modules of code are tie to objects or
buttons on the screen.
The code is only run when the user
performs some operation on the screen. E.g.
clicking a button or moving the mouse.
Higher
Event-Driven Example
Private Sub Cmdclear_Click()
txtmessage.Text = ""
Cmdclear.Enabled = False
Cmddisplay.Enabled = True
End Sub
Private Sub Cmddisplay_Click()
txtmessage.Text = "Hello World"
Cmddisplay.Enabled = False
Cmdclear.Enabled = True
End Sub
This code is run only when
the display button is
pressed
Private Sub Cmdexit_Click()
End
End Sub
Int 2
Scripting Language
These are like a procedural language, in that
they use variables etc.
The main difference is where these are
used.
Scripting languages are used to automate or
extend the functionality of an application.
E.g. VBScript. NOT VB
Int 2
Scripting Language
These scripts may create an applet (Small
Application) or a macro (A stored list of
actions recorded from users actions).
Run Example.
Int 2
Module Libraries
In order to save programmers time small pieces
of code that do simple tasks are saved separately.
These pieces of code are called Modules.
Modules are stored together in Module
Libraries.
Advantages are:
You do not have to rewrite code that has been written
before.
The code has already been tested for errors.
These modules should be well documented.
Download