Programming paradigms

Martin McBride, 2018-05-20
Tags none
Categories none

A programming paradigm describes an overall approach to programming. It often specifies how a complex problem is broken down or decomposed into smaller, more manageable parts. Different programming languages provide varying support for different paradigms, so the decision of which approach to use is often linked to the decision of which language to use.

Here are the most common paradigms:

  • Procedural programming. This is a the style of most people are taught when they are first introduced to programming. The program consists of a sequence of instructions for solving the problem. It uses the basic elements of sequence, selection and iteration. Procedural programming is very useful for simple scripts or programs, but as complexity increases it is usually better to choose a different paradigm. This is covered in programming techniques in the GCSE book. It is supported by Python, Java, C/C++, BASIC, Pascal and many other languages.
  • Structured programming. For complex procedural programs, it can be useful to analyse the problem and specify the structure of the code needed to solve it. This will include what functions are required, and within each function what loops and conditional code blocks are required. The program is designed at an abstract level, and the detailed code is added when the design is implemented.
  • Object oriented programming (OOP). In this case, code is organised into "objects". An object is a set of functions and data that represent some object that the program needs to interact with - for example a file, a window in the user interface, a database query. By encapsulating the data and the code into a separate unit of code, the program becomes better structured and more robust. It is possible to create libraries of reusable objects to save development time.Object oriented programming is supported by Java, C++, Python and other languages.
  • Declarative programming. This takes a completely different approach. The language allows you to specify the result you want to obtain, or the problem you want to solve. It is then up to the language interpreter to decide how to solve the problem. Examples are HTML (where you specify the content of a web page, but do not provide detailed instructions for exactly how to lay it out), and SQL (where you request information from a database, but rely on the SQL implementation to decide exactly how to perform the search).
  • Functional programming (FP). In FP, complex problems are decomposed into functions as the high level building blocks (in a similar way to OOP breaking the problem down into objects). In FP, functions are first class objects, so a function can be stored in a variable or passed into another function as an argument. Functions that operate on other functions are called higher order functions. Examples of functional programming languages are Haskell and Lisp, but Python and Java also support FP.

In this section we will over object oriented programming and functional programming.

Copyright (c) Axlesoft Ltd 2021