Knowledgebase

Programming Paradigms Print

  • programminglanguages, programming, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Ways of structuring programs.

PROCEDURAL

Programs as sequences of instructions, organised into procedures.

OBJECT-ORIENTED

Programs as objects combining data and the operations on it.

FUNCTIONAL

Programs as compositions of functions, avoiding changing state.

DECLARATIVE

Describing what is wanted rather than how to obtain it.

WHAT MOST MODERN LANGUAGES ARE

Multi-paradigm, supporting several approaches.

WHAT OBJECT ORIENTATION PROVIDES

  • Encapsulation: data and behaviour together
  • Inheritance: sharing behaviour
  • Polymorphism: different types used uniformly

WHAT IT IS CRITICISED FOR

Deep inheritance hierarchies becoming rigid and difficult to follow.

WHAT TO PREFER

Composition over inheritance.

WHAT FUNCTIONAL PROGRAMMING PROVIDES

Predictability, since functions depending only on inputs are easy to reason about and test Easier parallelism, since shared changing state is what makes it hard

WHAT A PURE FUNCTION IS

One with no side effects, returning the same result for the same inputs.

WHAT TO ADOPT REGARDLESS OF LANGUAGE

Minimising changing shared state, and preferring pure functions where practical.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot