Intuitive comparison of functional vs imperative programming

 Another example of how you can spend hours trying to understand an idea and get nowhere, but search for "intuitive+youridea" and rapidly find a gem like this example of the difference between functional and imperative programming. Within seconds of reading this I understood more than an hour of reading other articles on the same subject:

Imperative:
  • Start
  • Turn on your shoes size 9 1/2.
  • Make room in your pocket to keep an array of keys.
  • Put the keys in the room for the keys in the pocket.
  • Enter garage.
  • Open garage.
  • Enter Car.
... and so on and on ...
  • Put the milk in the refrigerator.
  • Stop.
Declarative, whereof functional is a subcategory:
  • Milk is a healthy drink, unless you have problems digesting lactose.
  • Usually, one stores milk in a refrigerator.
  • A refrigerator is a box that keeps the things in it cool.
  • A store is a place where items are sold.
  • By "selling" we mean the exchange of things for money.
  • Also, the exchange of money for things is called "buying".
... and so on and on ...
Make sure we have milk in the refrigerator (when we need it - for lazy functional languages).

 

Add a comment

Fields followed by * are mandatory

HTML code is displayed as text and web addresses are automatically converted.

Page top