The Switch: Surviving the bullets of a new language.

It has been a few weird weeks of diving into this new thing called Ruby! Ruby is weird!

Having played around with other languages become starting out in the Ruby land, my journey so far has been kind of mixed-feelings "thingi". I almost wanna go on strike with Ruby but then some of its parts are interesting. For now, let me point out some pain points I have so far run into.

The language construct

While starting, basic language constructs threw me off. Things like data types felt like missing parts as they tend to deviate from the usual path other languages follow by having primitive data types and objects. Ruby instead has [almost] everything as an object? That's weird!

I expected to find primitive data types like 'char', 'byte', 'int', 'double', 'float', etc. but that wasn't the case. Ruby being a dynamically typed language, data types are instead implied and you can't really notice what's happening as a beginner until you get to use the 'until' loop, LOL. Wait, what the hell is 'until' loop anyway? Up next... read on.

The weird flow control

Once you try to make sense of the basics, you get thrown into flow control that doesn't seem to make sense. Here is the until I was talking about up there

num = 9
        until num == 11 do
        # code to be executed
        puts num * 10
        num += 1
        end
        

The weird case ... when sample

case expression
        when expression 1
            # your code
        when expression 2
            # your code
        else
            # your code
        end
        

And oh, wait a minute! Where is switch? if this stands in for switch, what's else doing up there? I am still wondering too. :)

Looking at that thing, it's hard to connect the dots for quite a while.

Coming from another language, I saw that some of the things are missing their evil twins! Like the while loop is missing the do ... while loop. Why that? That I don't know too.

The scary and weird syntax

Scanning around, I also noticed a lot of differences in style things are done in the Ruby village and that just looks scary at the start. Once seems to have no control in how things should work. Here are a few syntax comparisons between Ruby and Java:

for loop in Ruby

for variable_name in expression [do]
        # code to be executed
        end
        

for loop in Java

for (statement 1; statement 2; statement 3) {
        // code block to be executed
        }
        

foreach loop in Ruby

collection_name.each { |temp_variable_name|
        # code block to be executed
        }
        

foreach loop in Java (Java calls this thingi enhanced for loop)

for (type tempVariableName : collectionName) {
        // code block to be executed
        }
        

I have so far gotten comfortable into unlearning what I know from other languages and just settled for what's on the plate from this while beast, Ruby!

Again, Ruby is weird!
        Ruby is a bug; we should fix it!