The Logic of Coding

by Carson

We always encounter apps in our everyday life, and they require lines of code. Before we can program a computer, we have to grasp the logic before learning programming languages. So, what’s the logic of coding, and how the languages resemble that?

A Running Race

Your actions can literally create the idea of programming! For example, when you are on a running race (Hopefully, you aren’t thinking about coding), you initiate lots of movements just to move forward by a step. This is a built-in function, which is declared inside the language’s property. When you learn something new, you are inserting functions into your brain, and the programmer can call the function to repeat that.

def function():
    return "Run!"

However, you see obstacles on your way! You have to jump over it! So, you are writing an “if” statement, and that goes like this:

while (race == True):
    if (obstacle_distance < 2):

Did you notice that an “if” block isn’t enough? We need booleans, which describes if a condition is true or false. Also, don’t forget we used the “while” block: It provides a stop condition when the race ends to break out of the loop. You don’t want to continue running immediately after a competition because it’s tiring, right? Also, we utilized variables, which holds data by defining objects like integers, decimals, booleans, and floats. Imagine that we cannot make the program depend on some parameters!

Have you ever seen some questions having the phrase “unless specified”? Well, we are setting a default value in the brain when we receive that. For instance, the “race mode” is off most times, so we need to define the value of “race” as false prematurely.

Remember Debugging

Remember that Software Bugs always appear in programs, and it’s necessary to know about the logic of debugging. Ask yourself, ‘How do you check your answers after an exam?’ We have to see if all procedures are correctly done, just like when you debug.

We have to add some “print” statements amid the program to find out where the error or the unintended outcome occurs. Also, if an exception takes place, you will be able to inspect the problematic input, like an undeclared variable or a syntax error that makes the program unable to run.

So, here’s a brief review of the logic of coding as a running race and the mechanism of debugging.

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.