Skip to content

Lonely Operator vs Null Object Pattern vs try! chains vs present? chains #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
toobulkeh opened this issue Dec 26, 2015 · 5 comments
Closed

Comments

@toobulkeh
Copy link

Ruby 2.3.0 introduced the Lonely Operator:

https://bugs.ruby-lang.org/issues/11537

@mcmire
Copy link

mcmire commented Dec 26, 2015

We've talked about this before internally, and I don't think many of us are fans of this, as it encourages the use of nil to represent a meaningful value (when it truly shouldn't represent anything at all). It also makes violating the Law of Demeter really easy. We tend not to use try or try! for the same reason.

So I think it's one of those things that would be used sparingly, if absolutely necessary.

@toobulkeh toobulkeh changed the title Lonely Operator (> Null Object Pattern (> try! chains (> present? chains))) Lonely Operator vs Null Object Pattern vs try! chains vs present? chains Dec 26, 2015
@toobulkeh
Copy link
Author

So maybe a line in the guides suggesting a NullObject Pattern instead?

@mcmire
Copy link

mcmire commented Dec 26, 2015

That's what I would do. "Prefer the Null Object pattern over using try, try!, or the lonely operator (&.)." I'm curious what other people think, though.

@jferris
Copy link
Contributor

jferris commented Jan 4, 2016

It feels too early to write up a guideline on how to use this. Plenty of us have existing thoughts on nil and the Null Object pattern, but I'd suggest waiting until we have some Ruby 2.3 projects under our belts before jumping to conclusions.

@mike-burns
Copy link
Contributor

I'm going to close this. We can revisit the topic with a pull request when we have more usage of this operator.

(Also, I can't think of a guideline for this that fits our guides; our guides are things we agree on, but not a list of decision trees on when to use language features.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants