Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
The Truth, Nothing But The
Truth.
Why Type Systems are important to Configuration Management
About me.
henrik.lindberg@puppet.com
@hel
helindbe
http://puppet-on-the-edge.blogspot.se
What is Truth?
Do we know it when we see it?
4
The Truth, Nothing but the Truth
Truth and Philosophy
Coherence of Belief
Witches float.
Divine Truth
Do not jeer at a bal...
Distortions of Truth
0.5 x truth + 0.5 x truth != truth
Pseudoscience
Pseudoscience - Science applied to non Science, or just pure nonsense
astrology, alchemy, medical quackery, ...
Ambiguity
Ambiguity - lack of context or definition - or simply clashing - the source of puns
8
Paradoxes
“This sentence is false.”
“This sentenc contains three erors.”
“Can you publish a book containing all published ...
10
Escape to a higher level
“This sentenc contains three erors.”
A “sentenc" is a kind of english sentence where the word “th...
Communication
What’s in a word?
Communication is based on Language
A shared understanding of syntax and semantics
Built out of words
Words are symbols
Sym...
What is this?
SHOUT IT OUT… (ready….)
14
16
Communication
17
18
What’s Love Got to
do With It?
Tina Turner
Is my Puppet Logic error free?
Does it do what I intended?
How do we deal with the problems of Truth?
Constraining the space to what matters ?
Cheat ?
Be sloppy / ambiguous and use ...
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 dis...
22
“The system works
in mysterious
ways…”
“…it must be a Deity!”
Deus Ex Machina
“God arrives via Machinery”
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]]].typ...
Deus ex machina
function successors(Number $x) >> Array[Number] {
[$x, *successors($x+1)]
}
notice successors(1)
... (runs...
Puppet’s Type System
(because only a Deity writes perfect code)
28
Type is a Kind of
Pattern
An Abstraction
29
3.1415
8 7
5
1
2
3
0.5 1.23E3
“red”
“blue”
“green”
“hello”
3.1415
8 7
5
1
2
3
0.5 1.23E3
30
String
“red”
“blue”
“green”
“hello”
31
Number
“red”
“blue”
“green”
“hello”
3.1415
8 7
5
1
2
3
0.5 1.23E3
32
Integer
“red”
“blue”
“green”
“hello”
3.1415
8 7
5
1
2
3
0.5 1.23E3
33
Integer[5,7]
“red”
“blue”
“green”
“hello”
3.1415
8
1
2
3
0.5 1.23E3
7
5
34
Enum[red, green, blue]
“red”
“blue”
“green”
“hello”
3.1415
8
1
2
3
0.5 1.23E3
7
5
35
type Color = Enum[red, green, blue]
“red”
“blue”
“green”
“hello”
3.1415
8
1
2
3
0.5 1.23E3
7
5
36
Color
“red”
“blue”
“green”
“hello”
3.1415
8
1
2
3
0.5 1.23E3
7
5
37
Variant[Color, Integer]
“red”
“blue”
“green”
“hello”
3.1415
8
1
2
3
0.5 1.23E3
7
5
Many Built in Data Types
Any
Integer, Float, String, Boolean, Regexp, Pattern, Enum, Array, Hash, Tuple, Struct, Iterable,...
Create your Own
Simple Alias
type Color = Enum[red, blue, green]
Recursive Structure
type IntegerTree = Variant[Integer, A...
And can be used in many ways
function myfunc(MyType $x) >> Boolean { }
define myresource(MyType $x) { }
class myclass(MyTy...
Type Theory
What is it?
Strongly vs. Weakly Typed
A scale from:
Strongly typed - no implicit conversions even if harmless
Performing conversions
T...
Type Systems
Strongly or Weakly typed - fuzzy concepts
Memory Protection - allocation/layout of data in memory
Union Types...
When we have a strong type system - it is like having two
programs in one - both the concrete level that we observe
when r...
Type Inference
Static transformation of the program to Type Equations that are then solved.
Can statically find known to b...
Type Inference in Puppet
Precise - all information is retained, unless asked for a reduction or generalization:
$value = [...
47
CODE CLEAN
& TYPE
STRONGLY
a reinforcing loop of truth
Type your inputs
Do not over-type
Test
Fail early
PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration Management – Henrik Lin...
PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration Management – Henrik Lin...
Upcoming SlideShare
Loading in …5
×

PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration Management – Henrik Lindberg, Puppet

131 views

Published on

Here are the slides from Henrik Lindberg's PuppetConf 2016 presentation called The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration Management. Watch the videos at https://www.youtube.com/playlist?list=PLV86BgbREluVjwwt-9UL8u2Uy8xnzpIqa

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PuppetConf 2016: The Truth, Nothing but the Truth: Why Type Systems are Important to Configuration Management – Henrik Lindberg, Puppet

  1. 1. The Truth, Nothing But The Truth. Why Type Systems are important to Configuration Management
  2. 2. About me. henrik.lindberg@puppet.com @hel helindbe http://puppet-on-the-edge.blogspot.se
  3. 3. What is Truth? Do we know it when we see it?
  4. 4. 4
  5. 5. 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
  6. 6. Distortions of Truth 0.5 x truth + 0.5 x truth != truth
  7. 7. Pseudoscience Pseudoscience - Science applied to non Science, or just pure nonsense astrology, alchemy, medical quackery, the occult 7
  8. 8. Ambiguity Ambiguity - lack of context or definition - or simply clashing - the source of puns 8
  9. 9. 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
  10. 10. 10
  11. 11. 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
  12. 12. Communication What’s in a word?
  13. 13. Communication is based on Language A shared understanding of syntax and semantics Built out of words Words are symbols Symbols are abstractions 13
  14. 14. What is this? SHOUT IT OUT… (ready….) 14
  15. 15. 16
  16. 16. Communication 17
  17. 17. 18 What’s Love Got to do With It? Tina Turner
  18. 18. Is my Puppet Logic error free? Does it do what I intended?
  19. 19. 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
  20. 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
  21. 21. 22 “The system works in mysterious ways…” “…it must be a Deity!”
  22. 22. Deus Ex Machina “God arrives via Machinery”
  23. 23. Deus ex machina in Puppet class a { } class b inherits a { } class c inherits b { # ERROR ONE LEVEL ONLY } 24
  24. 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
  25. 25. Deus ex machina function successors(Number $x) >> Array[Number] { [$x, *successors($x+1)] } notice successors(1) ... (runs until out of machine resources) 26
  26. 26. Puppet’s Type System (because only a Deity writes perfect code)
  27. 27. 28 Type is a Kind of Pattern An Abstraction
  28. 28. 29 3.1415 8 7 5 1 2 3 0.5 1.23E3 “red” “blue” “green” “hello”
  29. 29. 3.1415 8 7 5 1 2 3 0.5 1.23E3 30 String “red” “blue” “green” “hello”
  30. 30. 31 Number “red” “blue” “green” “hello” 3.1415 8 7 5 1 2 3 0.5 1.23E3
  31. 31. 32 Integer “red” “blue” “green” “hello” 3.1415 8 7 5 1 2 3 0.5 1.23E3
  32. 32. 33 Integer[5,7] “red” “blue” “green” “hello” 3.1415 8 1 2 3 0.5 1.23E3 7 5
  33. 33. 34 Enum[red, green, blue] “red” “blue” “green” “hello” 3.1415 8 1 2 3 0.5 1.23E3 7 5
  34. 34. 35 type Color = Enum[red, green, blue] “red” “blue” “green” “hello” 3.1415 8 1 2 3 0.5 1.23E3 7 5
  35. 35. 36 Color “red” “blue” “green” “hello” 3.1415 8 1 2 3 0.5 1.23E3 7 5
  36. 36. 37 Variant[Color, Integer] “red” “blue” “green” “hello” 3.1415 8 1 2 3 0.5 1.23E3 7 5
  37. 37. 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
  38. 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
  39. 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
  40. 40. Type Theory What is it?
  41. 41. 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
  42. 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
  43. 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.
  44. 44. 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 = 10 1 + $x type($x) = type(10) type(1) + type($x) Integer + Integer $x = /.*/ 1 + $x type($x) = type(/.*/) type(1) + type($x) Integer + Regexp
  45. 45. 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
  46. 46. 47 CODE CLEAN & TYPE STRONGLY a reinforcing loop of truth Type your inputs Do not over-type Test Fail early

×