What is programming?
Programming is providing the necessary instructions to a machine or device so that it can work automatically.
In every program there are a series of elements that will always be present:
- Input: data or information that must be provided to the machine so that it can perform the desired operations.
- Ouput: information or result that the machine shows.
- Storage: The data, while being processed by the machine, needs to be stored in some way to work with it. Here we will talk about variables, vectors, matrix or other complex data storage structures, although in this course we will limit ourselves to working with variables.
- Processing: operations to which the data is subjected to obtain the desired results. They can be arithmetic, logic, loops, conditionals, etc...
The development of a program consists of the following steps:
- Definition and analysis of the problem
- Algorithm design using flowcharts.
- Program coding: obtaining the source code using the chosen programming language.
- Compilation: conversion of source code to machine language.
- Bug debugging and program checking.
- Operation: documentation and maintenance. In this course, due to the simplicity of the programs created, we will not go into this step, although it is essential that every good program be accompanied by good documentation and a good update plan.
When we talk about structured programming we are talking about a way of programming that is based on the combination of three orders for data processing:
- "Sequence"; ordered statements or subroutines executed in sequence.
- "Selection"; one or a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as
if..then..else..endif
. The conditional statement should have at least one true condition and each condition should have one exit point at max. - "Iteration"; a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as
while
,repeat
,for
ordo..until
.
There are a series of principles when designing software that are common:
- KISS: acronym for Keep It Simple, Stupid! This principle tells us that any system will work better if it is kept simple than if it becomes complex. Simplicity has to be a goal in development and unnecessary complexity must be eliminated.
- DRY: acronym for Don't Repeat Yourself. This principle talks about the duplication of the code, first of all because of the previous principle, and also because subsequent maintenance becomes more difficult since we do not know where we have to modify things because they are repeated on various occasions throughout the program and the inconsistencies multiply.
For further information about these principles consult here.