Programming Paradigms
# What is it?
A paradigm is simply the way you look at and make sense of the world
So a programming paradigm is a way of thinking about and expressing a computer program.
There are quite a few paradigms and some are related
- Imperative: structured, procedural and object-oriented are examples
- As a general rule, imperative languages explain how to do something step by step
- Declarative: functional database (SQL) and mark-up languages (HTML)
- As a rule, declarative languages describe the problem and the system knows how to deal with it
- Imperative: structured, procedural and object-oriented are examples
# Structured Programming
Code that is imperative
- That is, it defines a series of steps that must be performed to complete a task
Structured programming is a subset of imperative programming.
Structured programming sees the world as a sequence of tasks that can be broken down into small, easy to manage chunks
- These chunks can be reused
# Hierarchy or Structure Charts
- A structure chart shows us the calling structure of a program
- Which subroutines get called from where and what information is passed and returned.
*By Pluke - Own work based on: Structured Chart Example.jpg by Sandia National Laboratories, Public Domain, https://commons.wikimedia.org/w/index.php?curid=16283788 *
# Pseudo Code
- Pseudo means not genuine
- Pseudo code allows you to think like a programmer while not needing to worry about the syntax of any given programming language
# Finite State Machines
- FSMs allow you to plan the states for a control system and what causes the transition from one state to another and any output.
- A Mealy machine’s outputs are determined by it’s state and input: you label the output on the transition.
- A Moore machine’s outputs are determined only by the current state: the output is labelled in the state.
# Comments
- Comments should enhance the readers understanding of the code
- You can assume the reader can already understand code in the language it is written in.
- Avoid in line comments where possible
- Be consistent in terms of comment use
- Comments are especially useful for:
- Module headers
- Subroutine headers
- Explaining the logic behind changes
- Logging code changes
# What is “Object Orientated Programming”?
- Code that is imperative
- Object oriented programming is a subset of imperative programming
- It sees the world as a collection of objects or things
- You define a generalised example of a thing which includes all the programs and data that it needs to function