First steps

The terminal (this “little” thing…) and Ruby

When I started my apprenticeship three weeks ago (already?!), my super-mentor Rabea assigned me a few tasks I had to accomplish for my first IPM (“Iteration Planning Meeting”) with her which was taking place the week after. During these IPM’s (which are scheduled once a week), we set up the tasks I have to accomplish week by week (we call them “stories”, which form an “iteration”), we talk about my achievements, we go through any issues/doubts I could have encountered during the week, and so on.

My first iteration included, among others, a sort of online course to become confident with using the terminal. Now, the first question that came up my mind was: what is a terminal??? Quite a great start… ah? Now, what I learned in a nutshell is that the terminal, or command-line interface, is a means of directly connecting to the soul of your computer by inserting a command on your shell. Or, if you prefer a Wikipedia definition, “a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines).” Now, this is pretty a cool thing as through your terminal you are able to do magic things like create a new directory, change the name of your directory, create new files into your directory, move to different directories/files, and much more stuff like that, without using your mouse. And then you can also do very bad things, like accidentally erase everything contained in the desktop of your computer (which I have done, of course…). The truth is, when you erase something through your terminal, well, you must be prepared to lose it for good. Yeah. Bye-bye, desktop-as-I-used-to-know-you. So, be careful with your rm -r command…

Another interesting story included in my first iteration stated “Ruby: learn the hard way”. Hmm, encouraging. I didn’t even know what Ruby was yet, and I was supposed to learn it “the hard way”. Actually, that was the name of an online course for beginners Rabea suggested me (learnrubythehardway.org). It was meant for beginners, so no panic.

What is Ruby? I quote, from Wikipedia:

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz”Matsumoto in Japan.”

Now, what I knew about programming languages when I firstly approached coding was that each programmer had their own favourite language, and according to them the one they were currently using was actually “the best”. So, whenever I talked to a programmer they would suggest me a different language all the times, and they would explain to me why that language specifically was the best language. Now, as far as I knew about programming languages, they looked (and still look…) all the same to me! But my super-mentor has told me I have to start with learning Ruby, so it shall be Ruby!

Let’s analyse Wikipedia’s definition. Ruby is a “dynamic, reflective” language. Even if I have never dealt with programming languages before, I can say Ruby is quite intuitive and, light. With that meaning that to me it seems very clear and straightforward. I am not sure whether this is what Mr. Wikipedia meant, but whatever. And how do I know Ruby is more clear and straightforward than other programming languages?? I don’t. But I was told so from other people as well. And, when it comes to Ruby’s syntax, I can superficially tell quite a difference compared to other programming languages’ syntax. Furthermore, Ruby is an “object-oriented” programming language. Well, even if this is a concept I have come across quite often, I still have to find out what this actually means. Therefore I will skip this part.


So, once I was able to use my terminal, I could finally start writing some code using a code editor. The first thing I learned was how to print a string. A string is a sequence of characters (letters, numbers, other characters) that you want the terminal to return to the user. It can be contained between starting single(or double)-quote(s) and ending single(or double)-quote(s). If you write these formulas on your code editor:

puts “My name is Gabriella.”
puts “What is your name?”

and then you run them through your terminal, what your terminal will return is:

My name is Gabriella.
What is your name?

In the same way, you could write something like this on your editor:

puts 5 + 3 / 8 * 10 + 23

and run it through your terminal, which would return this:

28

You have actually written a program. Cool, ah?? Well, it was cool for me the first time.

Another exciting thing I have learned so far are the variables. Variables are a very nice thing because they allow you to store in one single word = averyverylongorcomplexexpression that will return a value, so that whenever you need that value again throughout your code, you will only need to write the magic word. What you have to do is put your word (or variable) into this #{} in your string. Here’s an example:

news = “tomorrow it will rain again”
puts “I have read in the newspaper that #{news}. If the newspaper states that #{news}, than #{news}.”

What your terminal will return once you have run your script is:

I have read in the newspaper that tomorrow it will rain again. If the newspaper states that tomorrow it will rain again, than tomorrow it will rain again.”

You can also assign the value of a variable to another variable. Check this:

chickens = 33
cows = 24
animals = chickens + cows
puts “In my grandma’s farm there are #{chickens} and #{cows}. In total there are #{animals} animals.”

The script, once run, will return this:

In my grandma’s farm there are 33 chickens and 24 cows. In total there are 57 animals.

But you can also write this:

animals = 2
x = “In my grandma’s farm there are #{animals} types of animals”
one = “chickens”
two = “cows”
y = “Some are #{one} some are #{two}.”
puts x
puts y

What your terminal will show once you have run the script is this:

In my grandma’s farm there are 2 types of animals.
Some are chickens and some are cows.

You can also ask the user a question and allow them to insert an answer on your terminal (this is reaaally cool):

puts “Hi! What is your name?”
name = gets.chomp
puts “Hi, #{name}! Nice to meet you!”

This is what you will see on your terminal once the code has been run:

Hi! What is your name?”
Brad (or-whatever-name-the-user-has-typed-in)
Hi, Brad (or-whatever-name-the-user-has-typed-in)! Nice to meet you!

Kind of fun! Thanks to the method (or command) gets.chomp, it is possible to get an input from the user. That input can be assigned to a variable (in this case, the variable name), and its value reused multiple times. There are a lot of more methods in Ruby, and I have just started to look at some of them. Another interesting method is .to_i: this returns your string as an integer. Or, vice versa, .to_s returns a number as a string. Tricky!

Roughly, this is what I have learned during my first week at 8th Light. Lately, I have discovered the functions, but this is another story. Functions are getting me stuck most of the time… but, honestly, the same occurred with the variables, at the beginning! Coding means also getting stuck, and frustrated, sometimes. But also getting a lot of satisfaction, once you get it!