Skip to main content

Hello, world!

If you have some experience in programming, you have probably seen this quote uncountable times. The Hello, world! start is always a good start. With such a simple meaning, it can make you learn a lot of useful things about the language you want to learn. We will take C++ as an example. This is the code that makes that beautiful and simple quote to appear on your screen:

#include <iostream>
using namespace std;

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

First of all, you will notice the #include <iostream>. From now on, you have to remember to include that library when you want to use the stdout or stdin. Then, we have using namespace std;. Although this line can be omitted, it is way better to include it in our program. Otherwise, we would have to add std:: before every single token calling a function inside the Standard Library, so the fifth line would be:

std::cout<<"Hello, world!"<<std::endl;

And that can be kind of frustrating, specially when one of those devilish std:: is missing, and we spend even hours debugging our code until we find out that almost invisible mistake. So, as a life advice, always write that line, even though we are not going to make use of any of its features (don't take that seriously, if you are completely sure you won't need it, you can remove it, mainly for optimization).

All after that, comes the start of the main function: int main(), not a strange thing to someone used to C-based languages. From this, you learn that all of the code that will be executed must be written or called inside this function.

Then we have the cout instruction, which is a normal instruction to make use of the stdout. The endl instruction will just print a new line when used within a cout instruction. And finally, we have return 0;, which simply means that the main() function returns a 0, the integer equivalent of a null value. In modern versions of C++, this can be omitted, and the compiler will obviate it.

But, is this a C++ blog? No. So, why don't we talk now about ALB? In ALB, we can make use of the stdout very easily, as it is shown in this code, that would print Hello, world! on your screen:

BEGIN
 out {
  :string "Hello, world!" NEWL ;
 }
END

So, first of all, you must remember that, in the same way as in C++, where the executed code must be inside the main() function, here, in ALB, that code must be between the BEGIN and END keywords, that indicate the beginning and the end of the executed part of your code, respectively.

And after this, we have an out structure, the equivalent of C++'s cout. Inside curly braces ({}) we have to, first indicate the type of output we want to get (in this case, :string or :str), that can be a string, an integer (:int), a floating-point number (:float), a single character (:char) or a variable of any type (:var). After that, we specify the string we want the program to show ("Hello, world!"). To end the :string output, we also include NEWL, which works exactly the same as C++'s endl.

Finally, we close the out structure and the executed program chunk, with a closing curly brace (}) and the END keyword, respectively. You must also remember that every command must end with a semicolon (;), except for keywords as BEGIN, END, VAR, ENDVAR, and structure-opening commands, such as out, repeat loops, if / elif / else conditional structures...

You should also know that this is not the only way to make use of the stdout in ALB. In the next lesson we will talk about special (or specific) outs, which are basically outs that can just write one output at a time, and of a specific type. That is why there are as special outs as types in ALB.

To sum up, in this first ALB lesson we learned:
  • How to specify the executed code (BEGIN and END).
  • How to make use of the stdout with an example using the string type (Hello, world! example).
  • That every command must end with a semicolon, except for the ones specified above.
  • And a bit of C++.
 Also, if you want to know more about the Hello, world! tradition, I recommend reading this article posted on Wired.
See you in the next lesson, and keep coding!

Comments

Popular posts from this blog

What is ALB?

First of all, welcome! This is the official blog of ALB. Here we will post news, updates and some other things related to it. But... What is ALB? ALB has been created as an open-source project by me, Alberto Navalón, with the objective of creating a useful and also powerful programming language, such as others like C++, Java, Python... What's the purpose of it? Whatever you want! This language should be suitable for anyone who wants to use it: a game developer, a mathematician, or even a kid with eager to learn! By now, this is just an idea. But together, we can bring this project to the world, and make it fly, and let people create unimaginable things! That would be awesome, wouldn't it? Some people would reproach us that we are crazy, but do not listen to them. If you are a professional developer, an student, or just someone that wants to learn more about programming languages, open-source projects, or any other thing, come and join us! And remember, It is sometime...

GitHub for ALB!

We are glad to announce from the ALB Developers Team, that we have a GitHub repository! Here you all can propose changes and contribute by providing your code, your documentation and your ideas. To do so, and if you don't have one, you just have to create a free account, and start contributing. It's very easy! Also, if you don't already know what GitHub is, feel free to check out this video: You can go to our repository by clicking here (or copy and paste this URL in your preferred browser: https://github.com/albertonl/alb ). We are eager to see your contributions!