choosing the write programming language for the job. the choice of language may be based on: the...
TRANSCRIPT
Choosing the write programming language for the job.
The choice of language may be based on:
• The experience and expertise of the development team. • The range of languages and development platforms available to the organisation.• Which language has the facilities most appropriate to solving the required problem.• A suitable compiler/interpreter available for the client hardware.• If the task requires text processing, for example, a language which supports data of type string is necessary. • A language which supports arithmetic, logical operators, sound or graphics may be necessary.• Another factor is portability. A program is portable to the extent that it can be used on different computer hardware. If the programs are in the form of machine code a program compiled into machine code on a PC will not be executable on a different machine, eg Apple Macintosh.
Development Languages and Environments
Programming languages are classified according to their structure and purpose.
Types of languages include:
• Procedural/Imperative
• Declarative
• Event Driven
• Scripting
Language classification
Language Structure Purpose
Pascal imperative general purpose language, widely used
Visual BASIC
imperative windows interface applications, multimedia
PROLOG declarative artificial intelligence
Visual C++event-driven
used as front end to develop user interface
COBOL imperative business use
Javaobject-oriented
platform independent - an object oriented language
VBscript scripting creating and editing macros
FORTRAN 90
object-oriented
scientific and software engineering
Lisp functionalartificial intelligence uses - many other languages are derived from it
JavaScript scripting writing and enhancing web pages
BASIC imperativeeasy to learn, originally developed to teach non-specialists the art of programming
FORTRAN imperative scientific programming language
NOTE!Although Visual basic is listed as an imperative language it can also be classed as an event-driven language and also an object-oriented language.
Procedural Languages
Procedural languages employ structures which include procedures and functions. Programs generated in procedural languages involve a sequence of operations and are often described as linear programs.
They will have clearly-defined start and end points, with each instruction leading on to the next.
The sequence:
1. Get Numbers
2. Calculate Average
3. Display Average
4. END
Features:
• Data Storage using variables of different types (integer, real, string, Boolean)
• Arithmetic and logical operations (+, -, *, AND, OR, NOT)
• Program control using sequence, repetition and selection (three basic constructs)
• Subroutines (procedures and functions) with passing parameters
• Built in functions (Int, rnd)
Declarative Language
Very different from procedural language as they treat the computer in an entirely different way.
The computer is treated not as a machine that can process data but as a machine that can perform logic and produce an answer.
Design and Implementation
Declarative languages allow the programmer to create a knowledge base which contains facts and rules.
Statements or clauses can be used to describe facts and rules within a knowledge based system.
Declarative Language cont…
The programmer declares relationships between items in the hope that the system will produce a result.
Example Language – Prolog (Programming in logic)
Usage
A typical program consists of a database and a set of rules. The items in the database are known as facts.
A query/search is then used to interrogate the knowledge base and draw conclusions.
Has(flute, holes)Has(trumpet,values)Has(trombone,slide)Has(fiddle,string)
Instruments
Wind String
Brass
HolesBlowing BowingStrings
Values Blowing
Plucked
hasplayed by
has
played byplayed by
played by
has
Played(fiddle, bowing)Played(guitar,plucking)
The programmer would need to set up a structure to hold the knowledge and predefine its type (string, number etc).
A declarative/logical language is simplistically described as telling the computer what to do and not how to do it.
A declarative language will find a pattern matching the query with the stored rules
Features• Problems can be defined in terms of facts and rules• Rules can be applied to inputs to give yes/no or true/false response.• Queries/searches will find a pattern matching the query with the stored rules• No rigid control structures are used.
Event Driven
Programs would be written in terms of procedures, which would process, or operate, on, the data passing through. – Procedural
Programs were sequential, starting at the beginning of the code and running to completion, branching and looping according to the program instructions.
ProblemsAs programs became more complex it became unmanageable to write these programs using a procedural language.
Windows is an event driven environment and user interaction is required in the form of a mouse click or a key press.
Procedural languages do not posses the necessary constructs to deal with this style of programming and are generally unsuitable for building windows applications.
Event driven and object orientated programming techniques overcome this problem.
Program modules are written and are tied to buttons or other on-screen objects, This code is run when the user of the software performs and action.
An event could be the user clicking on a command button, text being changed in a text box, a window or menu being opened.
Visual Basic is an example of an event driven language
Features
• provide a graphical user interface
• do not have a predefined pathway in the execution of the code, as opposed to imperative programming style i.e. they have no beginning or end.
• The user executes an event, such as, a mouse click or key press.
Scripting Language
Also like procedural languages, in that they use variables, etc to create programs to carry out tasks.
Programming language provided with an application package to allow the user to go beyond the features available in the application. The user can customise a package.
Examples
• VB for applications
• Javascript
• Perl
An expert of an application would use a scripting language to automate a repetitive task. The programs created in the application are known as Macros.
JavaScript
Perhaps the most publicised and well-known scripting language was initially developed by Netscape as LiveScript to allow more functionality and enhancement to web page authoring that raw HTML could not accommodate.
A standard version of JavaScript was later developed to work in both Netscape and Microsoft's Internet Explorer, thus making the language to a large extent, universal. This means that JavaScript code can run on any platform that has a JavaScript interpreter.
Use
• Image or text rollovers
• Creating a pop-up window
VB for application
Most general purpose packages have some sort of scripting or macro capability.
The use of VB to perform script in Microsoft Excel and Access. These will simplify the execution of searches and other complex or frequently used functions.
Macro
Created
A series of commands, keyboard or mouse actions that are recorded and performed automatically when a certain key is pressed or a certain command is entered.
Type of QuestionQ. State two methods of creating a macro.
A. Record a series of key presses, menu choices and mouse clicks.Or using the application based scripting language.
Edited
Changes can be made to the code of a Macro to create a new version.
Why is there a need for Scripting?
Web Based
The market for producing dynamic web content is now expanding extremely rapidly such that new scripting languages have been developed to allow users with little or no programming expertise to develop interactive web pages with minimum effort.
Advantages
• Allows applications packages to be enhanced
• Beginner can perform tasks that they would not have otherwise be able to undertake.
• This saves you time by replacing an often-used, sometimes lengthy series of actions with a shorter action.
Translator Programs
A program used to convert a program code from one language to another.
Example:
High Level Language (Visual Basic)
Translator
Machine Code
Reminder – Credit Standard Grade
High Level Language
A computer language which is easily read by humans - the code consists of English-like words where each statement corresponds to several machine language instructions.
Machine Code
The computers own language, made up of 0’s and 1’s. The computers processor only understands machine code.
Problem!
How does the processor understand high level language programs?
Answer
Computer scientists developed translator programs.
There are three types of translator programs:
• Assembler
• Compiler
• Interpreter
For higher we will study Compliers and Interpreters.
Compiler
A complex program in itself, translates source code into object code that is then loaded into main memory and executed.
The compiler translates the whole program into machine code once.
Once translated it can be used over and over again without the need for translation.
High Level Language (source code)
Compiler
Machine Code
(object code)
Advantage
• Runs quicker than a Interpreter
• Once translated the user does not need the translator program on their own computer.
Source Code
Original HLL version of the program
Object Code
Compiled machine code version of the program
High Level Language (source code)
Compiler
Machine Code
(object code)
Games or application programs will have been compiled into machine code before being distributed.
Interpreter
Translates and runs a HLL program one instruction at a time.
No object code is produced.
High Level Language (source code)
Compiler
Machine Code
Disadvantage
Runs slower then complied programs because each line must be translated every time.
Advantages
Reports mistakes in the code as it is being developed, rather than waiting until the end.
Comparing Interpreted programs and compiled programs
Compilers
• Requires the program to be compiled separately and then run
• Runs fast
• Reports mistakes at end of compilation
• Translate and run are separate processes
• Can save object code
• Compiler not required to run code.
Interpreters
• Uses a single process
• Interpreter programs are popular with students and others learning.
• Tend to use more memory because both programs must be present in memory
• Runs slower
• Reports mistakes immediately
• Translate and run is a single process
• Cannot save translated version
• Interpreter required to run the code
Text Editors
Allows a programmer to enter and edit the source code for a program.
Some text editors come with predictive typing. Which helps complete the program.
Modularity
Program is designed and written, it is divided into smaller sections called subprograms or subroutines.
Advantage
• can divide it between programmers and work on a bit each
• break problem into smaller more manageable parts
• can test modules separate first, before joining together
• can use passing parameters
• improves readability – find mistakes
• the repetition of lines of code are avoided.
• More useable - procedure code can be saved and re-used in future projects
Our minds work better when we can focus on
smaller tasks
Two types of Modules or sub programs are:
• Procedures
• Functions
Don’t be confused with types of module design:
• Stepwise Refinement (Top-down design)
• Bottom-up design
Procedures
Is a portion of code within a larger program, which performs a specific task (effect) and is relatively independent of the remaining code.
Procedures must be defined before the program can use it. Defining a procedure gives it a name and states the data required to passed in and out of the procedure
How it works?
1. Data is passed (data flow) to a procedure using parameters.
The flow of data between procedures, functions and the main program block is accomplished by the use of parameters, which will be discussed later.
2. The procedure carries out the operation using the data
3. Makes the results available to the program.
Functions
Similar to a procedure, but returns a value to a program.
Functions MUST return a value, procedures doesn't need to.
Pre-Defined Functions
Functions built into the programming language.
It is possible to create your own function which is not provided in the language. These are called user-defined functions.
Module Libraries (Software Library)A collection of pre-written subroutines that are available to a programmer.
Exist for algorithms that come up time and time again in program such as sorting an array or validating an item of data.
Advantages
1. Time is saved in not having to write the same programming code over and over again.
2. Modules will be tried and tested and free from errors.
3. Full documented with function of module.