On Fri, Oct 16, 2009 at 7:44 PM, Markus <[email protected]> wrote:
>
>> I've tried to not comment on this, but I'm failing, and I'll try real
>> hard not to rehash well-known examples, issues, and languages.
>>
>> Instead, would it be more Ruby-ish to monkeypatch the Object class: e.g.,
>
...the idea of providing a more
>> readable check for a common idiom is a reasonable approach.
>
> Uh, no.

Apparently I did not adequately point out that what I wrote is an
illustration of an approach, not intended to be legal Ruby.  I'm fully
aware it's  not legal Ruby, but was using it as a pseudo-code example.
 My apologies for that confusion.

>
> 1) "defined?" is special syntax, ...

> 2) The issue isn't the syntax, it's the semantics.  Having a "cleaner"
> way to test (which this wouldn't be) isn't the issue.  Where the test is
> appropriate, defined? is perfectly acceptable.

I'm not sure we're talking about the same problem (which is why I've
hesitated jumping in): the point I'm trying to make is that when we
have idioms that 'smell' but are necessary, for example,

if defined? foo and !foo.nil ...

The 'Ruby-ish' way to approach this would be to monkeypatch and
provide something more elegant.

Unfortunately, as you point out, defined? is special, and can't be
used this way.  A def_method approach, as you point out, might be
doable from a programming standpoint, but would be really, really
ugly.

>
> 3) Even if all of the above weren't the case, "and !self.nil?" (assuming
> you just forgot the "?") in a global monkeypatch is a code smell all its
> own.  It will return true (and thus have no effect) everywhere but on
> the singleton instance of NilClass.  It should be omitted for methods
> such as this and they should, if needed, be overridden in NilClass.
>

Right, this is another point where Ruby's syntax is not as flexible as
one might desire.

Some languages can support this kind of construct (e.g., via a macro
system or lazy evaluation).  Ruby metaprogramming could perhaps be
leveraged to provide a richer check here, but it would be fairly
complex.

The main point, however, is that I think that running with warnings
enabled is a good thing to aim at.

Could you clarify what your take on the 'defined? foo and !foo.nil?'
idiom is? (e.g., 'not a problem', 'bad; we should do X instead', etc)
I missed what you think we should do with that construct in the
previous emails.

Thanks,
Steven

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to