Computing Science Software Design and Development Languages and

  • Slides: 39
Download presentation
Computing Science Software Design and Development Languages and Environments

Computing Science Software Design and Development Languages and Environments

Learning objectives Learning Objectives • By the end of this topic you will be

Learning objectives Learning Objectives • By the end of this topic you will be able to: • ; • understand the difference between high level and low level programming languages • know that all programming languages can be reduced to three basic control structures: sequence, selection and iteration; • appreciate that programming languages can be classified in a number of different ways; •

Learning objectives Learning Objectives • By the end of this topic you will be

Learning objectives Learning Objectives • By the end of this topic you will be able to: • ; • explain the differences between procedural, declarative, objectoriented and domain-specific languages; • understand the difference between two types of translation software: compilers and interpreters; • describe the tools a programmer would expect to be available in a modern programming environment. •

High level and low level programming languages • Low-Level languages are the languages which

High level and low level programming languages • Low-Level languages are the languages which the computer understands directly such as machine code. They consist of binary codes. • High-Level languages have to be translated into machine code before they can be understood by the computer

Control Structures: Sequence, selection and repetition • Sequence: commands will be executed one after

Control Structures: Sequence, selection and repetition • Sequence: commands will be executed one after the other. • Selection: execution depends on whether a condition is true or not. • Iteration: a set of commands is repeated for a set number of times, often called a loop.

Programming Classification There a large number of programming languages (more than 2000). One way

Programming Classification There a large number of programming languages (more than 2000). One way to classify them is by how they are used • • Procedural Declarative Object Oriented Domain specific

Procedural languages • Commonest type of language • Programs are a sequence of commands

Procedural languages • Commonest type of language • Programs are a sequence of commands executed in a predictable order. Earliest languages used line numbers • Provide standard operations like: + - * / AND NOT OR

Procedural Languages • Use Control structures like: • For. . Next • IF. .

Procedural Languages • Use Control structures like: • For. . Next • IF. . Then • While. . Do • Provide Data structures like: • • Real Integer String Array

Procedural Language Examples – Basic – Pascal –C – Cobol – Fortran

Procedural Language Examples – Basic – Pascal –C – Cobol – Fortran

Declarative Languages • Lets the user describe the problem to be solved in terms

Declarative Languages • Lets the user describe the problem to be solved in terms of facts and rules. T he user specifies what the problem is, not how to solve it. • Are often used to solve logical problems • Consists of a database (facts and rules) and an inference engine • Have fewer variable types and control structures than procedural languages

Prolog Example - Using facts, rules and queries Suppose we want to find out

Prolog Example - Using facts, rules and queries Suppose we want to find out whether a person drives a fast car. We start by building a set of facts and rules for our knowledge base. person(judy). - this is the fact that Judy is a person(james). drives_car(james, ford_escort). drives_car(judy, porsche). - this is the fact that Judy drives a Porsche drives_fast_car(X): - drives_car(X, Y) and Y = "porsche"

Prolog Example - Using facts, rules and queries In this example we could ask

Prolog Example - Using facts, rules and queries In this example we could ask the program to tell us whether Judy drives a fast car by typing the query: ? drives_fast_car(judy). The result would be YES since the goal is satisfied.

Prolog Example - Using facts, rules and queries If we asked: ? drives_fast_car(james) then

Prolog Example - Using facts, rules and queries If we asked: ? drives_fast_car(james) then the result would be NO as drives_car(james, Y) would evaluate Y="ford escort". This would then cause the rule drives_fast_car(james) to fail as Y does not equal "porsche" and the goal is not satisfied.

Declarative Language Examples • Lisp • Prolog

Declarative Language Examples • Lisp • Prolog

Object Oriented Programming (OOP) Need for Object Oriented Programming • Size of programs makes

Object Oriented Programming (OOP) Need for Object Oriented Programming • Size of programs makes traditional programming methods unmanageable • Difficulty in controlling data flow, especially where global variables involved • Even with more modern design techniques, very difficult to make changes to designs of programs once development has started

Object oriented programming concepts • • • Objects Classes Inheritance Encapsulation Polymorphism

Object oriented programming concepts • • • Objects Classes Inheritance Encapsulation Polymorphism

Objects are self-contained data structures that consist of properties, methods, and events. – Properties

Objects are self-contained data structures that consist of properties, methods, and events. – Properties specify the data represented by an object (sometimes called states) – Methods specify an object’s behavior – Events provide communication between objects

