https://www.puppet.com/community logo
Title
h

hbui

05/25/2023, 4:50 PM
when referencing a parameter in a class manifest is the preference to reference it as the full class parameter or as the short version:
class profile::mysubclass (
  String param1 = 'foo',
){
  # is this preferred
  if $profile::mysubclass::param1 == 'foo' { }
  # or this
  if $param1 == 'foo' { }
}
are there any pitfalls to using just
$param1
?
g

Graeme Donaldson

05/25/2023, 4:53 PM
short version is fine 👍🏽
n

natemccurdy

05/25/2023, 4:53 PM
It's standard to use the short version (i.e. local scope version) when in the same scope that the variable is created. The fully-scoped version is used when referencing that variable outside of where it was created.
h

hbui

05/25/2023, 4:54 PM
thanks
b

bastelfreak

05/25/2023, 5:07 PM
shorter scope is also faster 🙂
r

ramindk

05/25/2023, 5:28 PM
I'd prefer the local var in that it avoids other signals when reading the code. If I come across a fully scope variable I'd assume a special case and start looking for it.