(#2)(coding tutorial) How to cook a program algorithm using our recipe

Hi, this is second article introducing you to how to start programming in any language. If you didn't read previous article. take a look at how coders think of a world in code.

When you start learning coding, you may feel overwhelmed by the amount of information, which you face at once. It's understandable, but no fear - if you compare some aspects to a real world, then everything start to be much easier. You may think, it's easy to say because you make software for a while, maybe it's true, but I also had to go through a learning stage to this day. That is because IT area keeps advancing and new inventions are coming like generating content using AI, people make a new programming languages, there are a new frameworks which makes easier to create something new.

Without further ado, let's learn some new stuff.

Computer is like a primary school student

If I think about programming I think about solving problems. Problems might be complex, but it should scare us at all.

++If you learn how to build complex solution using simple solution, then you are a good programmer.++

How so?

Just take a look what computer does in his CPU, a place where most of action is taking place. For now, to make it simple we narrow our look, and see what happens in that mysterious CPU processing device.

A code, which people writing to instruct how computer should behave, is in most languages written in plain English using some special keywords which computer knows how to interpret it by programming languages and it's environment.

SO, what computer sees, when coder instruct computer to do some jobs?

Well, I guess it would something like 10101010101010101000010101010000100010010

Not so readable and not to comples. Some bunch o 0nes and zeroes. You call that it a binary code. when you have some 0 and 1 in different combinations.

Ok, so computer has some binary code, which we get from our commands when we code in our favorite programming language, but what happen next? Well, it depends what you instruct him to do.

Let's take a stupid simple example:

let's make a 2 + 2 operation.

You might say

well, it's simple dummy the answer is 4. It's a knowledge from primary school.

You're right, but computer is like a child from primary school. He knows basically how to add, subtract, divide and multiply.

But computer doesn't know English or any human language. He knows zeroes and ones. Ok, so how it works?

so we do 2 + 2

We have two number 2 and 2, and also we have a plus sign which means that we want add two numbers. There should be also a equals sign, it instructs computer to give us a answer of this adding operation.

So far, we have parts 2,2,+,=

Now let's name our first number as firstNumber, and second number as secondNumber.

So now we have firstNumber, secondNumber, +, =. And we know that firstNumber is the first number 2, secondNumber is the second number 2.

Now computer takes firstNumber and store it inside CPU. Next he takes secondNumber and store it inside. Now he needs an operation which is a plus sign(+). So now CPU add those two numbers.

Computer gets a number 4,now it sees that there is a equals. In our language says give this result to us.

It was pretty simple, right? When computer needs to remember something along a line, then first he uses a RAM. Random Access Memory is super fast way to remember what we told computer, but computer can't do what was asked at this moment. He needs to store it temporarily, because there is something more important to do. But don't worry, CPU is very fast, so it should take a long time to process our request.

But what when we want to tell computer, to do many jobs? RAM is fast memory, but can't store as much as HDD or SDD. Hard drive stores many information which are a little bit slower to get, but it allows computer to focus on simple and the most important instructions to process at that moment.

To summarize,

Computer needs simple instructions, it takes numbers and make operations to them, the rest is what people do with that result. so when you 2 + 2 and get 4, in real life you want 4 apples but apples are in separate boxes. so you need to take 2 apples from one box and take 2 apples from another box. Sum should be 4. We can make it more complex, but to make complex, first you need to solve simple problems. The same applies to a code. Computer solves simple problems, we take simple solution and find other simple solution, and at the and we solved a complex solution.

To make it more real world example, let's make a sandwich. If you have never made a sandwich before, then you need a recipe to follow instructions to solve this problem. Recipe in computer world is called algorithm.

Algorithm is a set of instructions where you put some input information, follow instructions and get some kind of outcome which is our product of following instructions using information which we get at the beginning.

Let's get to ++make a sandwich++.

Ingredients:

a Bread, a salad, a butter, a ham slices

Instructions:

cut a bread to a half

apply butter to both halves

put slice of a ham on a bread slices

add salad on top of a ham slices

Result:

Sandwich with butter, ham and salad

So let's compare it to computer algorithm. Let's add two different number and get a result of addition at the end:

Starting information:

number 2,

number 3

Instructions:

take number 2,

take number 3,

add number 2 to a number 3

take result of addition

give result number 5

Ok, instructions were clear, but what if we want to know what is 2+4? We would have to make new recipe/algorithm. But it takes time! So why not make it more universal. Ok, so let's make it again, but now let's change some instructions.

Starting information:

number 2 but stored in box called numberA,

number 4 but stored in box called numberB

Instructions:

take number from box numberA,

take number from box numberB,

add number from box numberA to a number from box numberB

store result of adding numberA and numberB in box called resultNumberC

take result from box called resultNumberC and give a result number.

result number is 6

Uff, there is a lot of information to process, but don't worry it won't go anywhere because it's blockchain :) You come whenever you want.

My next article will take algorithm and I'll try to make it more like a code. For know we will call it a pseudo code. But stay tuned for next part.

If you have and questions, feel free to ask and rate.

Sort:  

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).


 
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 

Congratulations @grzegorz2047! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 1750 upvotes.
Your next target is to reach 2000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP