Archive for January, 2006

Ruby

Monday, January 9th, 2006

Well, I got around to ordering a Ruby book (Programming Ruby). It got here about a week ago and I finished it off in about a day or so.

Now that I’ve dove right into Ruby, I’ve found it to be a very nice language indded. Amongst the other reputable interpreted languages available for wide-spread use (PHP, Perl, Python etc), I can say I really like Ruby the best. Before I purchased this book, I didn’t know all to much and I couldn’t really say if I would like it. I knew that A) It was gaining traction and B) it had a fabulous framework called Rails (which was pretty much acting like a catalyst for point A).

Syntactically, it was not very famarliar to what I’m used to (C-style). For a lot of programmers, this fact alone could be a turn-off. But I’ve tried a bit of Python, and I knew that something as simple as using {} instead of the keyword ‘end’ (for example) doesn’t really make a difference. But I was somewhat surprised to see some things that I always expected to see in any language, done quite differently. For example, there is no ‘for’ loop (perse, there is actually one but Ruby will internally replace it with what I show here). A for loop in PHP, for example, might use a variable that counts from 1-100 like so:

for($i = 1; $i <= 100; $i++)
    echo $i . “\n”;

In Ruby, you use methods and a very useful feature called blocks. Blocks allow the programmer to associate a block of code with a function call. The block of code can be called inside of the function. The same PHP code could be written in Ruby:

1.upto(5) { |x| puts x }

Since Ruby is a true OOP language, everything is an object. The literal number 1 is an object of type Fixnum (which is a subclass of Integer), and it has many useful methods that we can use to easily do what we want:

# Count down from 50 to 40 (50, 49, 48 … 40)
50.downto(40) { |x| puts x }

# Count up from 5 to 100 by 5’s (5, 10, 15 … 100)
5.step(100, 5) { |x| puts x }

# Just repeat 3 times (Ho Ho Ho)
3.times { print ‘Ho ‘ }

When I got to using Ruby, there were a bunch of little things that are very intuitive and elegant. If you have not already, give it a go and see if you like it! And I want to say that Rails does not make Ruby. If you don’t like Rails, then you don’t have to use it — another common misconception I hear about is people complaining they don’t like Rails and therefore won’t like Ruby. Ruby != Rails.

php|architect

Tuesday, January 3rd, 2006

php|a is a magazine directed towards PHP developers. It’s the most successful magazine that focuses purely on PHP. They release an issue every month and they’re on their 4th year so far, with no signs of slowing.

I just ordered the last 4 issues (they offer both a digital [pdf] and printed version), and I really like it :-) If you are a PHP developer then I think this magazine will interest you greatly. While it doesn’t really hold content you couldn’t find online somewhere, it’s composed and written for you. That means every month, you get a range of topics that you might not have thought about before! December’s issue held an interesting article on Drupal — which actually prompted me to try the magazine in the first place.

(And before anyone comments: Yes, I’ve said I don’t like PHP in the past. But that doesn’t mean I’m going to give it up ;-) I still develop with it on a daily basis.)

Happy New Year!!!

Sunday, January 1st, 2006

^^ Happy new year everyone!