Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Art of Programming Program design and implementation.

Similar presentations


Presentation on theme: "The Art of Programming Program design and implementation."— Presentation transcript:

1 The Art of Programming Program design and implementation

2 I have a computational problem. What should I do first ? 1.Go straight to the keyboard and start typing. 3.Check that someone else hasn’t already done it! * *(and if they have, it doesn’t cost too much)? 2.Think about the problem, design on paper the structure of the program, then start typing.  

3 Writing a program – design, strategies and implementation 1.Analysing the problem  What do I need to do? 2.Unstructured programming 3.Program design with structured programming  pseudo code  program blocks and flow-schemes 4.Object-oriented programming (OOP) for complex projects  defining the problem in terms of objects

4 Problem analysis Define carefully what you want to do, writing it down if necessary. Ask yourself: –Is it feasible? (Protein folding is difficult, particularly in Perl!) –Has it been done before ? Check literature, web etc for similar work. Check software archives or libraries for programs that do similar things. Apart from bioinformatic sources, the CPAN site contains an extensive list of free Perl libraries and routines: http://www.cpan.org

5 Unstructured programming All the program code written in a single continuous main program. Many disadvantages for large programs difficult to follow logic if something needs to be done more than once must be re-typed hard to incorporate other code not easily modified difficult to test particular portions of the code... Many disadvantages for large programs difficult to follow logic if something needs to be done more than once must be re-typed hard to incorporate other code not easily modified difficult to test particular portions of the code...

6 Structured programming Structured or procedural programming attempts to divide the problem into smaller blocks or procedures which interact with other. The aim is to clearly define the structure of the program before writing program code. (At this stage we could also decide to attach pre-written libraries or other programs) Structured or procedural programming attempts to divide the problem into smaller blocks or procedures which interact with other. The aim is to clearly define the structure of the program before writing program code. (At this stage we could also decide to attach pre-written libraries or other programs)

7 Stuctured programming Ideally each block should be a black box –should carry out a well-defined task, interacting with other blocks only through definite inputs and outputs. input output PROGRAM FLOW

8 Structured programming 1.Write pseudo-code if desired to define the problem. 2.Decide on the program blocks, specifying the inputs and outputs for each blocks. 3.Refine and see if the larger blocks can be in turn sub-divided into smaller blocks. 4.Now you can start programming..just fill in the blocks with computer code ! 1.Write pseudo-code if desired to define the problem. 2.Decide on the program blocks, specifying the inputs and outputs for each blocks. 3.Refine and see if the larger blocks can be in turn sub-divided into smaller blocks. 4.Now you can start programming..just fill in the blocks with computer code ! Strategy

9 Structured Programming - Example Problem: From a FASTA file, extract the DNA sequence data and translate in all six reading frames.

10 DNA translation – pseudo code read sequence data from file –read what is in file –extract sequence data (i.e. remove FASTA headers and comments) for each reading frame –translate DNA to peptide –loop over codons and translate each codon to aminoacid or stop print results read sequence data from file –read what is in file –extract sequence data (i.e. remove FASTA headers and comments) for each reading frame –translate DNA to peptide –loop over codons and translate each codon to aminoacid or stop print results

11 DNA Translation -Block diagram get sequence data from file translate each OF to protein print results read file extract sequence select codon translate to aa loop over codons loop over OFs

12 Each box has well-defined input and outputs – information should only pass through these points translate each OF to protein CCGGTAGCCTCCAGGTC.. PVTPSELPRPRRPLPTQQQPQ.. DNA input protein output

13 Implementing structural design In terms of program code, there is usually a main program and calls are made to the routine from this loop (which may call other routines, etc.) After each routine has finished the computer returns to the point right after the call. In terms of program code, there is usually a main program and calls are made to the routine from this loop (which may call other routines, etc.) After each routine has finished the computer returns to the point right after the call.

14 DNA translation – advanced pseudo code # NOT VALID PERL # main program call get sequence loop over OFs call convertDNA end loop call results end program # NOT VALID PERL # main program call get sequence loop over OFs call convertDNA end loop call results end program get sequence call read data call del_headers get sequence call read data call del_headers convertDNA loop over codons call tr_codon end loop convertDNA loop over codons call tr_codon end loop results printresults results printresults read_data del headers tr_codon

