F.Zappa - excerpt from "The Torture Never Stops":

"Flies all green and buzzin'
 In the dungeon of despair
 Who are all those people
 That he's locked away down there
 Are they crazy
 Are they sainted
 Are they zeros someone painted
 That had never been explained
 Since at first it was created
 But a dungeon like a sin
 Requires not much lockin' in
 Of everything thats ever been"

(http://www.metrolyrics.com/the-torture-never-stops-lyrics-frank-zappa.html for full lyric)

Somehow fitting, Halloween and all... for what I want to bring up.

Yet again someone was bit by the automatic String to Numeric conversion
that is in Puppet (and also in --parser future).

The particular thing this time was https://tickets.puppetlabs.com/browse/PUP-3602 that caused certain md5 fingerprints to look like floating point values of value 0 (they all started with "0e" but had different digits after the e, and since 0 * 10 ^something is always 0 the two different md5 fingerprints were reported to being equal.

This is not the only place where String to number conversion is a very
bad idea. Someone recently had problems with conversions in a case
where string comparison was wanted for version strings. https://tickets.puppetlabs.com/browse/PUP-3333 has the details.

With --parser future it is at least consistent. In 3x different operators used different rules. Now <, >, <=, >=, ==, and != all share the same behavior; they convert a string to numeric if both sides of the expression are numeric or can be converted to numeric.

The in operator has some additional rules (see the spec, but it uses
the same comparisons as for the regular operators).

We fixed PUP-3602 by not converting strings that are floating point 0 with exponential part and we also do not convert values that are floating point infinite in Ruby (e.g. 4e999 and such). This is a crutch though, and it is only a matter of time until someone stumbles over the next SURPRISE !

The best cure is naturally to never do String to numeric conversion. And we wonder what people feel about that. Should we go for this in Puppet 4.0.0 (and have a 3.7.4 release as the last of the 3x series where this behavior is implemented when using --parser future).


There has also been a number of other suggestions how to fix this, that are less appealing, and for the sake of not having to waste anyone's time, here they are, with the reasons why they are not so appealing.

* Only convert if LHS is a Number. This makes the order of the comparison matter and then ($x == $y) != ($y == $x) which is really bad.

* Add === operator to compare both type and value. This is a slippery slope since we probably want Integer and Float to compare equal - say 0.0 and 0. It adds yet another operator, and we have to decide what case, selector and in should use since there is no way to specify if one or the other should be used.

Instead, since we already have sprintf for value to string conversion, and there is a scanf in Ruby which does the conversion the other way, we can simply add that function to core puppet for value conversion.

We could also add to_number(s), or to_number(s, format_string).
When doing that though, we risk ending up with a plethora of to_xxx functions, and we could instead offer one more universal convert_to(Type, value, options) function e.g.

# best effort, or fail
convert_to(Number, value)

# only if it is an integer, or fail
convert_to(Integer, value, {base => 10})

# convert integer to hex string with some extra text (the sprintf way)
convert_to(String, value, {format => "Hex %x"})

# convert to array of string (give full control over all
# nested conversions.
#
convert_to(Array[String], value, {
  Integer => { format => "0x%x" },
  Float   => { format => "%#.4G" }})

# etc.

So - "Boldly break all the (s)t(r)hings"?

- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/m31ckf%24ob5%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to