Programming Paradigms and languages Criteria Covered in this presentation • P1:describe the application and limits of procedural, object oriented and event driven programming paradigms • P2:describe the factors influencing the choice of programming language • P3:explain sequence, selection and iteration as used in computer programming • P4:outline the benefits of having a variety of data types available to the programmer Programming Paradigms A programming paradigm is a fundamental style of computer programming – Procedural – Event driven – Object oriented Procedural Paradigm • The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines • Procedural languages are the most traditional types of language, and usually the first type that is learnt. • They include Fortran, Pascal, Basic and C. • Specifies the steps the program must take to reach the desired state. • Inclusion of reusable subprograms (procedures, functions) to avoid repetition of coding. • Procedural languages are very good for small-scale projects. Limitations of Procedural Paradigm • To limit the program flow in 1-dimensional (or linear way). Most of software developers would have been brain-washed to think this way. • The most serious limitation is the tendency for large procedural-based programs to turn into "spaghetticode". – Spaghetti code is code that has been modified so many times that the logical flow becomes so complicated. Accordingly, any new programmer coming onto the project needs a two month prep-course in order to even begin to understand the software innards Event Driven Paradigm • The flow of the program is determined by events, such as or user actions (mouse clicks, key presses) or messages from other programs • Is widely used in graphical user interfaces • Is clearly divided down to two sections: – the first is event selection (or event detection) – the second is event handling. • Limitations Sometimes leading programmers to create error prone, difficult to extend and excessively complex application code Object Oriented Paradigm • Object-orientated languages provide an excellent model for programming and designing computer software • They include C , Smalltalk and Java. • An object-oriented program may be viewed as a collection of interacting objects • Objects are consisting of datafields and methods Limitations of OOP • Not all programs can be modeled accurately by the objects model. If you just want to read in some data, do something simple to it and write it back out, you have no need to define classes and objects. • Another disadvantage is that one programmer's concept of what constitutes an abstract object might not match the vision of another programmer. The objects often require extensive documentation. Types of programming languages • There are so many types of programming languages • In this presentation, only two are mentioned: – Visual Programming languages – Script languages – Mark up languages Programming Languages • Visual languages use images to communicate concepts based on spatial context, as opposed to a linear (text) context. • One example of a visual language is Visual Basic.Net, which is part of the Visual Studio.Net package. • Other languages include script and markup languages that can be used for web page design, such as JavaScript and hypertext markup language (HTML). Factors influencing the choice of programming languages 1. Organizational policy : where a default programming language is used as standard 2. Suitability : how functional and user friendly is it in terms of features and tools? Is it easy to learn? 3. Availability of trained staff: user expertise and their level of understanding or training in a particular language 4. Reliability of the language: is it a reliable language? e.g. does it provide adequate exception handling? 5. Expandability : is it capable of expanding with the organization or task requirement? Factors influencing the choice of programming languages 6. Development and maintenance costs : • Some languages become obsolete or unsupported • Cost is influenced by a variety of factors including: Training of programmers Cost/Time of writing the actual program Compiler cost (time and development environment cost) Execution cost (deployment environment cost) Bugs and reliability issues Maintenance Features of Programming Languages Data Types Data types define the format or context of the data. For example, a data type could be classed as: Text Can include any alphanumeric characters, for example abc123. Text benefits from the flexibility of combining both characters and numbers together, a good example being in an address field. Integer A whole number such as 1, 2, 3 or 4. Benefits of using an Integer are that less storage space is required, a counter can be used, mathematical operations can be performed and comparisons can be made. Floating point A ‘ real number ’ that has a decimal point. The benefits of using a floating point are that percentages, areas, measurements and computations can be stored. Data Types Byte – used for storing binary data in a computer system. Date will represent data in a specific date format It is beneficial to users as it will prompt them to enter the date in a set format, for example --/--/----, 22/02/1972. Boolean a logic value that will return a ‘ true ’ or ‘ false ’ value. Boolean data types are very small, requiring one bit, 0 or 1, representing true or false. Benefits of having different data types • Efficiency of storage: efficient memory allocation for variables • Imposes less bugs to programs: allows you to catch common coding problems during compilation and during development before delivering the code to production • Allows the runtime to understand how to implement the operators: Operators perform differently for different types(+ adding numbers or connecting strings) • Allows code and subroutine parameters to be more expressive • Programs become more secure: because a data's type specification limits what the data can be used for • They also provide conveniences in developing and maintaining the code.