languages and environments higher computing unit 2 – software development

30
Languages and Languages and Environments Environments Higher Computing Higher Computing Unit 2 – Software Unit 2 – Software Development Development

Upload: basil-wilkins

Post on 26-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Languages and Environments Higher Computing Unit 2 – Software Development

Languages and Languages and EnvironmentsEnvironments

Higher ComputingHigher Computing

Unit 2 – Software Unit 2 – Software DevelopmentDevelopment

Page 2: Languages and Environments Higher Computing Unit 2 – Software Development

What I need to knowWhat I need to know

Description and comparison of procedural, Description and comparison of procedural, declarative and event-driven languages declarative and event-driven languages

Comparison of the functions, uses and efficiency Comparison of the functions, uses and efficiency of compilers and interpreters of compilers and interpreters

Description of the features and uses of scripting Description of the features and uses of scripting language (including creating and editing a language (including creating and editing a macro) macro)

Explanation of the need for and benefits of Explanation of the need for and benefits of scripting languages scripting languages

Description of the use of module libraries Description of the use of module libraries

Page 3: Languages and Environments Higher Computing Unit 2 – Software Development

Types of LanguagesTypes of Languages

Programming languages may be classified Programming languages may be classified according to their type. according to their type.

Types of programming languages include:Types of programming languages include:

Procedural;Procedural;

Declarative; Declarative;

Event-driven; &Event-driven; &

ScriptingScripting

Page 4: Languages and Environments Higher Computing Unit 2 – Software Development

Procedural LanguagesProcedural LanguagesDefinitionDefinition A language in which the user sets out a list of A language in which the user sets out a list of

instructions in the correct sequence in order to solve instructions in the correct sequence in order to solve a problem.a problem.

FeaturesFeatures:: Data storage using variables of different data types;Data storage using variables of different data types;

Arithmetic and logical operations;Arithmetic and logical operations;

Program control using sequence, repetition and Program control using sequence, repetition and selection;selection;

Subprograms or procedures; &Subprograms or procedures; &

Data flow using parametersData flow using parameters

Page 5: Languages and Environments Higher Computing Unit 2 – Software Development

Procedural LanguagesProcedural LanguagesA program written in a procedural A program written in a procedural language has:language has:

a definite start and finish point; &a definite start and finish point; & all the steps are in a sequential order.all the steps are in a sequential order.

Here is a typical algorithm which could Here is a typical algorithm which could be easily implemented in a HLL:be easily implemented in a HLL:

1.1. Get numbersGet numbers

2.2. Calculate averageCalculate average

3.3. Display averageDisplay average

Page 6: Languages and Environments Higher Computing Unit 2 – Software Development

When a procedural language is run, the sequence When a procedural language is run, the sequence of instructions is followed from the beginning of of instructions is followed from the beginning of the program to the end in the order of the code.the program to the end in the order of the code.

For this reason, procedural languages are also For this reason, procedural languages are also known as known as imperative imperative languages, since the word languages, since the word imperative in the context of the computer imperative in the context of the computer languages means giving or expressing languages means giving or expressing commands.commands.

VB, COMAL and Pascal are examples of VB, COMAL and Pascal are examples of procedural languagesprocedural languages

Procedural LanguagesProcedural Languages

Page 7: Languages and Environments Higher Computing Unit 2 – Software Development

Declarative LanguagesDeclarative Languages

The use of a declarative language is very The use of a declarative language is very different from the use of a procedural language. different from the use of a procedural language.

Instead of giving a concise list of instructions Instead of giving a concise list of instructions set out in the correct order, a declarative set out in the correct order, a declarative language states ‘what has to be done’ rather language states ‘what has to be done’ rather than ‘how to do it’.than ‘how to do it’.

The code is written using a list of facts and The code is written using a list of facts and rules rather than telling the program what to rules rather than telling the program what to do.do.

Page 8: Languages and Environments Higher Computing Unit 2 – Software Development

Languages- declarativeLanguages- declarative

Declarative languages like Prolog, contain Declarative languages like Prolog, contain sets of statements or clauses, like this:sets of statements or clauses, like this:

cold(snow).cold(snow). means that snow is coldmeans that snow is cold

cold(ice).cold(ice). means that ice is coldmeans that ice is cold

hot(molten_lava).hot(molten_lava). means that molten lava is hotmeans that molten lava is hot

which can be used to describe rules like:which can be used to describe rules like:

melts(X,Y):-melts(X,Y):- means that X melts Y ifmeans that X melts Y if

hot(X), cold(Y).hot(X), cold(Y). X is hot and Y is coldX is hot and Y is cold

