Yes, this may sound a little strange to some people, especially the more traditional ones, but that is what I am proposing in this post.
My first experience with a programming language was in 1997, with Pascal, a language created in 1970 by Niklaus Wirth, whose main goal was to encourage the use of structured code, especially for teaching.
Here is a small example of a logical test in Pascal:
program Testelogico;
var a,b:integer;
uses crt;
begin
clrscr;
writeln ('Digite um número para A');
readln (a);
writeln ('Digite o número para B');
readln (b);
if (a = b) then
writeln ('A é igual a B')
else
if (a < b) then
writeln ('B é maior que A')
else
writeln ('A é maior que B');
end.
We can see that this code requires learning several concepts related to the language’s structure itself instead of focusing on the problem. For example, it requires parentheses and a semicolon at the end of a block, as well as the classic rule that you do not put a semicolon before else, because the semicolon is used to end programming blocks.
Ruby is a language created by Yukihiro Matsumoto and designed for large-scale programming combined with fast coding. Here is the same example in Ruby:
print "Entre com o valor de A:"
a = gets
print "Entre com o valor de B:"
b = gets
if a == b
print "A é igual a B"
elsif a < B
print "B é maior que A"
else
print "A é maior que B"
end
Besides requiring less code and making things simpler, the learning curve also tends to be shorter, because we no longer have to keep track of language-structure rules. The if-else block does what it is supposed to do without our having to worry about whether we forgot a semicolon.
We can see an even more convincing example with loops that have a known endpoint. Here is a Pascal example that displays the word “teste” ten times:
Program repeticao
var
i : integer;
begin
for i:= 1 to 10 do
writeln("teste");
end
To write this simple example, I had to go through the bureaucracy of naming the program, creating the variable, and only then writing the routine. Here is the same example in Ruby:
10.times do
puts "teste"
end
Or:
10.times { puts "teste" }
Can you see how dramatically simpler Ruby code is? Some routines are almost like writing a sentence in English (a human language). Instead of needing to know that the loop will increment the value of a variable i from 1 to 10, I simply ask it to print the word “teste” ten times.
Combine that simplicity with the fact that Ruby is fully object-oriented. In addition, together with the Rails framework, it can be used professionally to develop web systems. I think that is enough reason to retire Pascal for good (it is still widely used in academic settings and technical courses as a first programming language alongside algorithms) and move to a simple, productive, general-purpose, and even fun language like Ruby.
Remember, I am suggesting it as a first language; you can continue using it afterward or not. Whenever possible, it is very important to learn other languages to gain different perspectives.
Best wishes, and until the next “Think about it!”