Knowledgebase

Functional Programming Concepts in Practice Print

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

Ideas worth adopting anywhere.

WHAT A PURE FUNCTION IS

One depending only on its inputs, with no side effects.

WHY THAT MATTERS

It is trivially testable, safely parallelisable, and easy to reason about.

WHAT IMMUTABILITY MEANS

Values that do not change after creation.

WHAT IT PREVENTS

An entire class of bugs where something changed unexpectedly.

WHY IT MATTERS FOR CONCURRENCY

Values that cannot change cannot be raced on.

WHAT FIRST-CLASS FUNCTIONS ENABLE

Passing behaviour as an argument.

WHAT THE STANDARD TRANSFORMATIONS ARE

  • Mapping: transforming each element
  • Filtering: selecting elements
  • Reducing: combining elements into one result

WHY THOSE ARE PREFERABLE TO LOOPS

They state intent rather than mechanics, and they eliminate index errors.

WHAT COMPOSITION MEANS

Building complex behaviour from simple functions.

WHAT TO ADOPT REGARDLESS OF LANGUAGE

Minimising changing shared state Preferring pure functions where practical Using the standard transformations

WHAT NOT TO DO

Force a functional style where the language fights it.

WHAT MATTERS MORE THAN PURITY

Clarity.


Was this answer helpful?
Back

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


Trustpilot