Page 9: Languages and Environments Higher Computing Unit 2 – Software Development

Languages- declarativeLanguages- declarative

The user enters The user enters queries queries into the system:into the system:

?hot(molten_lava).?hot(molten_lava). Which asks the question , isWhich asks the question , is

molten lava hot? This molten lava hot? This query would return query would return yes.yes.

?melts(molten_lave, X).?melts(molten_lave, X). This query would return X=Snow, This query would return X=Snow, X=Ice.X=Ice.

Rules of declarative languages:Rules of declarative languages: Only variables have capitals.Only variables have capitals. Must have a full stop at the end.Must have a full stop at the end.

Page 10: Languages and Environments Higher Computing Unit 2 – Software Development

Declarative LanguagesDeclarative Languages

The facts and rules in a declarative language The facts and rules in a declarative language program are known as the program are known as the knowledge baseknowledge base..

When a query is entered, the declarative When a query is entered, the declarative language looks for the solution in the knowledge language looks for the solution in the knowledge base.base.

FeaturesFeatures:: Recursion in a declarative language is equivalent to Recursion in a declarative language is equivalent to

looping in a procedural language.looping in a procedural language.

Recursion involves a rule referring to or calling itself.Recursion involves a rule referring to or calling itself.

Recursion must be used with care, because it is easy to Recursion must be used with care, because it is easy to enter an infinite loop, and if this happens, the program enter an infinite loop, and if this happens, the program may cause the computer to hang or perhaps crash.may cause the computer to hang or perhaps crash.

Page 11: Languages and Environments Higher Computing Unit 2 – Software Development

Event-Driven LanguagesEvent-Driven Languages

An event-driven language is a language An event-driven language is a language which helps you to design the user which helps you to design the user interface by placing graphics on screen. interface by placing graphics on screen. The code can then be placed within these The code can then be placed within these graphics/icons.graphics/icons.

Because of this it is much quicker to Because of this it is much quicker to design a program with a graphical user design a program with a graphical user interface when using an event-driven interface when using an event-driven language.language.

Page 12: Languages and Environments Higher Computing Unit 2 – Software Development

Event-Driven LanguagesEvent-Driven LanguagesEvent-driven languages have no definite start or Event-driven languages have no definite start or end.end.

When the program is running, the user interacts When the program is running, the user interacts with the event-driven language by selecting from with the event-driven language by selecting from a choice of screen objects like buttons, menus or a choice of screen objects like buttons, menus or windows. Clicking on one of these objects windows. Clicking on one of these objects activates the program code associated with that activates the program code associated with that object.object.

The action of clicking a screen object is called an The action of clicking a screen object is called an eventevent and the event is detected by the program. and the event is detected by the program.

Page 13: Languages and Environments Higher Computing Unit 2 – Software Development

Event-Driven LanguagesEvent-Driven LanguagesThe code below is written in the Visual Basic language:The code below is written in the Visual Basic language:

Private Sub GetName_Click()Private Sub GetName_Click()dim v_name as stringdim v_name as stringv_name = inputbox(“Please enter your name :”)v_name = inputbox(“Please enter your name :”)

End Sub End Sub

By clicking the button “GetName” we run this code.By clicking the button “GetName” we run this code.Runrev is also an event-driven languageRunrev is also an event-driven language

On MouseUpOn MouseUplocal v_namelocal v_nameask (“Please enter your name :”)ask (“Please enter your name :”)put it into v_nameput it into v_name

End MouseUpEnd MouseUp

Page 14: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting Languages

Features of scripting languageFeatures of scripting language Scripting languages may be divided into two Scripting languages may be divided into two

types:types:

those which are embedded within an application those which are embedded within an application package and which make use of only those package and which make use of only those commands which are available within the commands which are available within the package.package.

those which work with the operating system and those which work with the operating system and across and between suitable applications. across and between suitable applications.

Page 15: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting Languages

Uses of a scripting languageUses of a scripting language

The provisions of a scripting language allows The provisions of a scripting language allows the user to tailor an application package to the user to tailor an application package to carry out additional operations other than carry out additional operations other than those provided in the original menus. those provided in the original menus.

Scripting languages use commands from Scripting languages use commands from application packages in order to do this.application packages in order to do this.

Examples of scripting languages include Examples of scripting languages include Visual Basic for Applications (VBA), JavaScript Visual Basic for Applications (VBA), JavaScript and Perl. and Perl.

Page 16: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting Languages

A user of an application package would A user of an application package would use a scripting language to automate a use a scripting language to automate a complex task that has to be carried out complex task that has to be carried out many times. many times.

