Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

exceptions

This bug makes me a little sad. From one of the patches for fixing:
- @string = (str.string rescue str)
+ @string = str.respond_to?(:string) ? str.string : str

The problem is that the former method uses an exception handler, and when an exception is generated it includes a backtrace, and this particular bit of code gets called with very deep call stacks, so that bit of code ends up being expensive.

I think the fixed code better expresses what the code was trying to do -- the former one could imaginably produce strange errors if you had, for example, a typo in an object's "string" method -- but the underlying problem is the sort of leaky abstraction that endemic to programming in general and always disappoints me a bit with the state of our art.
Tags: ruby
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 6 comments