On Jul 20, 2008, at 6:58 PM, Daniel Pittman wrote:

>
> Luke Kanies <[EMAIL PROTECTED]> writes:
>> On Jul 20, 2008, at 3:59 AM, Daniel Pittman wrote:
>>> Luke Kanies <[EMAIL PROTECTED]> writes:
>>>> Why don't you try the recursive setting of instance variables and  
>>>> see
>>>> how it performs?  It might be sufficient.
>>>
>>> So, as expected this had the side-effect of making it impossible to
>>> detect when an undefined variable was used in a template.  This was
>>> quite a loss, in my opinion, and something I would rather not give  
>>> up.
>>
>> Why would that be the case?  Ruby has a builtin 'defined?' method:
>
> Ah, my explanation was unclear:
>
> ...this had the side-effect of making it impossible for Puppet to
> automatically detect, and signal an error, when the template used an
> undefined variable.
>
> At the moment a reference to an undefined value will raise an  
> exception,
> failing the catalog build.
>
> Using an undefined variable, after the change, will simply return
> 'nil'.  That gives up this (IMO, desirable) behaviour of treating an
> undefined value as an error.
>
>
> So, yes, the author could manually test every value was defined, but a
> typographic error in the template would go unnoticed.[1]
>
> What would be list is *automatic* checking.

Hmm, I think this objection isn't valid, because it's an objection to  
Ruby, rather than Puppet's use of Ruby.  That is, Ruby doesn't fail  
when you use an undefined variable, so Puppet probably shouldn't either.

I know in my own programming I'm very conscious of the difference  
between defined, nil, and having a value.

Given that your code directly exposes a lot more information to the  
user, I like it better, and I'd actually like to switch to it.  It's  
more like how other applications use templating (instance variables  
rather than method_missing hacks), and you can do things like list  
available variables, check whether they're defined, and a good bit  
more.  The method_missing hack requires that all of this functionality  
be provided piecemeal, as methods in the template wrapper class.

For the record, I came up with this hack while semi-drunk and talking  
to the CTO of Red Hat -- I was talking about how we were going to add  
templating as soon as I could come up with a means of doing so, and as  
I said it, I came up with this mechanism.  So, it was created in a fit  
of inspiration rather than one of those long-term visions, and it's  
always felt a bit hackish.

-- 
You've got to take the bitter with the sour.
     -- Samuel Goldwyn
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
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