Monday, January 27, 2014

First time Ruby

It was also my first time using codeacademy and so far I like the way it teaches us or how it works in general. Codeacademy is very simple and easy to use, it is also free, and it's lessons are short and very simple worded. I personally love it and I wouldn't mind using it to learn other programming languages as well.

Now on to Ruby, so far I have completed 25% of the entire Ruby lesson/section or whatever you call it.  So far I have learned the basics, which were data types, string methods, conventions, if-else, booleans, and I have just gotten up to learning loops. So far Ruby seems very simple and convenient in some areas compared to other programming languages that I have learned. Java is my native language or my very first programming language and I know some masm/ assembly code and little bit of c from my assembly class last semester. I will compare Ruby and Java since they are both high level object oriented programming languages.

Both Java and Ruby seem to be very similar in many ways in terms of their programming style, so I will pretty much focus on what Ruby does that I found interesting and what Java does not. Also since codeacademy is where I have learned how to program in Ruby, most of my references will come from the codeacademy website (http://www.codecademy.com/dashboard).

1. The way Ruby gathers input. From the exercise, the line that ruby gathers user input is (user_input = gets.chomp). "user_input" is the variable name, "gets"is what literally gets the input, and chomp is used to trim the fat, or is basically like the trim function in Java. This was interesting to me because in Java, in order to gather input from the user, you would need to import a scanner, declare a variable for the scanner then make the line to get user input. but for Ruby, all you need to do is put that one line of code, which is also only like 3-4 words long as well.

2. In Ruby you can chain String methods! For example, (String_name.method1.method2.method3. ..). That really tripped me out and I thought it was really cool. But then again I think you can chain string methods to strings in Java but it would get very messy and sometimes confusing. I guess how Ruby does it, it makes it so that it is cleaner and simpler.

3. In Ruby, it has a special function for (!). Basically what it does from what I have learned so far is that , you could use the (!) character after a string method to replace the current string it was set too. What I mean is lets say string1 = "word" . Lets say you want to put all the letters in string1 in uppercase. So in Java you would do this [string1.toUppercase()], but it will only uppercase the string if you add the (toUppercase), meaning if you were to just print out string1, it will still come out as word. Of course in Ruby you can just do (string1.upcase) and  if you just want to print out string1, it would give the same result. But if you did this instead (string1.upcase!) then print out string1. It would print out "WORD." What this function does (!) is that it would override the current string and get rid of the old string forever. So it maybe useful but also very dangerous. 

4. Lastly in Ruby I found some methods/functions that I believe was pretty unnecessary. The "Unless" statement was made just to check if something is false. It is basically an If statement but the opposite. I felt it was unnecessary because you could just manipulate the if. I could see where it would be useful to some people but I feel like it is just redundant. Same goes to the "Until" loop function. "Until" is basically the opposite of the "while" loop. "While" keeps going till it is true but "Until" keeps going until it is false. 

So in all, Ruby is pretty similar to Java and there are some things that Ruby does better than Java, but I am still learning Ruby and these are just my personal thoughts on Ruby so far.