Ruby Ruby Ruby

I’ve started poking around with Ruby. Why?

  • Because I always like to learn something new
  • Because Ruby has been on my list for some time now
  • Because there was a book on sale (20$ for e-book and book…that’s a bargain!)
  • Because it’s the only programming language I know of, that has its own song (sorry!)

At work I spend most of my time burried in Java code and I’d like to try something else. I think it’s healthy to see if this really is the best, or if perhaps the grass is greener somewhere else. I mean, Java is a nice language but it feels heavy sometimes, or perhaps it’s the environment surrounding it that feels heavy. The fact that I’m mostly doing JEE related stuff probably doesn’t reduce the heaviness. JSR this and JSR that, loads of dependencies, build tools, deployment descriptors, web.xml, MANIFEST.MF and so on and so forth, not something I’d like to tinker with at home.

First Impressions

I’ve not read anymore than three chapters of the pickaxe book and I’m just starting to create my first classes but so far I have to say that I really like Ruby, it just seems…I don’t know, friendly or thought through.
A tiny example:
I’ve always taken for granted that you had to write your getters and setters yourself (or have your IDE do it for you) so just a simple thing as attr_accessor was great…wait what! you mean I just write

attr_accessor :name, :age 

and that’s it! No more getters and setters..whaau!

On Blocks

I’ve just started looking into blocks and I can see that this is smart and efficient, but at the same time I know that it’s something that I really have to work with in order to use start using it, and using it properly, I mean, I could get away with just doing “Java” code in Ruby and it would probably work.
For example this:

arr = [1,2,3,4,5,6,7,8,9]
for i in 0..arr.length-1
	puts "here's #{arr[i]}"
end

works fine, does the job, there are no errors and it looks like code I could write in Java (apart from the fact that I’d probably use some sort of list and an iterator but nevertheless).

but…since blocks exists, it could also be done like so

[1,2,3,4,5,6,7,8,9].each {|val| puts "here's #{val}"}

Which, to me looks and feels much more elegant but it’s just not something that I’m used to since I’m mostly writing and reading Java code. Hopefully this’ll get easier as I progress.

That’s about as far as I’ve read until now. I look forward to reading more and to writing some more Ruby code.

One thought on “Ruby Ruby Ruby”

Leave a Reply

Your email address will not be published. Required fields are marked *