The user would then active the script by The user would then active the script by clicking a button or a keystroke rather clicking a button or a keystroke rather than going through the task manually.than going through the task manually.

Programs written using a scripting Programs written using a scripting language are often called language are often called macrosmacros..

Page 17: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting Languages

A A macromacro is a set of keystrokes and is a set of keystrokes and instructions that are recorded, saved and instructions that are recorded, saved and assigned to a single or combination of assigned to a single or combination of keys. keys.

When the key code is typed, the recorded When the key code is typed, the recorded keystrokes and instructions are carried keystrokes and instructions are carried out.out.

Page 18: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting LanguagesCreating a macroCreating a macro

A macro may be created either by recording a sequence of keystrokes A macro may be created either by recording a sequence of keystrokes and mouse actions or by entering a suitable script in an appropriate and mouse actions or by entering a suitable script in an appropriate language into an editor.language into an editor.

This macro, in Excel, creates a simple spreadsheet which adds 2 This macro, in Excel, creates a simple spreadsheet which adds 2 numbers.numbers.

Sub Example()Sub Example()‘‘Keyboard shortcut: option+cmd+shift+AKeyboard shortcut: option+cmd+shift+ARange(“B2”).SelectRange(“B2”).SelectActiveCell.FormulaR1C1 = ‘number one’ActiveCell.FormulaR1C1 = ‘number one’Range(“B3”).SelectRange(“B3”).SelectActiveCell.FormulaR1C1 = ‘number two’ActiveCell.FormulaR1C1 = ‘number two’Range(“C5”).SelectRange(“C5”).SelectActiveCell.FormulaR1C1 = ‘=SUM(R[-3]C:R[-2]C)’ActiveCell.FormulaR1C1 = ‘=SUM(R[-3]C:R[-2]C)’Range(“B5”).SelectRange(“B5”).SelectActiveCell.FormulaR1C1 = ‘total’ActiveCell.FormulaR1C1 = ‘total’

End SubEnd Sub

Page 19: Languages and Environments Higher Computing Unit 2 – Software Development

Scripting LanguagesScripting Languages

Editing a macroEditing a macro A macro may be edited by making changes A macro may be edited by making changes

to its code and saving the new version. to its code and saving the new version.

The need for scripting languagesThe need for scripting languages arises from the requirements arises from the requirements to be able to make changes to the commands or menus, or to to be able to make changes to the commands or menus, or to automate tasks within an application package or an operating automate tasks within an application package or an operating system.system.

BenefitsBenefits:: They allow application packages to be enhanced with additional They allow application packages to be enhanced with additional

commands; commands;

They automate tasks for an expert user; &They automate tasks for an expert user; & They allow a beginner to perform tasks that they would not otherwise They allow a beginner to perform tasks that they would not otherwise

be able to undertake.be able to undertake.

Page 20: Languages and Environments Higher Computing Unit 2 – Software Development

TranslatorTranslator

DefinitionDefinition A translator is a computer program used to convert A translator is a computer program used to convert

high level program code to machine code.high level program code to machine code.

Translators are used because it is very difficult Translators are used because it is very difficult to write programs directly into machine code to write programs directly into machine code (all 0’s and 1’s). It is easier for the programmer (all 0’s and 1’s). It is easier for the programmer to write the program in an HLL and use a to write the program in an HLL and use a translator to change it into machine code.translator to change it into machine code.

There are two type of translator programs that There are two type of translator programs that we need to know about:we need to know about: Compilers; &Compilers; & Interpreters.Interpreters.

Page 21: Languages and Environments Higher Computing Unit 2 – Software Development

CompilersCompilersA compiler translates a high level language A compiler translates a high level language program, the program, the source codesource code, into machine code , into machine code which is the which is the object code.object code.

The complier changes each single high level The complier changes each single high level language instruction into several machine code language instruction into several machine code instructions. instructions.

Compilation involves analysing the source code, Compilation involves analysing the source code, checking to see if it is correct and producing checking to see if it is correct and producing the object code.the object code.

These separate compilation stages are known These separate compilation stages are known as lexical analysis, syntax analysis and code as lexical analysis, syntax analysis and code generation.generation.

Page 22: Languages and Environments Higher Computing Unit 2 – Software Development

CompilersCompilers

Once a program has been compiled and is Once a program has been compiled and is working properly the user will run the program working properly the user will run the program from the object code which can be saved and from the object code which can be saved and run separately from the source code.run separately from the source code.

This means that when the program runs it does This means that when the program runs it does not need to be re-translated which means that not need to be re-translated which means that it is more efficient on memory and processor.it is more efficient on memory and processor.

