Computer Programming CONTENTS • • • • • Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming skills in perl Perl applications in bioinformatics Software Categories • System SW – Programs written for computer systems • Compilers, operating systems, … • Application SW – Programs written for computer users • Word-processors, spreadsheets, & other application packages Operating system • The set of software that controls the overall operation of a computer system, typically by performing such tasks as memory allocation, job scheduling, and input/output control • Software designed to control the hardware of a specific data-processing system in order to allow users and application programs to make use of it. OS Tasks The operating system's tasks, in the most general sense, fall into six categories: i. ii. iii. iv. v. vi. Processor management Memory management Device management Storage management Application interface User interface Language • The purpose of language is simply that it must convey meaning. (Confucius) • That which can be said, can be said clearly. (Wittgenstein,1963) • A program is a specification of a computation. A programming language is a notation for writing programs.(Sethi,89) What is a programming language? • A language that is intended for the expression of computer programs and that is capable of expressing any computer program. 7 What is Programming • Program – a very specific set of instructions (or command lines) that making a computer do what you want it to do • Programming – the process of creating a program – the development of a solution to an identified program, and setting up of a related series of instructions which, when directed through computer hardware, will produce the desired results Differences or Similarities • Natural Language – Grammar – Vocabulary – Sentences • Programming Language – Syntax – Objects, data types – Commands Steps in program development 1. 2. 3. 4. 5. Define the problem Outline the solution(pseudocode) Develop the outline into an algorithm Test the algorithm for correctness Code the algorithm into a specific programming language 6. Run the program on the computer 7. Document and maintain the program Define the Problem • Divide the problem into three components (called IPO): – Inputs – what do you have? – Outputs – what do you want to have? – Processing • how do you go from inputs to outputs? • A defining diagram is recommended Outline the Solution • The major processing steps involved • The major subtasks (if any) • The major control structures (e.g. repetition loops) • The major variables and record structures • The mainline logic Develop the Outline into an Algorithm • Algorithm is a set of precise steps that describe exactly the tasks to be performed, and the order in which they are to be carried out • Pseudocode (a form of structured English) is used to represent the solution algorithm Test the Algorithm for Correctness • The main purpose of desk checking the algorithm is to identify major logic errors early, so that they may be easily corrected • Test data needs to be walked through each step in the algorithm, to check that the instructions described in the algorithm will actually do what they are supposed to Code the Algorithm into a Specific Programming Language • Only after all design considerations have been met should you actually start to code the program into your chosen programming language (e.g. Visual Basic, Java, C++) Run the Program on the Computer • This step uses a program compiler and programmerdesigned test data to machine test the code for syntax errors • Program complier translate high-level languages (e.g. VB) to low-level machine language before execution Document and Maintain the Program • Not the last step in the program development process • An ongoing task from the initial definition of the problem to the final test result • Involves both external documentation (such as hierarchy charts) and internal documentation that may have been coded in the program How do Programming Languages Differ? Common Constructs: • basic data types (numbers, etc.); variables; expressions; statements; keywords; control constructs; procedures; comments; errors ... Uncommon Constructs: • type declarations; special types (strings, arrays, matrices, ...); sequential execution; concurrency constructs; packages/modules; objects; general functions; generics; modifiable state; ... Pseudocode vs Algorithm • Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading. • Algorithm Procedure that produces the answer to a question or the solution to a problem in a finite number of steps. In mathematics, computing, and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state. Problem 1 A program is required to read three numbers, add them together and print their total. • Defining diagram Input Number1 Number2 Number3 Processing Prompt for input numbers Get input numbers Apply addition Display total Output total Solution Pseudocode Begin Program Get number1 Get number2 Get number3 Total = number1 + number2 + number3 Display total End Program Problem 2 • A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, and calculate and display to the screen the average temperature, calculated by (maximum temperature + minimum temperature)/2. • Defining diagram Input Max_temp Min_temp Processing Output Prompt for temperatures Avg_temp Get temperatures Calculate average temperature Display average temperature Solution Pseudocode Begin program Get max_temp, min_temp Avg_temp= (max_Temp + min_temp)/2 Output avg_temp to the screen End Program Problem 3 • Calculate the circumference and area of a circle • Defining diagram Input Radius pi Processing Output Get radius, pi Circumfere Calculate circumference = 2 * P nce I* radius Calculate 2 area=PI * radius ^ Display circumference, area area Solution Pseudocode Begin program get radius, PI circumference = 2 * P I* radius area=PI * radius * radius display circumference, area End program Attributes of a good language 1. Clarity, simplicity, and unity – Have a minimum number of different concepts, with the rules for their combination, simple and regular (conceptual integrity). – readability 2. Orthogonality – Being able to combine various features of a language in all possible combinations. 3. Support for abstraction 29 Attributes of a good language 4. Ease of program verification – Proof of correctness, desk checking, test – Simplicity of semantic and syntax 5. Programming environment 6. Portability of programs 7. Cost of use – – – – Program execution Program translation Program creation, testing, and use Program maintenance 30 Attributes of a good language (another view: to make a software reliable, maintainable, efficient) • Reliability – – – – – Writability Readability Simplicity Safety (no goto, no pointers) Robustness (undesired events can be trapped, like arithmetic overflow, invalid inputs) • Maintainability – Factoring (modularity) – Locality • Efficiency Jazayeri 31 Can you answer these questions? • • • • • • • What is an OS? PL? Pseudocode vs Algorithm? Steps involved in programming? Attributes of good PL? How do PL differ? Write pseudocode for a given problem? Assignment • Uses of internet as biologists • Single page