Cursea: Introduction to programming in Python I: Learning to program with Python #1
Introduction to programming in Python I: Learning to program with Python
In my eagerness to find where to learn, I came across this course on the Cursea platform, given by the Pontificia Universidad Católica de Chile, a beautiful private university. The course was free, only if you wanted the certificate at the end of the course you would have to put in a few dollars. So I went in happy to have a guide to start learning Python.
The course is divided into 6 modules. The first module explains the basics of what programming and logic is, which by the way made me laugh with the funny examples, the explanations of logic are great.
One of the most important things and the concept that underpins all programming is logic.
What is logic?
When we give instructions to the machine, we tell it step by step what it should do, those instructions are what we define as programming logic.
We as humans tend to skip several obvious parts when narrating cooking instructions, for example…
ingredients for a breakfast… 2 eggs, 1 bacon, heat for 10 minutes.
And that doesn’t make sense, because although it is implicit for us, it is not for the machine. If we put a machine to do this, what would happen would be that it would create 2 eggs of the same existence, breaking reality because we haven’t told it, hey bro, grab two eggs from such and such a place. And I would heat them yes with the eggshell included.
It doesn’t make much sense. Now yes, good programming logic would be to give clear, specific and unambiguous instructions:
Go to the kitchen, open the refrigerator, look for the eggs, grab the eggs, close the refrigerator, go to the kitchen table and grab the cooking tools, frying pan, take the frying pan and leave it on a burner in the oven, program the burner to raise its temperature, go to the table again, grab the oil, open the oil and place it inside the pan…
We have narrated the logic behind all this and even with all this we could not even cook a single egg due to the number of steps. Besides the fact that we are not used to thinking that way, don’t worry anyway. If you are starting to program and think that you are going to have to do all those steps over and over and over again, to do the same thing, since there are functions and loops for this. But let’s not talk about it yet, let’s continue with a boolean question.
Imagine that you ask a computer to hang a painting. Which of the following answers would be the most appropriate way to do this?
Take a hammer, a nail, and the painting to hang. Place the nail in the place where you want to hang the painting. Take the hammer and hit the nail until you have placed the nail in the correct position to hang a picture. Take the picture and place the hanger on the end of the nail that was left protruding from the wall.
Take a hammer, a nail, and the painting to hang. Find the place to hang the painting and place the nail using the hammer. Once the nail is placed, take the picture and place the hanger on the end of the nail that was protruding from the wall until it is hanging.
Take a hammer, a nail, and the painting to hang. Locate the place on the wall where you want to hang the painting. Place the nail in the chosen place and place its tip on the wall. Take the hammer and place it on the flat end of the nail. Hit the nail as many times as necessary until the nail is inserted into the wall leaving 1 cm out. Take the picture and place the hanger on the end of the nail that was left protruding from the wall.
3 is correct because: Correct Indeed! This instruction is clearer, more precise and less ambiguous than the rest of the answers and, therefore, more suitable for giving instructions to a computer.
The most efficient way to make an egg would be:
Have at your disposal a stove, a paina, a spatula, two eggs, a bacon, oil and salt. 2 light the kitchen flame with the matches, 3 take the paina and place it on the lit burner. 4 add oil to the paina, 5 take the egg and place it on the paina at one end, use one end of the paina to hit the egg shell until it cracks, 7 place the egg on a paina and finish breaking it to drop its contents without the shell, throw the shell into the trash can, 7 let the egg cook for a minute, 8 add salt to the egg, 9 use the spatula to remove the egg.
Programming Languages Level
We are referring to the level of complexity that languages have in communicating with the machine.
A machine language is the lowest level where we can observe that they communicate in binary, that is, a language of ones and zeros, which means that it is not accessible for us to communicate with the machine in that way, which is why high-level languages were invented, such as Python, JavaScript, Java, etc. With a syntax similar to ours in vocabulary, which makes it quite easy for us when programming.