How to explain programming paradigmas to you girlfriend

Recipes are often used as to explain what algorithm is.

Let’s take a simplified vegan Chocolate Cake recipe as an example:

var
	175g self raising white flour
	3 level tsp baking powder
	25g cocoa
	100g Barbados sugar
	125 ml olive oil
	325 ml cold water
begin
	Preheat oven to 190°C.
	Place all the cake ingredients in a bowl
		and mix thoroughly.
	Place mixture in greased loaf tin
		and bake for 30 minutes
		in the preheated oven.
	Cool on a wire rack.
	Arrange the chocolate beans on top.
end.

Low-level (Assembly) start be something like:

	Find to oven
	Make sure it is empty
	turn temperature switch to "190°"
	...
	and so on

Procedural/Modular would be similar to original formulation.

Functional (my favorite) could be:

...place mixed cake ingredients
    in a bowl
     and put it to the pre-heated oven for 30 min...

Logic/Descriptive programming:

What you are trying to do is cake.
Cake is round and sweet and tasty.
(try everything until you get it)

Object-Oriented is somehow difficult to make straightforward here.

I’ve tried this analogy on my gf, and it worked.

The interesting part is that although most males (like me) find “low-level” recipes most easy to use, more experienced people (and cookbooks) prefer “functional” formulations (which does not implicitly state the “order of evaluation”), as it is shorter and and is easier for “optimizations“(*),  “thread synchronizations“(**) and “multiprocessors“(***) and so on – exactly the advantages of fp.

(*) by optimization I mean, that in “functional” formulation, it is easier to understand that e.g. which jobs can be swapped, omitted etc.

(**) example of synchronization: “put baked A and roasted cut B to C and mix” is easier to both understand and prepare than

put A on fire;
cut C; put C on fire.
repeat:
    If A is ready turn A off.
    If B is ready turn off B.
until both are ready;
mix them

(***) Multiprocessors: If you have, say, two cooks and an instruction “take baked A and roasted and cut B to and mix”, the tasks can be trivially assigned in optimal way, but is much harder in more low-level recipe.

Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: