diff options
author | John Keiser <john@johnkeiser.com> | 2015-12-18 09:18:53 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-12-18 09:18:53 -0800 |
commit | 5f3f5781a61b89cd7f2aa19ee462a0ad839dd3c6 (patch) | |
tree | f527bbea19b60acb898c0e3327d162fa0eedc531 | |
parent | e7efc9754ff85d99d36df1982c2e4d4766e92519 (diff) | |
download | chef-jk/nil-discussion.tar.gz |
Typosjk/nil-discussion
-rw-r--r-- | nil-discussion.md | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/nil-discussion.md b/nil-discussion.md index e34bd48664..f0fb966f91 100644 --- a/nil-discussion.md +++ b/nil-discussion.md @@ -73,6 +73,8 @@ Things we want to be true: but *not* valid for `default: lazy { nil }` (or more likely, `default: lazy { other_property_that_could_be_nil }`). +## Possible Solutions + The possible solutions I can come up with are below. I think the one that meets all our criteria with the least complexity is "Properties with no default or `default: nil` are valid", with "Properties with no default are valid" running @@ -107,6 +109,8 @@ property :config_path, String, default: lazy { "#{path}/default_config.ini" } ### Properties with no default treat `nil` as valid +This is tied with the next one for my favorite. + This passes all of the rules, and is simple. If the default is not specified, then we are giving you a default, and we should take our own steps to make sure it is a valid one. @@ -118,12 +122,14 @@ property :x, String property :x, String, default: nil # ValidationError when declaring this ``` -This is not intuitive. It's the least bad of the alternatives in my opinion, -as the failure of intuition would be revealed immediately on declaration with a -clear error message. +This is not intuitive. It's not terrible in my opinion, as the failure of +intuition would be revealed immediately on declaration with a clear error +message. ### Properties with no default or `default: nil` are valid +This is tied with the previous one for my favorite. + In this, we solve the above problem by treating `default: nil` as valid (but no other construct). I don't think any other problems remain. This is arguably a bit more complex than the previous one, but it's also less surprising. |