leading double colons (::) for class instances

35 views
Skip to first unread message

Matt Zagrabelny

unread,
Jan 7, 2019, 4:31:51 PM1/7/19
to puppet...@googlegroups.com
Greetings puppet-users!

For many years I have been using the following convention for including my classes:

class foo() {
    include ::profile::bar
}

I know I don't need the leading double colon for including profile::bar, but at one point in time I thought it may have been a best practice or it would help prevent some sort of future pain point.

Is that still true? Was I ever correct?

What is the current best practice for namespacing included classes?

Thanks for any feedback!

-m

Matt Zagrabelny

unread,
Jan 7, 2019, 4:37:46 PM1/7/19
to puppet...@googlegroups.com
On Mon, Jan 7, 2019 at 3:31 PM Matt Zagrabelny <mzag...@d.umn.edu> wrote:
Greetings puppet-users!

For many years I have been using the following convention for including my classes:

class foo() {
    include ::profile::bar
}

I know I don't need the leading double colon for including profile::bar, but at one point in time I thought it may have been a best practice or it would help prevent some sort of future pain point.

Is that still true? Was I ever correct?

 
Needed to spend 30 more seconds reading before hitting send. Sorry for the noise!


Thanks for any additional feedback!

-m 

jcbollinger

unread,
Jan 8, 2019, 9:16:52 AM1/8/19
to Puppet Users
I observe that the voxpupuli thread slightly downlplays the scope of the issue as it affected Puppet 3.  Puppet's (long since removed) relative name resolution scheme looked not just at the namespace in which the name was used, as the voxpupuli discussion seems to suggest, but also at every ancestor namespace, in order, until ultimately reaching top scope.  I'm not sure where to find P3 docs any longer, but this behavior is summarized in the description of PUP-121, the issue for removing that behavior.

That only rarely bit people, but it bit enough people, often enough, that for a time it was considered best practice to always use fully-qualified names (which is effectively what the `::` prefix produces).  But Puppet, Inc. decided that the negatives of relative name resolution outweighed the positives, including the positive of minimizing breaking changes, so relative name resolution was removed in Puppet 4.  Nowadays, the :: prefix is accepted for backwards compatibility, but it conveys no additional meaning.


John

Henrik Lindberg

unread,
Jan 8, 2019, 11:01:40 AM1/8/19
to puppet...@googlegroups.com
> <https://tickets.puppetlabs.com/browse/PUP-121>, the issue for removing
> that behavior.
>
> That only rarely bit people, but it bit enough people, often enough,
> that for a time it was considered best practice to always use
> fully-qualified names (which is effectively what the `::` prefix
> produces).  But Puppet, Inc. decided that the negatives of relative name
> resolution outweighed the positives, including the positive of
> minimizing breaking changes, so relative name resolution was removed in
> Puppet 4.  Nowadays, the :: prefix is accepted for backwards
> compatibility, but it conveys no additional meaning.
>

Adding to what John said above:

There is no additional meaning for class names when it starts with '::',
it does however make a difference when referencing variables. If a
variable contains '::' (anywhere) it is always taken as an absolute
reference starting from topscope. Thus something like '$::x' is the
topscope $x, a '$x' is a local, inherited or topscope variable 'x', and
'$x::y' and '$::x::y' are exactly the same thing.

- Henrik
>
> John
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/325d0f92-98a4-462c-9378-ae189a22be5c%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/325d0f92-98a4-462c-9378-ae189a22be5c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Reply all
Reply to author
Forward
0 new messages