My next-level Sunday is here and since I mastered the Chef’s knife last week, I decided to impress my guests with a perfect crackling.
I’m aware that my standards are high, but I like to keep pushing myself to achieve more. In this way at the end of the day I’ll never regret learning to cook or learning to code.
Let’s fire up some software development and find out:
Algorithm of the day, “pork shoulder”.
Before a computer can solve a problem, a human must find an algorithm that describes how to solve that problem.
Based on my experience with software development (read documentation), I take one of my cooking books and search for the instructions I need to implement the above algorithm (cook that pork).
First step, is to break down the dish into lists of ingredients:
- 2 kg higher-welfare pork shoulder, bone-in, skin on
- 2 red onions
- 2 carrots
- 2 sticks of celery
- 1 bulb of garlic
- 6-8 fresh bay leaves
- 600 ml organic vegetable stock
Looking at all these ingredients I can easily identify them as a list of variables.
In software development a data type is an attribute of data which tells the computer how the programmer intends to use that data.
As an analogy, I can use the word “recipe” – to represent the meal that I want to cook every week. Because from one week to another it changes, that makes it a variable.
Last week recipe was “duck breast with orange sauce”. This week recipe is “pork shoulder”.
So, using variables I can simplify things because I don’t have to be so explicit. I just have to say “recipe” and it can take a different value.
Most of the programming languages support common data types of real, integer and boolean. These types constrain the values.
My recipe it’s using onions.
That means that I have a variable (I choose to name it “hasOnions”) and I can represent it using a boolean type (has one of two possible values, usually true and false):
var hasOnions: Boolean = true
Value 2 is considered an Integer (a number that can be written without a fractional component) so definitely is not a Boolean type.
AndroidStudio it’s a bad ass! It doesn’t allow you to do such a mistake.
Variable are typically used to store information which your algorithm needs to do its job.
It can be any kind of information (numbers, texts, temporary results etc).
In Kotlin we declare a variable like this:
There are variable naming conventions for each programming language. What I recommend most is to use all the time words which easily identify what your variables refers to so others can understand your code and work with you.
What I’ve learned with this recipe is to keep my list of ingredients short (as I forgot to add the bay leaf) and think all the time at the memory used by my code (since a variable is associated with a space in the computer’s memory which holds a value).
I hope I inspired you to start coding or cooking or both and invest in your learning path.
Don’t write ordinary code, be a Micheline star chef! Stay happy!
P.S: it should have 60 degrees celsius, I only got 59.9 (there’s room for improvement).
Thank you for reading this. If you have any questions, comments or funny jokes comment below.