Objects Think of the person sitting beside you • They have properties (name, sex,

Objects Think of the person sitting beside you • They have properties (name, sex, , height etc) • They have methods (sleeping, talking, reading etc) Now think of a button in a VB program It has properties (size, position, text etc) It has methods associated with it (drag, drop, resize etc)

Objects are considered as a single unit with both the properties and the methods

Objects are considered as a single unit with both the properties and the methods being integral unlike in traditional programming where the data (properties) is separate from the code that manipulates it (methods)

Classes • A class defines a blueprint for an object. • A class defines

Classes • A class defines a blueprint for an object. • A class defines how the objects should be built and how they should behave. • An object is also known as an instance of a class.

Base Class H Computing pupils Sub class Claire Sub class Sam Sub class Craig

Base Class H Computing pupils Sub class Claire Sub class Sam Sub class Craig Here each member of the sub-class shares common features with the base class

Inheritance • Inheritance is an OOP feature that allows you to develop a class

Inheritance • Inheritance is an OOP feature that allows you to develop a class once, and then reuse that code over and over as the basis of new classes. • The class whose functionality is inherited is called a base class. • The class that inherits the functionality is called a derived class • A derived class can also define additional features that make it different from the base class.

Inheritance Base Class H Computing pupils Properties – • Passed Nat 5 Computing •

Inheritance Base Class H Computing pupils Properties – • Passed Nat 5 Computing • In S 5 or S 6 • In School Methods • Read English • Write English • Always does homework • Prepared to bribe teacher for a good grade

Inheritance Sub class Claire Inherits all Properties and methods from the base class but

Inheritance Sub class Claire Inherits all Properties and methods from the base class but can have some of her own Properties Female Methods Listens to music when writing English essays

Inheritance • A sub – class (or derived class) will have all the properties

Inheritance • A sub – class (or derived class) will have all the properties and methods of the base class. • This makes it easy to edit large programs. If an error is found in a base (or super) class then correcting it there will also correct it in each of the sub-classes

Encapsulation • Objects communicate with each other using events which pass messages from one

Encapsulation • Objects communicate with each other using events which pass messages from one object to another. • There is no direct contact with either the properties or the methods in the objects – the outside can use the properties and methods of an object but cannot change them. • This is known as encapsulation

Polymorphism • Two or more classes derived from a base class are said to

Polymorphism • Two or more classes derived from a base class are said to be polymorphic. • Polymorphism allows two objects to respond to the same method in different ways. • In our example, when it is lunchtime, Claire goes to the Fuel Zone while Sam goes to the chip shop.

Domain Specific Languages • Domain Specific languages are procedural languages designed for a specific

Domain Specific Languages • Domain Specific languages are procedural languages designed for a specific task • Language will have specific commands and control structures suited to this task • These shorten development time and make development easier

Domain Specific Languages Examples of domain specific languages • HTML – describes the layout

Domain Specific Languages Examples of domain specific languages • HTML – describes the layout and structure of web pages • SQL – used for interrogating databases

Domain Specific Languages Scripting languages areused to add functionality to existing applications or operating

Domain Specific Languages Scripting languages areused to add functionality to existing applications or operating systems Examples • Visual Basic for Applications (VBA) – allows users to program additional features into Office programs like Excel and Access • Javascript – adds interactivity to web pages

Translation software Programs written in a high level language have to be translated into

Translation software Programs written in a high level language have to be translated into machine code before a computer can execute them Two types of translators for high level languages • Interpreters • Compilers

Translation software • Compiler: Translates the program source code into machine code all in

Translation software • Compiler: Translates the program source code into machine code all in one go. • Interpreter: Translates the program source code into machine code line by line.

Why use an Interpreter? • Because it translates the source code line by line,

Why use an Interpreter? • Because it translates the source code line by line, it can tell you if something is wrong with a line as you are writing it • Because it translates line by line, it can be used to test parts of a program while it is still being written

Disadvantages of an Interpreter • You need both the interpreter and the source code

Disadvantages of an Interpreter • You need both the interpreter and the source code every time you run the program • Because it needs to be translated every time it is run, the program runs much slower than a compiled program

Why use a Compiler? • Once translated, the program can be run on any

Why use a Compiler? • Once translated, the program can be run on any machine which understands that version of machine code. • It runs faster than a program which has to be translated line by line every time it is used. • No one can see or copy the original program code.

Disadvantages of a compiler • You need to re-translate a program every time you

Disadvantages of a compiler • You need to re-translate a program every time you make a change to it • A compiler does not help you understand what is wrong with a program when you are writing and testing it

Best of both Worlds! • Use an interpreter to write and test your program

Best of both Worlds! • Use an interpreter to write and test your program • Use a compiler to translate the source code once it is complete and you are ready to distribute it

Programming Tools • Text Editor: – Predictive typing – Search and Replace – Highlights

Programming Tools • Text Editor: – Predictive typing – Search and Replace – Highlights Key-words and documentation – Indents code • Debugging: – Breakpoints – Watch – Trace

Programming Tools Module and class libraries • A collection of modules which can be

Programming Tools Module and class libraries • A collection of modules which can be re-used when writing software. A module will include documentation and test results. • Save: – Design time – Implementation time – Testing time