Overview of Programming Paradigms | My Assignment Tutor

1Overview ofProgrammingParadigmsWeek 6 2Overview of Programming Paradigms Lecture Objectives: Be able to explain the differences between programming languages and programming paradigms. Be able to differentiate between low-level and high-level programming languages and theirassociated advantages and disadvantages Be able to list four programming paradigms and describe their strengths and weaknesses. Introduction to Computer Programming Programming Languages … Continue reading “Overview of Programming Paradigms | My Assignment Tutor”

1Overview ofProgrammingParadigmsWeek 6 2Overview of Programming Paradigms Lecture Objectives: Be able to explain the differences between programming languages and programming paradigms. Be able to differentiate between low-level and high-level programming languages and theirassociated advantages and disadvantages Be able to list four programming paradigms and describe their strengths and weaknesses. Introduction to Computer Programming Programming Languages Programming Paradigms Exercises 3Programming Languages A computer program is a clear, step-by-step, finite set of instructions. Acomputer program must be clear so that only one meaning can be derivedfrom it and is written in a computer language called a programminglanguage. There are three categories of programming languages: 1. Machine languages. (low-level languages) 2. Assembly languages. 3. High-level languages. 4Programming Languages (cont’d) A Machine language program consists of a sequence of zeros and ones. Each kind of CPU has its own machine language. Advantages Fast and efficient Machine oriented No translation required Disadvantages Not portable Not programmer friendly 5Assembly Language Assembly language programs use mnemonics to represent machine instructions Each statement in assembly language corresponds to one statement in machine language. Assembly language programs have the same advantages and disadvantages as machinelanguage programs. Compare the following machine language and assembly language programs: 8086 Machine language program forvar1 = var1 + var2 ;8086 Assembly program forvar1 = var1 + var2 ;1010 0001 0000 0000 0000 00000000 0011 0000 0110 0000 0000 0000 00101010 0011 0000 0000 0000 0000MOV AX , var1ADD AX , var2MOV var1 , AX 6High-Level Programming Languages A high-level language (HLL) has two primary components (1) a set of built-in language primitives and grammatical rules (2) a translator A HLL language program consists of English-like statements that aregoverned by a strict syntax. Advantages Portable or machine independent Programmer-friendly Disadvantages Not as efficient as low-level languages Need to be translated Examples : C, C++, Java, FORTRAN, Visual Basic, and Delphi. 7Programming Paradigms Why are there hundreds of programming languages in use today? Some programming languages are specifically designed for use in certain applications. Different programming languages follow different approaches to solving programming problems A programming paradigm is an approach to solving programming problems. A programming paradigm may consist of many programming languages. Common programming paradigms: Imperative or Procedural Programming Object-Oriented Programming Event driven programming 88Proceduralprogramming paradigm 9Procedural programming Often thought as a synonym for imperative programming. Specifying the steps the program must take to reach the desired state. Based upon the concept of the procedure call. Procedures, also known as routines, subroutines, methods, or functionsthat contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program’sexecution, including by other procedures or itself. A procedural programming language provides a programmer a meansto define precisely each step in the performance of a task. Theprogrammer knows what is to be accomplished and provides throughthe language step-by-step instructions on how the task is to be done. Lisp, C++, and Python are multi-paradigm; you can write programs or libraries that are largelyprocedural, object-oriented, or functional in all of these languages. 1010Procedural programming Benefits:» Often a better choice than simple sequential or unstructured programming in manysituations which involve moderate complexity or require significant ease ofmaintainability.» The ability to re-use the same code at different places in the program without copying it.» An easier way to keep track of program flow than a collection of “GOTO” or “JUMP”statements (which can turn a large, complicated program into spaghetti code).» The ability to be strongly modular or structured. The main benefit of procedural programming over first- and second-generation languages isthat it allows for modularity, which is generally desirable, especially in large, complicatedprograms. Modularity was one of the earliest abstraction features identified as desirable for aprogramming language like Python 1111Procedural programming Disadvantagesdifficulty of reasoning about programsdifficulty of parallelization.Tend to be relatively low level.Sample code: 12Object-orientedprogramming paradigm 1313Object-oriented programming (OOP) is a programming paradigm that uses“objects” – data structures encapsulating data fields and procedures togetherwith their interactions – to design applications and computer programs.Associated programming techniques may include features such as dataabstraction, encapsulation, modularity, polymorphism, and inheritance.Though it was invented with the creation of the Simula language in 1965, andfurther developed in Smalltalk in the 1970s, it was not commonly used inmainstream software application development until the early 1990s.Many modern programming languages now support OOP.Object-oriented programming 1414A class defines the abstract characteristics of a thing (object), including thatthing’s characteristics (its attributes, fields or properties) and the thing’sbehaviors (the operations it can do, or methods, operations orfunctionalities).One might say that a class is a blueprint or factory that describes the nature ofsomething.Classes provide modularity and structure in an object-oriented computerprogram.Collectively, the properties and methods defined by a class are called itsmembers.OOP concepts: class 1515» An object is an individual of a class created at run-time trough objectinstantiation from a class.» The set of values of the attributes of a particular object forms its state. Theobject consists of the state and the behavior that’s defined in the object’sclass.» The object is instantiated by implicitly calling its constructor, which is oneof its member functions responsible for the creation of instances of thatclass.OOP concepts: object 1616An attribute, also called data member or member variable, is the dataencapsulated within a class or object.Attributes are an object’s variables that, upon being given values atinstantiation (using a constructor) and further execution, will represent thestate of the object.A method is a subroutine that is exclusively associated either with a class (inwhich case it is called a class method or a static method) or with an object (inwhich case it is an instance method).Like a subroutine in procedural programming languages, a method usuallyconsists of a sequence of programming statements to perform an action, a setof input parameters to customize those actions, and possibly an output value(called the return value).OOP concepts: attributes & Methods 1717 Inheritance Abstraction encapsulation and information hiding polymorphismOOP concepts: 18Programming Paradigms: Object-OrientedExample object oriented languages include: Java, C#, Smalltalk, Python, c++ etc Advantages Conceptual simplicity Models computation better Increased productivity.DisadvantagesCan have a steep learning curve, initiallyDoing I/O can be cumbersome 1919Procedural programming vs OOPS The focus of procedural programming is to break down aprogramming task into a collection of variables, datastructures, and subroutines, whereas in object-orientedprogramming it is to break down a programming task into objectswith each “object” encapsulating its own data and methods(subroutines). The most important distinction is whereas proceduralprogramming uses procedures to operate on data structures,object-oriented programming bundles the two together so an“object” operates on its “own” data structure. 20Event-drivenprogramming paradigm 21Event Event-driven programming is a programming paradigm in which the flow ofprogram execution is determined by events – for example a user action such as amouse click, key press, or a message from the operating system or anotherprogram. An event-driven application is designed to detect events as they occur,and then deal with them using an appropriate event-handling procedure. The idea isan extension of interrupt-driven programming of the kind found in early commandline environments such as DOS, and in embedded systems (where the application isimplemented as firmware). Event-driven programs can be written in any programming language, althoughsome languages(Visual Basic for example) are specifically designed to facilitateevent-driven programming, and provide an integrated development environment(IDE) that partially automates the production of code, and provides acomprehensive selection of built-in objects and controls, each of which can respondto a range of events. Virtually all object-oriented and visual languages supportevent-driven programming. Visual Basic, Visual C++ and Java are examples ofsuch languages. 22Event Driven Programming User-Centric Computer User Determines the Order of Actions Programs are Interactive Flow of Control is Determined at Runtime» User Clicks Mouse / Presses Key» Object in Scene Moves to create a Condition 23Event Handling Advantages– It allows for more interactive programs. Almost all modern GUI programsuse event driven programming.– It can be implemented using hardware interrupts, which will reduce thepower used by the computer.– It allows sensors and other hardware to easily interact with software.Disadvantages– For simple programs, event driven programming is often more complexand cumbersome than batch programming.– The flow of the program is usually less logical and obvious. 24Which Programming Paradigm is Best?Which of these paradigms is the best? The most accurate answer is that there is no best paradigm. No single paradigm will fit all problems well. Human beings use a combination of the models represented by these paradigms. Languages with features from different paradigms are often too complex. So, the search of the ultimate programming language continues! 2525References1. John von Neumann. First Draft Report on the EDVAC, 1945.2. Harold Abelson, Gerald Jay Sussman. Structure and Interpretation of Computer Programs. The MITPress. 1996.3. Roberts, Eric S. (2008). “Art and Science of Java; Chapter 7: Objects and Memory”. StanfordUniversity.4. Programming paradigms, https://blog.newrelic.com/2015/04/01/python-programming-styles/

Reference no: EM132069492

GET HELP WITH YOUR PAPERS

WhatsApp
Hello! Need help with your assignments? We are here