Machine code is specific to a processor. This Machine code is specific to a processor. This means that machine code that runs on an Intel means that machine code that runs on an Intel will not work on an AMD. Machine code will not work on an AMD. Machine code programs are not portable.programs are not portable.

Page 23: Languages and Environments Higher Computing Unit 2 – Software Development

InterpretersInterpreters

An interpreter translates and runs a high level An interpreter translates and runs a high level language program on instruction (or statement) language program on instruction (or statement) at a time.at a time.

No object code is produced.No object code is produced.

Interpreted programs run slower than compiled Interpreted programs run slower than compiled programs because each line must be translated programs because each line must be translated every time the program is run. If the program every time the program is run. If the program has a fixed loop which runs 10 times the code has a fixed loop which runs 10 times the code will be interpreted 10 times.will be interpreted 10 times.

An interpreter will report any syntax errors in An interpreter will report any syntax errors in the code as it is being developed.the code as it is being developed.

Page 24: Languages and Environments Higher Computing Unit 2 – Software Development

InterpreterInterpreter

Interpreted programs use more memory than compiled programs because the interpreter and source code must be present in the computer’s memory when the program is run.

Whereas with a compiled program only the object code is loaded into memory and run.

Page 25: Languages and Environments Higher Computing Unit 2 – Software Development

Comparison of TranslatorsComparison of Translators

InterpretedInterpreted Compiled Compiled

Run slowRun slow Run fastRun fast

Report mistakes immediatelyReport mistakes immediately Report mistakes at end of Report mistakes at end of compilationcompilation

Translate and run in a single Translate and run in a single processprocess

Translate and run are separate Translate and run are separate processesprocesses

Cannot save translated Cannot save translated versionversion

Can save object codeCan save object code

Interpreter required to run Interpreter required to run codecode

Compiler not required to run Compiler not required to run codecode

Page 26: Languages and Environments Higher Computing Unit 2 – Software Development

Comparison of TranslatorsComparison of Translators

Source Code(HLL program)

Compiler

Object Code(A Machine code

Program)

Source Code(single line of HLL)

Interpreter

Machine Code Instructions

Compiler Interpreter

ReportsErrors

ReportsErrors

GetNext

Instructions

Object code is not executed immediately

and can be saved

Each instruction is executed immediately and cannot be saved.

Page 27: Languages and Environments Higher Computing Unit 2 – Software Development

Use of compilers and Use of compilers and interpretersinterpreters

When a program that uses an interpreter is When a program that uses an interpreter is being created, both the source code and being created, both the source code and interpreter are required to write, edit, test interpreter are required to write, edit, test and use the completed program.and use the completed program.

When a compiled program is being When a compiled program is being created, the source code and the compiler created, the source code and the compiler are needed at the writing and editing are needed at the writing and editing stages; the source code, object code and stages; the source code, object code and compiler are required at the testing stage compiler are required at the testing stage and only the object code is required to use and only the object code is required to use the completed program.the completed program.

Page 28: Languages and Environments Higher Computing Unit 2 – Software Development

Module LibrariesModule Libraries

A module library is part of a software A module library is part of a software library. library.

A software library is a collection of A software library is a collection of software held permanently accessible on software held permanently accessible on backing storage.backing storage.

A software library will typically include A software library will typically include complete programs, a module library and complete programs, a module library and a set of machine code routines, which a set of machine code routines, which may be loaded into user programs when may be loaded into user programs when required.required.

Page 29: Languages and Environments Higher Computing Unit 2 – Software Development

Module LibrariesModule Libraries

Using a module library speeds up the Using a module library speeds up the whole software development process whole software development process because time is saved in design, because time is saved in design, implementation, testing and implementation, testing and documentation.documentation.

Saving time in design. Saving time in design. Using a module library saves time in program Using a module library saves time in program

design because the design has already been design because the design has already been created when the module was created in the created when the module was created in the first place.first place.

Page 30: Languages and Environments Higher Computing Unit 2 – Software Development

Module LibrariesModule Libraries

Saving time in implementation. Saving time in implementation. A programmer would not write a procedure each A programmer would not write a procedure each

time it was needed, the procedure would simply be time it was needed, the procedure would simply be loaded from a module library.loaded from a module library.

Saving time in testing. Saving time in testing. All of the modules in a module library are already All of the modules in a module library are already

tested and known to be free from errors. tested and known to be free from errors.

Saving time in documentation. Saving time in documentation. Each module in a module library is already fully Each module in a module library is already fully

documented. documented.