Ruby’s “Begin Rescue” and “Try and Catch”

Thanks to the book "Programming Language Pragmatics"
Programming Language Pragmatics
I'm beginning to appreciate Ruby's different notation for exception handling.

A sample:

begin
  value = 7 / 0
rescue
  print "Something went wrong! This is an error" 
end

The code above is to catch an exception. (In Java or C++ you would use try and catch)

Ruby also has got try and catch, but this isn't used for exception handling. It is used for implementing "Multi Level Returns".
A sample:

def search( name )
  # .. some fancy code here ..
  if filename.contains( name ) throw :found_it, filename
end

result = catch :found_it do
  search "one"
  search "two"
  search "three"
  false
end

In the sample above, result will be filled with the found filename. This can be
with the keyword "one", "two" or "three". If nothing is found result is filled with false. (the last value in the catch block)

I don't think I need the catch construct very much, but it's a nice feature!

Agile Web Development with Rails 2nd Edition – Part 2

Wel I've almost completely read the book while I was away on a summer holiday. I still like the book. Specially the Web 2.0 part has been improved very much. Also the RESTful routes part is interesting, but I don't see the direct need for it.

I still need to read the part about deployment, but after a quick peek, I think it's much completer and more mature then the description in the first book. Also it shifted the usage advice from fastcgi to Capistrano. Well an interesting chapter.

The Ajax part also hinted me about the "readystate 3" problem, which simply means that the web server should not use keep-alive with ajax. It looks like this is the problem I've encountered with a project of mine... Need to figure this out!

Agile Web Development with Rails 2nd Edition

agile_web_development_with_rails_2nd.jpgAfter a three week wait I finally got my ordered book: "Agile Web Development with Rails, 2nd edition". I remember the bookstore salesman "The book is in stock at my supplier, it will be here in three days...". Yeah right!

Last year I bought the first edition of this book, and a few days after buying I noticed there already was a second edition on the way. I felt pretty screwed. Tried to get some discount via Dave Thomas, but unfortunately I didn't get it.. Btw. I really think Dave is great writer and great developer, he always seems to anwers his email personally. Very good!

I told myself, I will not buy this 2nd edition book, I'm not paying the money again for a lot of the same content..

Well I changed my mind, (after viewing an illegal bittorrent PDF version)

And after reading through the depot application (again) I indeed found a lot of improvements and new things about rails I didn't know!

It again is worth the money.

Some highlights of new things I read ( Btw. I still need to read 400 pages ;-) )

  • link_to has a :method parameter. (Very usefull, didn't know this)
  • rjs templates, read about them never used them. Now I can see them in the Depot application
  • Ajax based cart, with nice update effects
  • form_for construct. Didn't know it existed, but I really like it!
  • request.xhr?
  • cycle, for automaticly cycling colours!
  • ... still need 400 more page to read, the items above are only items extra in the tutorial ...

Btw. Another great book from Dave I really advice you to read is "The Pragmatic Programmer From Journeyman to Master". I've got his book a few years ago and it's full of good advice and inspiration.

The coming days I'm not behind a PC, so I will not make a lot of digital adventures... Well I wil read some more in my new Rails book...

Now Oblivion Time ...