Re:Ruby 2.3.0 Released
by waylandsmithers on Friday December 25, 2015 @08:50AM
(#10791223)
Interested to see how people start using safe navigation! I personally tend to avoid `try` in Rails in favor of other `nil` handling patterns.
[ Parent
| on HN ]
Why? Genuinely curious.
Re:Ruby 2.3.0 Released
by chrisseaton on Friday December 25, 2015 @10:19AM
(#10791409)
'try' is relatively slow compared to other control logic, as allowing an exception to be thrown involves constructing an exception stack trace. This is slow in all VMs I know. Theoretically you could detect that the trace isn't used and remove it through escape analysis, but this is not easy, or you could do some crazy thing with lazily creating the stack trace, but that's a research project.
I wrote a script to benchmark some of the diff strategies for anyone curious. https://gist.github.com/hopsoft/ae361319c54bbcb4f8e2
Re:Ruby 2.3.0 Released
by jrochkind1 on Friday December 25, 2015 @11:17AM
(#10791536)
I think you are confused, `try` is not raise/rescue. The ActiveSupport `try` implementation does not involve allowing an exception to be raised.
https://github.com/rails/rails/blob/v4.2.5/activesupport/lib...
It should be as performant as other ways of checking for nil/empty.
Re:Ruby 2.3.0 Released
by chrisseaton on Friday December 25, 2015 @11:29AM
(#10791560)
Ah yes you're right - I was confusing this with raise/rescue.