- 20th March, 2018
How a data scientist makes a cup of tea
By Kingston Coker
Different programming techniques and styles, often termed as paradigms, are best suited for different situations. Two of the most common programming paradigms are Object Oriented Programming (OOP) and Procedural Programming. These techniques mainly serve to improve speed, readability and overall performance of the program - if one understands when to apply them.
Object Oriented Programming (OOP) is based on the concept of objects. Objects are entities that basically encapsulate related data. Objects also have actions associated with them that allow objects to interact with each other. Thus you can have a ‘person’ object, a ‘ball’ object and a ‘kick’ action to enable a ‘person to kick the ball’.
Procedural programming harnesses a top down approach to code execution. In a sense, it is a step by step, or line by line execution of instructions. Contrary to OOP, its focus is more on the functions and sequences of actions rather than the data itself.
Let’s illustrate the two paradigms and the differences between them by considering how one would go about making a cup of lemon tea. A procedural program would go through the following steps:
- Take out the tea bag
- Take out the mug
- Take out some milk
- Take out some sugar
- Boil a kettle of water
- Pour the water into the mug
- Dip the tea bag in to the mug of hot water
- Add sugar
- Add milk
Now if you fancied a cup of chamomile tea or wanted to use honey instead of sugar, a procedural process would be unable to do this unless it went through and re-wrote every single step. Clearly, this can be cumbersome.
With object oriented programming however, segments can be broken down into units that can be called upon whenever they’re needed. For example:
- Take out the ingredients
- Milk, mug, tea type, sweetener
- Boil the water
- Pour hot water in mug
- Mix the ingredients
- Dip tea bag into mug, add some sugar/honey/milk
With OOP, you don’t have to go through every single line of code every time the ingredients change. All you need is to modify the ingredients section of the code. While procedural programming can be quicker initially, it can be costly and time consuming later on when changes to the code need to be made. However when the data format presented does not change much over time or the data normally goes through very similar steps that do not need to be reused, then procedural programming has its merits.