1 / 26

The Art of Programming

The Art of Programming. Program design and implementation. Think about the problem, design on paper the structure of the program, then start typing. ?. Check that someone else hasn’t already done it! * *(and if they have, it doesn’t cost too much).

winona
Download Presentation

The Art of Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Art of Programming Program design and implementation

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

  3. Writing a program – design, strategies and implementation • Analysing the problem • What do I need to do? • Unstructured programming • Program design with structured programming • pseudo code • program blocks and flow-schemes • 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 • ...

  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)

  7. 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. PROGRAM FLOW input output Stuctured programming

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

  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

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

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

  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.

  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 get sequence call read data call del_headers read_data del headers convertDNA loop over codons call tr_codon end loop tr_codon results printresults

  15. complex block diagrams START EXIT utility routine EXIT

  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. • Becomes unmanageable for larger, more complex projects, with many programmers involved → Object Oriented Programming(OOP).

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

  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.

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

  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: • state information which describes the current characteristics of the object and • behaviour which describes how it interacts with other objects.

  22. Software representation of a cat object • STATE • Name • Breed • Weight • Age • Asleep • 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) STATE Behaviour controlled by method functions or subroutines which act on the local variables and interface with the outside. 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 white blood cell nerve cell skin 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

More Related