15 complex block diagrams EXIT utility routine START

16 Structured programming - summary Structured programs divide the problem into smaller sub-units or blocks, then divided into smaller blocks.. eventually reaching the level of program code. The blocks should ideally be self-contained – interactions with other blocks should be explicit ALL programming languages support Structured Programming to some extent Useful model for small-medium sized projects. Object Oriented ProgrammingBecomes unmanageable for larger, more complex projects, with many programmers involved → Object Oriented Programming (OOP). Structured programs divide the problem into smaller sub-units or blocks, then divided into smaller blocks.. eventually reaching the level of program code. The blocks should ideally be self-contained – interactions with other blocks should be explicit ALL programming languages support Structured Programming to some extent Useful model for small-medium sized projects. Object Oriented ProgrammingBecomes unmanageable for larger, more complex projects, with many programmers involved → Object Oriented Programming (OOP).

17 The object-oriented approach Evolution of Program Design 1950s- 1960s 1970s - 1980s 1990’s- “simple” program models Zenith of structured programming- especially Pascal. First object-oriented languages (esp C++) traditional languages “converted” to OOP COBOL, Algol, BASIC Pascal, C, Fortran, Perl Ada, C++, JAVA, SmallTalk Visual Basic, Delphi (Object Pascal), Perl 5, (e.g. BioPerl) Examples

18 The object-oriented approach The program is written as a collection of interacting objects. Q: Why objects? A: Because the world is made from distinct objects, which consist of other objects, etc., and this is often a natural and powerful way of representing a situation or problem. Q: Why objects? A: Because the world is made from distinct objects, which consist of other objects, etc., and this is often a natural and powerful way of representing a situation or problem.

19 Example objects - chemistry molecules are made of.... atoms which consist of.... protons, neutrons and electrons.. molecules atoms nuclei electrons protons neutrons object hierarchy

20 OOP and structured programming In structured programs the blocks are pieces of code which are executed as the program is run In object-oriented programs objects have lives of their own – they can be created, copied, destroyed or even lost!

21 What is a software object? An object has two components: 1.state information which describes the current characteristics of the object and 2.behaviour which describes how it interacts with other objects. An object has two components: 1.state information which describes the current characteristics of the object and 2.behaviour which describes how it interacts with other objects.

22 Software representation of a cat object STATE Name Breed Weight Age Asleep STATE Name Breed Weight Age Asleep BEHAVIOUR Sleeps a lot Scratches furniture Catches mice Fights other cats BEHAVIOUR Sleeps a lot Scratches furniture Catches mice Fights other cats

23 Implementation of objects State is usually held as local variables (also called properties), quantities not visible outside the object (data hiding) Behaviour controlled by method functions or subroutines which act on the local variables and interface with the outside. STATE BEHAVIOUR

24 Key feature of OOP - Inheritance Important ability of any OOP is the ability to derive one object from a more general class of related objects: this is called inheritance. A standard eukaryotic cell nucleus, cell membrane, cytoplasm, alive or dead undergoes division, makes proteins from DNA nerve cell skin cell white blood cell

25 Examples of OO languages C++ –Classic example, uses C syntax Java –Based on C++, often used for Web and graphics Visual Basic, Visual C++ –Windows programming Perl ? –Possible, e.g. BioPerl, but not originally designed for objects. Implementation is a bit ad-hoc. Wanna know more ? For experts C++, for semi-experts Java and Visual Basic for beginners.

26 OOP - Summary  Objects provide a powerful and natural approach to representing many problems  Features such as inheritance allow already written objects to be re-used – program modification easier.   Certainly more difficult than conventional programming  Some concepts hard, even for experienced programmers  Implementation of objects often use complicated syntax/semantics  OOP not famous for efficiency (memory or execution time)  C++ once famous for being slow, now much better  Java still famous for being slow  Objects provide a powerful and natural approach to representing many problems  Features such as inheritance allow already written objects to be re-used – program modification easier.   Certainly more difficult than conventional programming  Some concepts hard, even for experienced programmers  Implementation of objects often use complicated syntax/semantics  OOP not famous for efficiency (memory or execution time)  C++ once famous for being slow, now much better  Java still famous for being slow


Download ppt "The Art of Programming Program design and implementation."

Similar presentations


Ads by Google