PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration...
-
Upload
puppet -
Category
Technology
-
view
27 -
download
0
Transcript of PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration...
About [email protected] @hel helindbe http://puppet-on-the-edge.blogspot.se
The Truth, Nothing but the Truth
Truth and Philosophy
Coherence of Belief Witches float.
Divine Truth Do not jeer at a bald
man or you will be torn to pieces by bears.
- 2 KINGS 2:23-24
Logical Truth 0x2b || ! 0x2b
Scientific Observable reality
Are there as many truths as there are scents of shampoo?
5
Pseudoscience
Pseudoscience - Science applied to non Science, or just pure nonsense
astrology, alchemy, medical quackery, the occult
7
Paradoxes
“This sentence is false.”
“This sentenc contains three erors.”
“Can you publish a book containing all published books?”
“Can an almighty deity create a stone it cannot lift?”
9
Escape to a higher level
“This sentenc contains three erors.”
A “sentenc" is a kind of english sentence where the word “three” means 4, and and “eror” is a white space - all other words are English.
11
Communication is based on Language
A shared understanding of syntax and semantics
Built out of words
Words are symbols
Symbols are abstractions
13
How do we deal with the problems of Truth?
Constraining the space to what matters ?
Cheat ?
Be sloppy / ambiguous and use “bad math” and rely on Folklore to prevent accidents?
Add rigor ?
Provide features users can build robust solutions on?
20
What we do not want
Microsoft Word:
moves an image 1mm to the left
all text and images shift
4 new pages appear
in the distance, sirens
@gossipgirl on twitter
21
Deus ex machina in Puppet
class a {
}
class b inherits a {
}
class c inherits b { # ERROR ONE LEVEL ONLY
}
24
Deus ex machina
42.type
=> Integer.type
=> Type[Integer].type
=> Type[Type[Integer]].type
=> Type[Type[Type[Integer]]].type
=> Type[Type[TypeType[[Integer]]]].type
=> Type[Type[Type[Type[Type[Integer]]]]].type
... (until out of machine resources)
25
Deus ex machina
function successors(Number $x) >> Array[Number] {
[$x, *successors($x+1)]
}
notice successors(1)
... (runs until out of machine resources)
26
Many Built in Data Types
Any
Integer, Float, String, Boolean, Regexp, Pattern, Enum, Array, Hash, Tuple, Struct, Iterable, Binary, Sensitive, SemVer, SemVerRange, TimeSpan, TimeStamp, Variant, Optional, Undef, CatalogEntry, HostClass, Resource, Callable, Runtime
Type
Experimental:
Object, TypeSet
38
Create your Own
Simple Alias
type Color = Enum[red, blue, green]
Recursive Structure
type IntegerTree = Variant[Integer, Array[IntegerTree, 1]]
Types are Name-spaced, and Autoloaded
type MyModule::Color = Enum[red, blue, green]
4.x Ruby functions can have (additional) local types
39
And can be used in many ways
function myfunc(MyType $x) >> Boolean { }
define myresource(MyType $x) { }
class myclass(MyType $x) { }
$value =~ MyType
case $value {
MyType : { }
}
assert_type(MyType, $value)
40
Strongly vs. Weakly Typed
A scale from:
Strongly typed - no implicit conversions even if harmless
Performing conversions
Type inference
Do not care - will blow up later…
42
Type Systems
Strongly or Weakly typed - fuzzy concepts
Memory Protection - allocation/layout of data in memory
Union Types - (OR) Variant type in Puppet
Intersection Types - (AND) Integer[-128, 127] and Integer[0,255] => Integer[0,127]
Existential Types - “has interface” similar to Duck typing
Dependant Types -
function shorten(Array[$T, $n 1] $arr) >> Array[$T, $n-1]
Duck typing (Ruby, JS)
43
When we have a strong type system - it is like having two programs in one - both the concrete level that we observe when running it, and a program that defines its meaning.
Type Inference
Static transformation of the program to Type Equations that are then solved.
Can statically find known to be impossible operations.
Can only determine runtime safety if the system is completely typed (statically or by inference).
45
1 + 1 type(1) + type(1) Integer + Integer$x = 101 + $x
type($x) = type(10)type(1) + type($x)
Integer + Integer
$x = /.*/1 + $x
type($x) = type(/.*/)type(1) + type($x)
Integer + Regexp
Type Inference in Puppet
Precise - all information is retained, unless asked for a reduction or generalization:
$value = [1, ”hello”, 3.14]
notice $value.type
=> Tuple[Integer[1,1], Enum[“hello”], Float[3.14, 3.14]]
notice $value.type(reduced)
=> Array[Scalar, 3, 3]
notice $value.type(generalized)
=> Array[Scalar]
46
47
CODE CLEAN & TYPE STRONGLYa reinforcing loop of truth
Type your inputs Do not over-type
Test Fail early