[prev in list] [next in list] [prev in thread] [next in thread]
List: puppet-dev
Subject: [Puppet-dev] Booleans, 'if', and similar pursuits.
From: luke () madstop ! com (Luke Kanies)
Date: 2006-07-21 22:35:40
Message-ID: 44C156BC.9090604 () madstop ! com
[Download RAW message or body]
So, I've got a feature request in to myself to add an 'if' keyword,
because I keep doing statements like this:
define mything(useit = false) {
case $useit { false: {}
default: { ... }
}
}
It would be tons cleaner like this:
define mything(useit = false) {
if $useit { ... }
}
If I add this, though, I almost have to add, at the same time, at least
the ability to negate the test with '!', and probably an '||' operator
and a '&&' operator. This is enough complexity (since almost no
statements in Puppet currently have values) that I'm considering this a
relatively large stand-alone project in the parser, not just a quick
additional statement type.
This gets me thinking about booleans, though, and about -- other
problems aside -- how nice cfengine's class booleans are. Puppet has
just started to be able to manipulate a global boolean dictionary called
'tags', which are basically equivalent to cfengine's classes, but they
require separate functions to manipulate:
tag(mytag)
tagged(mytag)
I'm thinking about creating a top-level boolean type that maps to these
tags, and then just using a different sigil, like '@' or '~'. As I
create more complex configurations in Puppet, and I start to think about
how to really use these tags, I realize that it's pretty verbose to try
to use them right now, what with needing the case statement and the
function. Compare this cfengine code:
files:
hostname:: /my/file ...
To this Puppet code:
case tagged($hostname) {
true: {
file { "/my/file": ... }
}
}
Admittedly, a large part of the verbosity there is gratuitous curly
braces, and I should be fixing that anyway, but I don't like the
explicit mention of "true" here.
I'm thinking maybe something like this:
if @hostname {
file { "/my/file": ... }
}
And when curlies become largely optional (i.e., when I become a better
grammar writer), that would be even cleaner. I used to think curlies
looked so clean...
--
Sapolsky's First Law:
Think logically, but orthogonally.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic