Issue #15329 has been updated by Reid Vandewiele.
The following is lead-in context for two questions stated at the bottom of this
note.
The DSL is all about describing a desired end state. In that context I've used
`undef` frequently because it's often the case that I want to explicitly state
that I *don't care* about the value of a particular parameter and want a means
of specifying it with a variable in such a way that allows me to say I want the
default behavior, as if I hadn't set it at all. When switching based on a
conditional, for example, consider the following pattern:
<pre>
$mode = $::osfamily ? {
'RedHat' => '0755',
'Debian' => '0644',
'Windows' => undef,
}
file { $path:
ensure => file,
content => "example\n"
mode => $mode,
}
</pre>
This is a contrived example but it shows how stating an explicit `undef` in the
DSL using a variable can be useful. Specifically, allowing a variable to be
assigned the value of `undef` gives us a clean way of specifying that if this
manifest is evaluated on Windows the `mode` property should not be managed.
Another use case for undef that doesn't involve variables centers around
inheritance. For example:
<pre>
class parent {
file { '/tmp/example':
ensure => file,
content => "managed\n",
}
}
class child inherits parent {
File['/tmp/example'] {
content => undef,
}
}
</pre>
Here we see `undef` being used again as part of an intentional description of a
desired state. If the `parent` class is included on a system it will ensure
that `/tmp/example` exists and has a particular content. However, if the
`child` class is included, we override the content property to explicitly state
that Puppet shouldn't care about the content (or "un-state", if you will).
Right now with the current undef behavior this all feels very clean and
straightforward*. With that said, I basically have two questions for this
thread:
1. What purpose would having a `nil` keyword serve in the DSL? What would it be
used for?
2. How would removing `undef` in favor of more syntax ("fat comma") make the
DSL better?
-----
\* It used to be cleaner. See Feature Request #14654. The summary of the
uncleanness is that you can't test for undef in the DSL anymore.
<pre>
notify { "if message is undef, the title will be used instead":
message => undef,
}
if "" == undef {
notify { "then this message should not be empty":
message => "",
}
}
</pre>
----------------------------------------
Bug #15329: Puppet lacks a proper "undefined" value
https://projects.puppetlabs.com/issues/15329#change-78300
Author: Pieter van de Bruggen
Status: Accepted
Priority: Normal
Assignee: Henrik Lindberg
Category:
Target version:
Affected Puppet version:
Keywords: backlog
Branch:
$y = undef
notice($y == "") # true
notice($x == $y) # true
notice($x == "") # true
Recent changes in the Puppet DSL made equality commutative (good!), but in
doing so broke work-arounds for actually testing for the difference between an
undefined and "empty" value. The most logical fix would be to equate Puppet's
`undef` with Ruby's `nil`.
--
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.