So I just wanted to be on the record on the internet giving a piece of advice.
ActiveSupport monkeypatches Object and adds a
#try method. This method has the following semantics:
1.try(:to_s) #=> "1" 1.try(:thats_crazy_no_such_method) #=> nil
Up until now I hadn't made it publicly known, but from here on out let it be: if you use
#try I think you're a horrible person. It's probably not your fault - maybe you were abandoned as a child, and so you're terrified that an object isn't going to be there that you were counting on.
I don't care. Every orphan programmer has to grow up to become confident at some point. The next time you use
#try in your codebase, please at least use it this way:
# NOTE: I have no idea how this code works and I'm too much of a lazy jerk to make it better, so.... thing.try(:who_the_hell_knows).try(:why_im_employed).try(:shucks)
Seriously. Stop using
#try. I don't blame people too much that have only just learned about it - I used it a few times too. But every time you use it, you've planted a flag in your codebase and announced "we're done here, this code will not get better from here on out."
NOTE: It's entirely possible that I've just been bitten by people doing this twice in the past two days, but it's infuriating every single time I see it.
Josh Adams is a developer and architect with over eleven years of professional experience building production-quality software and managing projects. Josh is isotope|eleven's lead architect, and is responsible for overseeing architectural decisions and translating customer requirements into working software. Josh graduated from the University of Alabama at Birmingham (UAB) with Bachelor of Science degrees in both Mathematics and Philosophy. He also occasionally provides Technical Review for Apress Publishing, specifically regarding Arduino microprocessors. When he's not working, Josh enjoys spending time with his family. <a href="http://www.erlang-factory.com/conference/show/conference-6/home/"><img src="http://www.erlang-factory.com/static/upload/media/1389191028314604speaker120x125gif" alt="speaker badge" /></a>