Puppet 4.0 Future Parser, Variable Case

295 views
Skip to first unread message

Matthew Walster

unread,
Nov 25, 2014, 8:38:09 PM11/25/14
to puppet...@googlegroups.com
There seems to be a little ambiguity in the documentation for the future parser, I was wondering if someone could clear this up for me -- I'm referencing https://docs.puppetlabs.com/puppet/latest/reference/experiments_future.html :

"Variable names may not contain capital letters. They are limited to lowercase letters, numbers, and underscores."

My interpretation of this in the past (future parser in 3.7) is:

cheesecurds: YES
cheeseCurds: YES
CheeseCurds: NO
CHEESECURDS: NO

However, a colleague of mine has understood this to be:

cheesecurds: YES
cheeseCurds: NO
CheeseCurds: NO
CHEESECURDS: NO

Would someone like to enlighten me as to which is correct?

Many thanks in advance,

Matthew Walster

jcbollinger

unread,
Nov 26, 2014, 8:47:42 AM11/26/14
to puppet...@googlegroups.com
I don't think there's any room to interpret "may not contain capital letters" and "limited to lowercase letters, numbers, and underscores" as "may contain capital letters at some positions".  If some version of Puppet happens to accept 'cheeseCurds' as a variable name then that's at best an undocumented behavior and at worst a bug.  Inasmuch as the documentation indicates that such names are not allowed, it is unreasonable to expect Puppet to continue accepting them, or even for release notes to warn in the event that it stops accepting them.

Even if you think the documentation is less plain and clear than it seems to me, why take the risk of writing Puppet code whose validity is subject to uncertain interpretation?


John

R.I.Pienaar

unread,
Nov 26, 2014, 8:52:50 AM11/26/14
to puppet-users
For reference the current docs are @ https://docs.puppetlabs.com/puppet/latest/reference/lang_reserved.html#variables

And according to the rules in that doc, this still works in 3.7.x at least:

puppet apply -e '$fooBar="1" notice($fooBar)' --parser=future

This though fails:

puppet apply -e '$FooBar="1" notice($FooBar)' --parser=future
Error: Illegal variable name, The given name 'FooBar' does not conform to the naming rule /^((::)?[a-z]w*)*((::)?[a-z_]w*)$/ at line 1:1

Which is weird because 'fooBar' also doesnt match this rule so why did it work?

Matthew Walster

unread,
Nov 26, 2014, 9:42:40 PM11/26/14
to puppet...@googlegroups.com
On 26 November 2014 at 21:52, R.I.Pienaar <r...@devco.net> wrote:
puppet apply -e '$FooBar="1" notice($FooBar)' --parser=future
Error: Illegal variable name, The given name 'FooBar' does not conform to the naming rule /^((::)?[a-z]w*)*((::)?[a-z_]w*)$/ at line 1:1

Which is weird because 'fooBar' also doesnt match this rule so why did it work?


 NamedVariable
   : /[a-z_]\w*/
   | /(::)?[a-z]\w*(::[a-z]\w*)*/ 
That implies to me that fooBar would work, because the first character is part of [a-z_], and all successive characters have to be a word character (i.e. upper or lower case).

I had a quick chat with Henrik Lindberg in IRC, turns out that ​the future parser in 3.7 should behave as in 4.0 -- so if fooBar works now, it will work in future. He specifically told me "CamelCase is ok as long as the camel starts with a c and not a C" and that "internall[y], all names of classes etc is turned into lower case anyway"

So, Java fans, looks like camelCase lives on. snake_case seems to be the preferred option for puppet, but it's not strictly enforced.

Hope that clears things up. As I understand it, the documentation at https://docs.puppetlabs.com/puppet/latest/reference/experiments_future.html will be updated.

M
Reply all
Reply to author
Forward
0 new messages