How to Bake an App

by Neil Roger on April 27, 2015 7 comments

There are many comparisons out there that try to explain what programming is. These range from building things with Lego to bringing up a child, but there is one that I like to use and it’s:

Programming is Like Baking Cakes!

Let me explain…

A bog standard definition of programming is, “The process of developing and implementing various sets of instructions to enable a computer to do a certain task.”

The “task” could be putting some data in a field, playing a sound, or posting information to a web service, but all of these have to be initiated by a given set of instructions.

Now you may be thinking, “What does this have to do with baking a cake???” So, let me explain:

First, let me give you my infamous cake recipe that I’ve used for well over 20 years (yes, I still eat any leftover cake mix…its the best part!).

Recipe : Impulse 101- Fairy Cakes

Kitchen Utensils Required

Scales
Spoon
Mixing apparatus
Cake cases
Oven

Ingredients

4 Oz Margarine
4 Oz Self Raising Flour
4 Oz Caster Sugar
2 Large Eggs

Steps

1) Pre-heat oven to 180 degrees Celsius

nb2

2) Mix sugar and margarine until a paste forms

nb3

3) Add half of flour and one egg to paste and mix

nb4

4) Add remaining egg and flour to mix and mix until creamy texture and mix slightly sticks to mixing utensil

5) Add mix to cake cases and put in oven for 20 mins approx

nb5

6) When ready, cakes should have risen with no mix sticking to knife if placed into the cake

nb6

Done.

Now, how can this be compared to programming? 🙂 Let me break it down:

The utensils can be seen “variables” and the “Ingredients” are the “Constant” contents which we are putting into these variable. The steps are the “Set of instructions” required for the desired outcome. In the case of a cake recipe – we obviously want some mouth watering cakes!

Now that we have our variables, constants, and instructions, we can generate some suitable script that would be equivalent to physically baking the cake.


// code

local sBowl, sMixer, sSpoon, sOven, sEmptyCases, sFullCases

constant margarine = "4"
constant sugar = "4"
constant flour = "4"
constant eggs = "2"


on bakeMeSomeCakes
   
   put "180" into sOven -- pre heats the oven
   
   put margarine into sBowl -- puts our margarine in bowl
   add sugar to sBowl-- adds our sugar to margarine
   
   put randomMixer(10,20) into sMixer -- as mixing times will vary depending on user, we will want to vary the mixing time
   
   repeat with x = 1 to sMixer -- simulate mixing
      repeat with y = 1 to 8
         put y into sBowl
      end repeat 
   end repeat
   
   add (flour/2) to sBowl -- adds half our flour to our bowl
   add (eggs/2) to sBowl -- adds 1 egg to our bowl
   
   put randomMixer(10,20) into sMixer -- get a random mixing time again
   
   repeat with x = 1 to sMixer -- simulate mixing again
      repeat with y = 1 to 11
         put y into sBowl
      end repeat 
   end repeat
   
   add (flour/2) to sBowl -- add the remaining ingredients
   add (eggs/2) to sBowl 
   
   put randomMixer(20,30) into sMixer -- get a random mixing time again but this time a bit longer to make the mix a bit fluffier
   
   repeat with x = 1 to sMixer -- simulate mixing again
      repeat with y = 1 to 14
         put y into sBowl
      end repeat 
   end repeat
   
   put 14 into sEmptyCases -- number of cake case for our cakes
   
   repeat with x = 1 to 14
      put (sBowl/sEmptyCases) into sFullCases[x] -- will divide our mix equally and place into fullCase variable array
   end repeat
   
   put sFullCases into sOven -- puts our full cases in our oven
   
   wait 1200 seconds -- 1200 seconds is 20 minutes 
   
   answer "Done! You have baked some awesome cakes nom nom nom!"
end bakeMeSomeCakes

function randomMixer lowerLimit,upperLimit -- gives a random value between upper and lower limit
   return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomMixer

So, there you have it: proof that programming is just like baking a cake 🙂 (although, admittedly, not as tasty)!

Just like baking, you can also optimise your code (recipe) to make it more efficient. One way you could do this is replacing the “wait 1200 seconds) code with something that is non-blocking.

This means you could check the status of your baking (i.e. opening the oven) at various intervals throughout the baking process. 🙂

Hopefully this has sparked the budding chef in you, so please feel free to share any comments/recipes you have in the comments section below. Bon appetit! 🙂

Neil RogerHow to Bake an App

7 comments

Join the conversation
  • Laurie - April 28, 2015 reply

    Nice analogy and great way to show how it’s accomplished using livecode syntax but where’s my cake?

    Neil Roger - April 28, 2015 reply

    In the famous words of Portal 2 – http://tinyurl.com/29d4wpy

    Richmond - April 28, 2015 reply

    NO! The cake is not a lie. The cake is extremely apt: especially as in my coding, my cakes almost always sink in the middle 🙂

    Richmond - April 28, 2015 reply

    I should, perhaps, point out that while with your cake you stick to an explicit declaration of variables, I just grab what I find in the cupboard.

    What I do like, more than anything else, about LiveCode, is that it is, by-and-large, tolerant of my use of ingredients to hand, it being incredibly flexible.

  • Richmond - April 28, 2015 reply

    I’m a bit wary of margarine, I prefer either ingredients that come out of a cow or sunflower oil. The analogy is very good; but I do feel that using margarine is a bit . . .

    Neil Roger - April 29, 2015 reply

    I do love myself a bit of margarine 🙂 I’m a bit partial to margarine and sugar on its own! As disgusting as it sounds, it is the best bit of the cake mix.

    Richmond - April 29, 2015 reply

    I guess that makes you a “stork baby” . . . LOL

Join the conversation

*