1 software development topic 2 software development languages and environments

19
1 Software Software Development Development Topic 2 Topic 2 Software Development Software Development Languages and Languages and Environments Environments

Upload: barnaby-bond

Post on 27-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

11

Software Software DevelopmentDevelopment

Topic 2Topic 2

Software Development Software Development Languages and EnvironmentsLanguages and Environments

2

TranslatorsTranslators

► As mentioned in the CS topic computers can only As mentioned in the CS topic computers can only understand instructions and data that are written understand instructions and data that are written in binary form. in binary form.

► Programs written in high level languages use lots Programs written in high level languages use lots of English like terms and need to be translated of English like terms and need to be translated so that the computer can understand them.so that the computer can understand them.

► This is done by a piece of systems software This is done by a piece of systems software called a called a translatortranslator..

► We will look at 2 types of translator: -We will look at 2 types of translator: - ► CompilerCompiler► InterpreterInterpreter

3

CompilerCompiler

This program converts high-level language code into This program converts high-level language code into machine code. machine code.

The compiler takes all the source code (the high-level The compiler takes all the source code (the high-level language program before anything is done to it) as one language program before anything is done to it) as one block and translates it into machine code. block and translates it into machine code.

This translated program can be run at any time without This translated program can be run at any time without the source code or the compiler because the translated the source code or the compiler because the translated program is stored as machine code and this machine program is stored as machine code and this machine code can be understood by the processor.code can be understood by the processor.

4

If a change is made to the source If a change is made to the source code then the program must be code then the program must be compiled again so that the change is compiled again so that the change is incorporatedincorporated in the finished compiled in the finished compiled program.program.

The finished compiled program is The finished compiled program is called called object codeobject code. .

Object code is created every time the Object code is created every time the source code is compiled.source code is compiled.

5

InterpreterInterpreterAn interpreter translates and executes each An interpreter translates and executes each program instruction one at a time as the program instruction one at a time as the program is run.program is run.

In simple terms the interpreter does the following: 

1. Fetch instruction2. Translate instruction into machine language

equivalent(s)3. Execute

Programs translated using an interpreter can only be run in conjunction with the interpreter.

If the interpreter is not present then the source code instructions cannot be translated into their machine code equivalents.

6

Compilers V Interpreters.Compilers V Interpreters.1.1. Compilers produce executable programs. Compilers produce executable programs.

E.g. They produce programs that can be run E.g. They produce programs that can be run on a computer system without the need for on a computer system without the need for the source code or the compiler/assembler the source code or the compiler/assembler to be present in the system.to be present in the system.

2.2. Compiled programs run much faster than Compiled programs run much faster than interpreted programs. interpreted programs. This is because interpreted programs read This is because interpreted programs read and translate each instruction in turn and and translate each instruction in turn and this takes time. Compiled programs already this takes time. Compiled programs already have all their instructions converted to have all their instructions converted to machine code. machine code.

Loops run very slowly in interpreted programs Loops run very slowly in interpreted programs because every line in the loop has to be because every line in the loop has to be translated every time it operates.translated every time it operates.

7

3.3. Interpreted programs take less time to develop Interpreted programs take less time to develop (write) because if a change is made to the (write) because if a change is made to the source code then this change is included in the source code then this change is included in the next program run.next program run.

However, with compilers any changes to the However, with compilers any changes to the source code are not included in the executable source code are not included in the executable code until the source code is re-compiled. code until the source code is re-compiled.

Each time a change is made a new version of Each time a change is made a new version of the executable program must be made.the executable program must be made.

8

►The choice of which type of The choice of which type of translator to use depends on the translator to use depends on the type of programs being written and type of programs being written and the experience of the program the experience of the program writer. writer.

►E.g. E.g. Complex programs written by Complex programs written by experienced programmers for experienced programmers for system software or applications system software or applications tend to use compilers.tend to use compilers. Translator Speed Easy to Alter Easy to Understand

Interpreter Slow Yes Yes

Compiler Fast No Yes

Summary

9

Programming LanguagesProgramming LanguagesSDP Theory Booklet pages 34 - 35SDP Theory Booklet pages 34 - 35

►There are 4 main classifications There are 4 main classifications of programming languages that of programming languages that we will concentrate on. These arewe will concentrate on. These are

Procedural LanguagesProcedural Languages Declarative LanguagesDeclarative Languages Event Driven LanguagesEvent Driven Languages Scripting LanguagesScripting Languages

Procedural LanguagesProcedural LanguagesKey featuresKey features► Carried out in a fixed Carried out in a fixed

sequence with a start sequence with a start and end pointand end point

► Can be split into Can be split into separate functions and separate functions and proceduresprocedures

► Have control structures Have control structures such as If statements, such as If statements, for..next loops and for..next loops and do..while loopsdo..while loops

Examples of procedural Examples of procedural languages are:languages are:

►BASICBASIC►PascalPascal►CC

A lot of programmers A lot of programmers are familiar with at are familiar with at least one procedural least one procedural languagelanguage

Example Pascal Procedural Example Pascal Procedural CodeCode

Declarative LanguagesDeclarative Languages

Key featuresKey features► Consist of facts and Consist of facts and

rulesrules► No fixed sequence of No fixed sequence of

instructionsinstructions► Are queried (asked Are queried (asked

questions) which they questions) which they try to find a solution totry to find a solution to

► Uses pattern matching Uses pattern matching to answer queriesto answer queries facts and rules facts and rules

combined in different combined in different ways until a solution, or ways until a solution, or no solution, is foundno solution, is found

Examples of declarative Examples of declarative languages are:languages are:

►PrologProlog►LISPLISP►MLML►SchemeScheme►ErlangErlang

languages such as Prolog languages such as Prolog and LISP are used and LISP are used predominantly in the field predominantly in the field of Artificial Intelligence.of Artificial Intelligence.

Here are some facts:

Parent (Liz, Tom). means that Liz is a parent of TomFemale (Liz). means that Liz is femaleMale(Tom).Parent(Bert, Tom).

Here is a rule:

Mother(X, Y) :- means that X is a mother of Y IF Parent(X, Y), Female(X) X is a parent of Y AND X is female!

Query could be Mother(X, Tom) which would give the answer X=Liz

Example Prolog Declarative Example Prolog Declarative CodeCode

Event Driven LanguagesEvent Driven Languages

Key FeaturesKey Features► no fixed order of no fixed order of

instructionsinstructions► wait for user input wait for user input

(clicking a button) (clicking a button) before performing an before performing an actionaction

► front end for creating front end for creating graphical user graphical user interfacesinterfaces

► share the same type of share the same type of language features as language features as procedural languagesprocedural languages

Examples of event Examples of event driven languages are:driven languages are:

►Visual BasicVisual Basic►Delphi (Object Pascal)Delphi (Object Pascal)►SmalltalkSmalltalk

Used for creating a wide Used for creating a wide range of desktop range of desktop applications for modern applications for modern OS’s such as Mac OSX OS’s such as Mac OSX and Windowsand Windows

Example Visual Basic Event Example Visual Basic Event Driven CodeDriven Code

Scripting LanguagesScripting LanguagesKey FeaturesKey Features►usually built-in to existing usually built-in to existing applicationsapplications

►automate or extend the automate or extend the functionality of functionality of applicationsapplications

►have extra functions, have extra functions, procedures and data types procedures and data types related to the applicationrelated to the application

Selection.Font.NameSelection.Font.Name Range(“A1”).SelectRange(“A1”).Select

►run slower than other run slower than other programs because they’re programs because they’re interpretedinterpreted

►share the same type of share the same type of language features as language features as procedural languagesprocedural languages

Examples of scripting Examples of scripting languages are:languages are:

►VBA (Visual Basic for VBA (Visual Basic for Applications)Applications)►JavascriptJavascript►TCLTCL

Lots of people create Lots of people create and use and use macrosmacros who who wouldn’t consider wouldn’t consider themselves themselves programmersprogrammers

Example VBA Scripting CodeExample VBA Scripting Code

MacrosMacrosBenefits of MacrosBenefits of Macros

► Can extend and add Can extend and add new features to a new features to a program that the program that the developers didn’t developers didn’t think ofthink of

► Can simplify and Can simplify and repeat complex or repeat complex or frequently used frequently used commandscommands

► Can be assigned to a Can be assigned to a keyboard shortcut to keyboard shortcut to make it easier to use make it easier to use when requiredwhen required

Creating a MacroCreating a Macro

1.1. Record a series of actions Record a series of actions in an application you are in an application you are usingusing

2.2. Code gets generated and Code gets generated and saved as a program scriptsaved as a program script

3.3. Script can then be Script can then be assigned to a keystrokeassigned to a keystroke

OrOr

1.1. Write and save the script Write and save the script in an editorin an editor

2.2. Run the script in the Run the script in the application and find and fix application and find and fix any errorsany errors

3.3. Script can then be Script can then be assigned to a keystrokeassigned to a keystroke

Example Exam QuestionsExample Exam Questions1.1. Describe two characteristics of a scripting language not Describe two characteristics of a scripting language not

commonly found in a procedural language (2)commonly found in a procedural language (2)

2.2. A program contains the following statement:A program contains the following statement:

Is_a(rover, dog).Is_a(rover, dog).

State which type of programming language is being used. (1)State which type of programming language is being used. (1)

3.3. State two benefits of using a macro to create an alphabetical list State two benefits of using a macro to create an alphabetical list of customers whose account balance is over £5000. (2)of customers whose account balance is over £5000. (2)

4.4. Macros are written in a high level language. State the type of Macros are written in a high level language. State the type of high level language that is used to write macros. (1)high level language that is used to write macros. (1)

5.5. State two features of a declarative programming language (2)State two features of a declarative programming language (2)

6.6. State two methods of creating a macro (2)State two methods of creating a macro (2)