Language: EN

programacion-estructura-de-un-programa

Program structure

We begin to talk about programming through high-level programming languages (yay!🎉) To start, the first thing we have to talk about is the structure of a program.

By program structure I mean the way the code is organized and structured. It is the way we divide our code into parts, and how they relate and interact with each other to perform a specific task.

A well-defined program structure makes the code easy to read, understand, and maintain. In addition, a good program structure also makes the code easier to write, debug, and improve its performance (which translates into money 💸).

Code examples

The best way to see what the structure of a program is all about is to get into the nitty-gritty and put a “Hello World” program in different programming languages.

A “Hello world” is a program that simply displays the message “Hello world” on the console. Traditionally, it is the program that is used as an example to teach a programming language because it is simple and basic.

Well, let’s get to it!.

This is what a “Hello World” program looks like in C++

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
    return 0;
}

While in C# we could do it like this:

using System;

class Program {
    static void Main() {
        Console.WriteLine("Hello, world!");
    }
}

In JavaScript it would be simply:

console.log("Hello, world!");

Finally in Python it would be:

print("Hello, world!")

Similarities and differences

Let’s start with the most obvious. A program in a high-level programming language will consist of lines of text, which is what we call code.

These lines are compiled or interpreted by the computer to perform the actions we want.

Even in such a simple example, we already see that they have many things in common. For example,

  • Programs consist of lines (or statements)
  • Statements can be grouped into functions or blocks
  • The language provides certain predefined functionalities (in our example, displaying text on the command line)

However, there are also obvious differences. The lines are different, the words are different. In general, the same program, in different languages, has a different form.

Nor is it something that should seem very strange. In the end, it’s like speaking Spanish, French, or English. What you want to say is the same, but the words and phrases you use are different.

Also, as happens in languages, some languages are more concise, and others are more “long-winded”. That is, some languages need more words than others to express the same thing.

So don’t be overwhelmed by the differences in syntax. The important thing is that, more or less, all languages work the same. I don’t know how to say “I have a yellow bicycle” in Chinese. But almost certainly they have the concept of “have”, “bicycle”, and “yellow”.

Well, in programming languages it’s similar. Only in rare occasions, and very complex aspects of languages, do we really find differences. Which, by the way, is the most interesting thing to compare, and that we will see in this course 😉.

Of course, this is just a very simple example, for a first introduction. In a “real” program, the number of lines can be enormous, up to millions of lines!

Logically, keeping the structure of your program clean and easy to maintain will be one of the most important points as your program grows.