On 04/13/2011 12:34 AM, jcbollinger wrote:
> You can include unparameterized classes any number of times, and it
> means the same thing whether you include a class once or a hundred
> times.  This is one of the fundamental characteristics of Puppet
> classes, and a feature that I personally put to good use.  There is no
> reason in principle why you should not be able to include
> parameterized classes multiple times as well, provided that the
> parameters are everywhere the same for a given node.  My expectation
> for such a case would be that the effect is the same as including the
> class only once, just as for unparameterized classes.

John,

I used to think along the same lines. Not anymore. As a matter of fact,
I don't think non-parameterized classes should be considered equal to
their parameterized counterparts. They are different concepts with
different uses (which are unlike defines', see below).

It can be useful to be able to include things in multiple places and
leverage the "singleton" qualities of non-parameterized classes.
For the things you *do* parameterize, you will typically want to be sure
it won't get included anywhere far from node level.

Being an 0.25 person, I have to rely on dynamic scoping here and there.
The scoping problems are horrible, so most of the time I end up
declaring variables near node level and immediately include the class
that uses those variables.
Parameterized classes allow for this to be written somewhat more
explicitly, but I don't expect them to become as flexible (wrt.
distributed inclusion) as non-parameterized classes (anymore).

Don't even get me started on distributed inclusions of classes that do
expect dynamically scoped variables.

> Defines are altogether different: they are resource types written in
> Puppet DSL, much more akin to File or User than to any class.  Whereas
> it must be an error to include a class two or more times with
> inconsistent parameter sets, multiple instantiations of a define
> *must* differ, at least in their titles.  Whereas multiple inclusions
> of the same parameterized class (with consistent parameters) should
> mean the same as a single inclusion of that class, multiple
> instantiations of a define model separate resources to manage.

I *think* Patrick knew that ;)

> Defines are nevertheless relevant to the discussion, because they can
> indeed serve in most of the roles for which parameterized classes are
> suggested.  Since parameterized classes can only be included once
> anyway, the most significant distinction between a parameterized class
> and a define is largely mooted in practice.  This then begs the
> question: for what purpose are parameterized classes uniquely useful?
> I may be missing something, but the only things I come up with are

Technically, you can replace each and every parameterized class with a
define that bears a label "use this only once per node!" (which I've
done in places with 0.25, as a matter of fact). Yes, it works. Yes, it
has largely the same effect as a paramerized class.

But that's horrible design practice! Parameterized classes represent
collections of unique resources. Drawing on the define paradigm to get
something similar is ugly.

I've talked a to Dan about this during the Berlin Meetup, and it was my
impression that the vision is that future manifests should
1) declare most used classes near node level and
2) have interdepending classes produce failures when dependencies are
missing (whereas in the 0.25 age, you would include dependencies and be
done with it)

This sounds very sane to me, but I haven't had a change to really dabble
in that type of design myself. For this discussion's sake, I'd be
honestly thankful to see some examples of classes that should both be
parameterized and multiple-includable. (Yes, I am making up terms as I
go ;-)

Regards,
Felix

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to