Movies move our imagination, make us dream and sometimes believe, fear and also cry some others. But not everything that comes from films belongs to the reality, most of what is sold in them are exaggerated or even mystified to create a better response in the audience.
What is programming all about?Today’s world is a digital world. Every day we are using more and more electronic devices in our daily tasks in our job, social networking or just for fun. That’s the reason why these devices have become a significant asset in our life. Despite their great utility, these devices are not really that intelligent, they only are capable of processing data, based on a set of instructions given by humans, and giving back a result to the user.
That data could be of any type, for example: in a sudoku game, an initial value could be the touch of a tablet’s screen indicating the position where we want to add a number.
The process then would be the calculation of the box that corresponds to the area we just pressed, and the result would be the enabling of the exact box we wanted with a numeric keyboard at its side to let us enter the number.
All the electronic devices we use, are able to work thanks to some lists of instructions they have within them, those lists indicate them what kind of data they have to expect, how to process it and which output they have to show a result.
Those sets of instructions are known as programs.
Programs are a set of ordered steps that are necessaries to accomplish some task.
They work the same way a recipe does, instructing to the chef in how to prepare a dish:
- showing which are the needed ingredients (input data),
- how is the preparation of these ingredients (Process)
- and which have to be the result (output).
But, as a programmer, you don’t need to use binary code to write a program (you can but doing so could be painful).
To help us in that process there exists a lot of “intermediate languages” named Programming Languages.
Some of the most known are BASIC, C, Visual Basic, Java, Python, C#, PHP, etc.
Once you write a program in any of these languages, all the instructions you wrote must pass through a “translation process” to the machine language to be understood and executed by devices.
This translation process can be done in one of two main ways: By the compiling process or the interpreting process.
COMPILING AND INTERPRETING
The compiling process is similar to receiving a letter written in some foreign language, let’s say French for example, and translate its entire content to the English language and then, publish it to be understood by English speakers.
On the other hand, in the interpreting process instructions are translated line by line, one at the time and immediately sent to the machine to be executed. This is like the process a translator does in a conference: Translating instantly each sentence the foreign speaker says, so the public can understand the information. The translator doesn’t wait until the end of the speech to translate; he made it right after the speaker talks.
Sometimes these two processes are combined, as is done in the Java programming language. In Java, there is a compiler that first compiles all the code to an intermediate code (devices are not able to understand that code), and then there is an interpreter that receives all that intermediate code and interpreted it one line at the time, making the devices able to execute it.
- The objective of our program
- The inputs it must receive
- The output it must give to the user
With all these things clear, now we are able to write an algorithm.
But, what is an algorithm?
Let’s suppose by a moment that we are movie producers and we want to create a new action film. We have an idea about the main story we would like to show, and maybe we even have some preferences in the cast that could participate in our film but, in order to start this new project, we must write a script to have a complete description of the movements, actions, expressions and dialogues of the characters of the movie.
It is a similar process in programming, the first step we must take, just right after knowing the need that motivates it, is to write a script about what is going to be done in our program, this script is named Algorithm.
Algorithms must fill some specific characteristics:
IT MUST HAVE A START AND AN END,
It looks like obvious but is very important for our algorithms to have an initial point and a final one after completion of a set of task.
The image at the left shows an example of an algorithm that will never end
It must express clearly each of the instructions or steps to follow,
Every step in the algorithm must be clear and precise, for example, instead of describing an action like: Write information about your best friend, it must be concrete and say: Write the first and last name of your best friend.
It may have initial values,
Those initial values or inputs are the information that’s going to be processed. An example could be that if we want to write an algorithm to add two numbers, the algorithm must first know those numbers.
This initial data could be defined within the algorithm or be provided by an external source.
It must return some outputs,
For general use conventions, algorithms are written in a human-readable language and not using programming languages.
After the completion of our algorithm, we can then write our program in the desired language and pass it through the “translation process” to the machine language to be executed for machines.
- Electronic devices we use work thanks to lists of instructions they have within them, known as programs
- Programs are a set of steps that indicates to machines how to process data
- Programs are written in programming languages and then translated to the “machine language” through the compilation process or the interpreting one.
- To write a program we must have clear: the goal of it, the inputs it will receive and outputs it will produce
- Algorithms are the scripts that help us to define what is going to be done by our program to accomplish its goals.
- Algorithms must be: finite, precise, have initial conditions and produce some outputs.