Programming Paradigms By James Veale

Get Started. It's Free
or sign up with your email address
Rocket clouds
Programming Paradigms By James Veale by Mind Map: Programming Paradigms By James Veale

1. Imperative

1.1. Description

1.1.1. The Imperative paradigm is used to conceptualize the solution to a problem as a sequence of steps. A program written in an Imperative language usually consists of self contained instructions that indicates how a task is performed. Emphasizes linear steps that provide the computer with instructions on how to solve a problem or carry out a task.

1.2. Computer languages that support Imperative

1.2.1. Fortran, a language developed in the early 50's, was the first widely used standardized computer language. This set the pattern for other popular procedural languages such as COBOL, APL, PL/1, Ada, and BASIC, to name a few.

1.3. Types of problems suited for Imperative

1.3.1. Imperative is typically used for problems that can be solved by following a step-by-step algorithm. Imperative has been used for transaction processing by the use of a single algorithm applied to many sets of data. Many problems in math and science also use the Imperative approach.

1.4. Example Code. This will double the numbers in an array.

1.4.1. var numbers = [1,2,3,4,5] var doubled = [] for(var i = 0; i < numbers.length; i++) { var newNumber = numbers[i] * 2 doubled.push(newNumber) } console.log(doubled) //=> [2,4,6,8,10]

1.5. Advantages/Disadvantages

1.5.1. An advantage of the Imperative approach is that it produces programs that run quickly and use the systems resources efficiently. The Imperative program allows programmers to apply it to many types of problems because of how powerful and flexible it is. But its disadvantages include that fact that it does not fit gracefully with certain types of problems. It also forces programmers to view as a series of steps, whereas some problems may be best viewed as interacting objects, concepts, or ideas.

2. Object-oriented

2.1. Description

2.1.1. The object-oriented program is based on the idea that the solution for a problem can be visualized in terms of objects that interact with each other. An Object-oriented paradigm formulates programs as a series of objects and methods that interact to perform a specific task.

2.2. Computer languages that support object-oriented

2.2.1. C++, visual basic and C#, are just a few languages that give programmers the option of using procedural and object-oriented techniques.

2.3. Types of problems suited for object-oriented

2.3.1. The object-oriented approach can be used for basically any type of problem that can be envisioned as a set of objects that pass messages back and forth.

2.4. Example Code. This code defines the firstName property for the Person class

2.4.1. var Person = function (firstName) { this.firstName = firstName; console.log('Person instantiated'); }; var person1 = new Person('Alice'); var person2 = new Person('Bob'); // Show the firstName properties of the objects console.log('person1 is ' + person1.firstName); // logs "person1 is Alice" console.log('person2 is ' + person2.firstName); // logs "person2 is Bob"

2.5. Advantages/Disadvantages

2.5.1. The object-oriented approach allows programmers to visualize solutions to a problem a lot more easier than most paradigms. But a disadvantage of the object-oriented is its runtime efficiency. Object-oriented programs tend to require more memory and processing resources than procedural programs.

3. Declarative

3.1. Description

3.1.1. A declarative paradigm attempts to describe a problem without specifying exactly how to arrive at a solution.

3.2. Computer languages that support declarative

3.2.1. Non-procedural languages such as LISP, Haskell, and Prolog can be grouped into the declarative paradigm.

3.3. Types of problems suited for the paradigm

3.3.1. It is possible to use the declarative language to solve problems involving calculations. But problems that require intensive computation are best suited for the declarative paradigm.

3.4. Example Code. This will double the numbers in an array.

3.4.1. var numbers = [1,2,3,4,5] var doubled = numbers.map(function(n) { return n * 2 }) console.log(doubled) //=> [2,4,6,8,10]

3.5. Advantages/Disadvantages

3.5.1. Declarative languages allow programmers to describe problems using words rather than the abstract structures procedural and object-oriented languages require. But declarative languages are known for providing minimal input and output capabilities. Another disadvantage of declarative languages is their poor performance on today's computer architecture. Declarative languages run more efficiently on parallel architectures.

4. Functional

4.1. Description

4.1.1. The functional paradigm emphasizes the evaluation of expressions, called functions, rather than execution of commands.

4.2. Computer languages that support functional

4.2.1. The functional paradigm is supported by languages such as LISP, Scheme, Haskell

4.3. Example Languages. This partitions the array to be sorted.

4.3.1. qsort([]) -> []; qsort([X|T]) -> ElementsLessThanX = [Y || Y<-T, Y<X], ElementsGreaterEqualToX = [Y || Y<-T, Y>=X], [qsort(ElementsLessThanX),X,qsort(ElementsGreaterEqualToX)].

5. Event-driven

5.1. Description

5.1.1. Allows a programmer to develop a program by selecting user interface elements and specifying event-handling routines.

5.2. Computer languages that support event-driven

5.2.1. Event-driven paradigms are supported by C# and Visual Basic languages.

5.3. Types of problems suited for event-driven

5.3.1. The programmer is never required to deal with the overall programming sequence because the visual development environment automatically user interface elements and event-handling routines into a faile that becomes the final computer program

5.4. Example Code. This takes an input and then doubles it.

5.4.1. int[] x = new int[10]; 2 Scanner scan = new Scanner(System.in); 3 for(int i = 0; i < x.length; i++){ 4 System.out.println("Enter number " + (i+1)); 5 x[i] = scan.nextInt(); 6 }

5.5. Advantages/Disadvantages

5.5.1. The event-driven paradigm can reduce development time and simplify the entire programming process.