Issue #10506 has been updated by James Turnbull. Status changed from Unreviewed to Needs Decision Assignee set to Nigel Kersten
---------------------------------------- Bug #10506: Naming rules are inconsistent https://projects.puppetlabs.com/issues/10506 Author: Henrik Lindberg Status: Needs Decision Priority: Normal Assignee: Nigel Kersten Category: language Target version: Affected Puppet version: Keywords: usability syntax Branch: The rules for naming of classes is inconsistently applied to different language concepts. * It is allowed to name a class using *NUMBER* (e.g. '0', '0.0', '0477', '0x1f', '1.3e-2'). * A dollar variable is parsed with the regular expression `%r{\$(::)?([-\w]+::)*[-\w]+}` and can thus never refer to a variable in a class named with a '.' (period) in the name * A *NAME*, *CLASSREF*, or *CLASSNAME* is parsed with` %r{((::)?[a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*}` and can also not contain a '.' (period) * Regular expression matching injects values into variables `$0` - `$n` (although not directly clashing since a class is typically not referenced with a variable, it is still confusing to see say `$0::1`, when $0 is a regexp match) * Class defaults can be set using a class reference (each segment starts with upper case letter in a fully qualified name), this is strange when name is numeric (how do you write an upper case '1'?). Compare: using words: class one($a) { class two($b) {} } One { a=>10 } One::Two {b=>20} using numbers: class 1($a) { class 2($b) {} } 1 { a=>10 } 1::2 {b=>20} The second example (naturally) results in: Could not parse for environment production: All resource specifications require names at /private/tmp/test.pp:2 on node xxx * A separate issue is that assignment to `$0` - `$n` may not take effect (the variable is still undefined) in some cases. * The documentation does not seem to mention the fact that classes may have numerical names (the stricter rules are shown in several places). I suggest that: * Numerical names should be deprecated * Assignment to `$0` - `$n` should be illegal (reserved for regular expression matches) In contrast, if trying to fix this by adding '.' (period) as valid in variables, a lot of string interpolation will break (in similar ways to how the altered string interpolation rules regarding '-' (hyphen) breaks existing code). The interpolation issues could be resolved by deprecating the interpolation short form (i.e. interpolating without braces), but that may be considered a more serious imposition (even if recommended as best practice) - i.e. that `"Hello $name"` must be written `"Hello ${name}"`. It seems like 2.8 would be a good candidate for more stringent rules since dynamic scoping of variables will be deprecated and people do have to inspect their code and deal with naming/reference issues. -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" 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-bugs?hl=en.
