Following is my analysis of four different programming paradigms, recognized by the computer science: Imperative Paradigm, Declarative Paradigm, Functional Paradigm and Object-oriented paradigm.
Imperative programming started at the time when the first high-level programming languages began to appear. Computers of that time, circa 1950, were using vacuum tube transistors and only a couple of kilobytes of memory, so programming languages needed to evolve to use those resources smartly. The one way to realize this goal was to use a sequence of commands (programming directions), which communicate with a computer exactly what it needs to perform. This is a very straightforward and efficient way of coding and also very intuitive, and it rules the world of programming to this day. All that a programmer needs to do is to provide the logical list of steps, and it’ll get executed in that sequence.
Imperative Programming Languages:
- The Machine Language
- ALGOL (1950-1960) – worked nicely with mathematical algorithms
- FORTRAN (1954) – first programming language that allowed more complex code
- MUMPS (1966) – interesting about this one was a fact that it relied purely on commands (it had no statements)
- COBOL (1960)
- BASIC (1964) – attempt to make programming look like English
Following are some of the newer imperative languages, that are however not completely necessary in their nature and use ideas from object-oriented programming:
- Perl (1987)
- Python (1990)
- Visual Basic (1991)
- Visual C++ (1993)
- PHP (1994)
- Ruby (1995)
- NET and C# that run on .NET Framework (2002) – imperative at its core
To conclude this section, I’d just summarize it by saying, that as we can see, this traditional way of programming is still very popular today. And PHP, Python and .Net languages are one of the most popular programming languages today, albeit we have to add, that while imperative in their core, some of these newer languages allow imperative as well as object oriented programming.
- Structured programming
- Sequential composition
- Good level of control
- Portable source code
Declarative paradigm is somewhat different from the imperative programming. In declarative programming, programmers do not use the sequence of instructions. Instead they just describe the approach of the task at hand. It’s a style of developing the structure and elements. The declarative programming doesn’t use any flows to describe the logic; it only needs to concern itself with “explaining what the program must accomplish regarding the problem domain, rather than explain how to perform it as a sequence of the programming language primitives. This is in contrast to imperative programming, which implements algorithms in specific steps.” (Lloyd, 2016). Declarative paradigm is synonymous with database query languages. It’s also often used in configuration management system languages, and programmers would also recognize this way of coding from regular expressions and other types of similar programming.
Declarative Programming Languages:
- SQL and XQuery
- HTML, MXML, XAML, XSLT and other markup languages
Declarative programming, however, is a standard term for a number of other programming paradigms, such as constraint and functional programming, domain specific, logic and hybrid languages, etc.
Among these, following are modern examples of Declarative Programming languages:
- Make – build specification language
- Scheme, Clojure, Erlang, Haskell, OCaml, Standard ML and Unlambda
- Makefiles and Yacc
- Modelica and Analytica – used for modeling
- Minimize mutability
- Reduces state side-effects
- Leads to more understandable code
- More scalable
Most of the known functional programming languages are expansions on the lambda calculus (a formal system developed in the 1930s), in which functional programming has its roots. Functional programming has lazy evaluation, uses higher order functions, is immutable and modular and thus it has no side-effects. It achieves this without statements, only by using expressions and declarations. “In simple words, Functional Programming (FP) is one of the favorite Programming paradigms, which does computation like Mathematical Functions without Changing State and Mutating Data.” (Kamma, S., Posa, R. and Bibhu, 2015).
Functional Programming Languages:
- Coq (Gallina)
Many other advantages are making functional programming popular today:
- Can predict the behavior of a program
- Bugs-Free Code
- Efficient Parallel Programming
- Better Performance and Encapsulation
- Nested Function support
- Increased Reusability, Testability, Readability and Maintainability
- Better Modularity
- Robust and Reliable Code
- Support for BigData
Object-oriented programming was created mainly to manage the complexity of procedural/structured languages. Even that some of the OOP languages are not purely object oriented and still use a bit of a structured programming, OOP languages such Java, C++ and C# are one of the most popular today.
“Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. The most popular OOP languages are class-based, meaning that objects are instances of classes, which typically also determine their type.” (OOP, 2016).
Today, OOP languages are much more attractive than structural programming languages. The main reason for object oriented programming being so successful is the fact that it brings the concepts we use in the real world (along with the business logic) into programming and allows programmers to characterize object properties and behaviors precisely.
- Clear modular structure – Use of objects, classes and other concepts of abstracting data
- Code Reuse and Recycling
- Encapsulation, Inheritance, and Polymorphism
- Design and Planning requirement (yes, this can be a good thing)
If I had to provide at least one example of a programming language that supports each of the identified programming paradigms, that would very likely be Python. Python is a compiled language, same as C, which is one of the most widely used procedural programming languages. But it also allows for defining programs and subroutines as mathematical functions, similar to how Lisp, or Curl do it, which are considered to be the functional languages. Python is in considered one of the Multiparadigm languages because it’s functional, compiled, interpreted, object-oriented (class-based), imperative, metaprogramming, extension, impure, interactive mode, iterative, reflective and scripting languages. Some other languages that are designed to support more than one paradigm are Object Pascal, C++, Java, C#, Scala, Visual Basic, Common Lisp, Scheme, Perl, Ruby, Oz and F#. These languages implement multiple styles and programming paradigms. “The design goal of such languages is to allow programmers to use the best tool for a job, admitting that a single paradigm cannot solve all problems in the easiest or most efficient way. (Abumgarsh, 2014)
Abumgarsh (2014) Multi-paradigm programming language. Available at: https://developer.mozilla.org/ar/docs/multiparadigmlanguage.html (Accessed: 28 September 2016).
Imperative programming (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Imperative_programming (Accessed: 28 September 2016).
Lloyd (2016) ‘Declarative programming’, in Wikipedia. Available at: https://en.wikipedia.org/wiki/Declarative_programming (Accessed: 28 September 2016).
Functional programming (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Functional_programming (Accessed: 28 September 2016).
OOP (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Object-oriented_programming (Accessed: 28 September 2016).
Object-oriented programming (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Object-oriented_programming (Accessed: 28 September 2016).
The principal programming paradigms (2008) Available at: https://www.info.ucl.ac.be/~pvr/paradigmsDIAGRAMeng108.pdf (Accessed: 28 September 2016).
Imperative vs. Declarative programming – pros and cons (2016) Available at: https://www.netguru.co/blog/imperative-vs-declarative (Accessed: 28 September 2016).
Kamma, S., Posa, R. and Bibhu (2015) JDBC interview questions. Available at: http://www.journaldev.com/8693/functional-imperative-object-oriented-programming-comparison (Accessed: 29 September 2016).
Introduction to Computer Science (2015) Available at: https://www.cs.drexel.edu/~introcs/Fa15/notes/06.1_OOP/Advantages.html?CurrentSlide=3 (Accessed: 29 September 2016).
List of programming languages by type (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages (Accessed: 29 September 2016).