What I dislike about Ruby... (part I continued)
In a previous post I complained a little bit about Ruby stack traces not being too readable for a mere Java mortals like myself. I got some criticism for my artificial example not being Ruby-ish enough.
Point taken. I am only a mere Java mortal, and not a Ruby superhero. That's exactly why I do expect Ruby stack traces to be a little more readable in the first place. ;)
But after saying "mea culpa", I tried to run one of the "100% Rubyish" examples got in the comments to the last post:
The result was the following:
Eeee... Well. I think I was not that far from truth saying that readability of Ruby stack traces could be improved... ;)
If you are a mere Java mortal like me, ask your boss a bonus when you immediately understand why this exception happened in this context. ;)
Point taken. I am only a mere Java mortal, and not a Ruby superhero. That's exactly why I do expect Ruby stack traces to be a little more readable in the first place. ;)
But after saying "mea culpa", I tried to run one of the "100% Rubyish" examples got in the comments to the last post:
require 'pathname'
class Pathname
def size_without_images
return 0 unless self.exist?
if self.file?
pictExts = %w[ .gif .png .jpg .jpeg .bmp ]
myExt = File.extname(self.to_s).downcase
return 0 if pictExts.include? myExt
File.size self
else
self.children.inject do |sum, child|
sum + child.size_without_images
end
end
end
end
synergy = Pathname.new("c:\\tmp\\synergy")
puts "Size: #{synergy.size_without_images}"
The result was the following:
c:/ruby/lib/ruby/1.8/pathname.rb:189:
in `dup': can't dup Fixnum (TypeError)
from c:/ruby/lib/ruby/1.8/pathname.rb:189:in `initialize'
from c:/ruby/lib/ruby/1.8/pathname.rb:434:in `new'
from c:/ruby/lib/ruby/1.8/pathname.rb:434:in `+'
from test.rb:13:in `size_without_images'
from test.rb:12:in `inject'
from test.rb:12:in `each'
from test.rb:12:in `inject'
from test.rb:12:in `size_without_images'
from test.rb:13:in `size_without_images'
from test.rb:12:in `inject'
from test.rb:12:in `each'
from test.rb:12:in `inject'
from test.rb:12:in `size_without_images'
from test.rb:20
Eeee... Well. I think I was not that far from truth saying that readability of Ruby stack traces could be improved... ;)
If you are a mere Java mortal like me, ask your boss a bonus when you immediately understand why this exception happened in this context. ;)


0 Comments:
Post a Comment
<< Home