|
| 1 | +.. role:: cover |
| 2 | + |
| 3 | +============================================ |
| 4 | +:cover:`Complexity in software development` |
| 5 | +============================================ |
| 6 | + |
| 7 | +.. class:: cover |
| 8 | + |
| 9 | + :: |
| 10 | + |
| 11 | + Jonas Juselius <[email protected]> |
| 12 | + HPC@UiT |
| 13 | + |
| 14 | +.. raw:: pdf |
| 15 | +
|
| 16 | + SetPageCounter 0 |
| 17 | + Transition Dissolve 1 |
| 18 | + PageBreak oneColumn |
| 19 | +
|
| 20 | +The tar pit |
| 21 | +---------------------------------------------------- |
| 22 | +* Over time software tends to become harder and harder to reason about |
| 23 | +* The code base easily becomes untidy ("I'll fix it later") |
| 24 | +* Small changes become harder to implement |
| 25 | +* Hacks and workarounds trump desing |
| 26 | +* Bugs start appearing where in unexpected places |
| 27 | +* More time is spent debugging than developing |
| 28 | +* Complexity strangles development |
| 29 | + |
| 30 | +Develoment speed |
| 31 | +---------------------------------------------------- |
| 32 | + |
| 33 | +.. image:: img/develspeed.jpg |
| 34 | + :scale: 60% |
| 35 | + |
| 36 | +Inherent vs. incidental complexity |
| 37 | +---------------------------------------------------- |
| 38 | +We distinguish between two types of complexity: |
| 39 | + |
| 40 | +* *Inherent* complexity of the problems space |
| 41 | +* *Incidental* complexity in the solution space |
| 42 | +* Complexity implies braiding and intertwining |
| 43 | +* Simplicity implies "one foldedness", i.e. one braid, single entity |
| 44 | + |
| 45 | +.. image:: img/tincan.png |
| 46 | + :scale: 45% |
| 47 | + |
| 48 | +Stockholm telephone tower anno 1910 |
| 49 | +---------------------------------------------------- |
| 50 | +.. image:: img/stockholm-tower.jpg |
| 51 | + :scale: 65% |
| 52 | + |
| 53 | +Simplicity |
| 54 | +---------------------------------------------------- |
| 55 | +* Simplicity is the prerequisite of reliability (E. Dijkstra) |
| 56 | +* We can only consider a very limited number of thinings at once |
| 57 | +* Complex things must be considered together, undermining understanding |
| 58 | +* We can only hope to make reliable things we undertand |
| 59 | + |
| 60 | +.. image:: img/Lady-Juggler.png |
| 61 | + :scale: 75% |
| 62 | + |
| 63 | +The brain facing computer code |
| 64 | +---------------------------------------------------- |
| 65 | +.. image:: img/Homer-simpson-brain.jpg |
| 66 | + :scale: 150% |
| 67 | + |
| 68 | +Simple vs. easy |
| 69 | +---------------------------------------------------- |
| 70 | +* Simple is not the same as easy |
| 71 | +* Simple means: |
| 72 | + * One role or taks |
| 73 | + * One concpt or dimension |
| 74 | +* Easy means: |
| 75 | + * Familarity |
| 76 | + * Near at hand |
| 77 | +* Just because you know it does not make it simple |
| 78 | + |
| 79 | +Benefits of simplicity |
| 80 | +---------------------------------------------------- |
| 81 | +* Easy to understand |
| 82 | +* Easy to change |
| 83 | +* Easy to debug |
| 84 | +* Simplicity is much harder than complexity! |
| 85 | + |
| 86 | +*"Simpliciy is the ultimate sophistication. L. da Vinci."* |
| 87 | + |
| 88 | +Causes of complexity |
| 89 | +---------------------------------------------------- |
| 90 | +* Our tools and languages |
| 91 | +* Poor design or wrong design |
| 92 | +* Not enough resources (e.g. time) |
| 93 | + |
| 94 | +Enemy of the state |
| 95 | +---------------------------------------------------- |
| 96 | +* The no. 1 cause of complexity is *state* |
| 97 | +* Every mutable variable is stateful |
| 98 | +* For every bit of state in your program, there are two tests: A program with |
| 99 | + 100 integer variables has :math:`2^{3200}` distinct states to test. |
| 100 | + |
| 101 | +.. image:: img/alfred_e_neuman_1.jpg |
| 102 | + :scale: 20% |
| 103 | + |
| 104 | +Local variables are stateful too |
| 105 | +---------------------------------------------------- |
| 106 | +.. math:: |
| 107 | +
|
| 108 | + f(x) = (n+1)(n+2) |
| 109 | +
|
| 110 | +.. code-block:: Python |
| 111 | +
|
| 112 | + def f(x): |
| 113 | + x = x + 1 |
| 114 | + y = x + 1 |
| 115 | + return x * y |
| 116 | +
|
| 117 | +.. math:: |
| 118 | +
|
| 119 | + f(x) = (n+1)^2 |
| 120 | +
|
| 121 | +.. code-block:: Python |
| 122 | +
|
| 123 | + def f(x): |
| 124 | + y = x + 1 |
| 125 | + x = x + 1 |
| 126 | + return x * y |
| 127 | +
|
| 128 | +Referential transparency |
| 129 | +---------------------------------------------------- |
| 130 | + |
| 131 | +.. code-block:: Python |
| 132 | +
|
| 133 | + def f(x): |
| 134 | + x1 = x + 1 |
| 135 | + y1 = x1 + 1 |
| 136 | + return x1 * y1 |
| 137 | +
|
| 138 | +Haskell example: |
| 139 | + |
| 140 | +.. code-block:: Haskell |
| 141 | +
|
| 142 | + f :: (Num a) => a -> a |
| 143 | + f x = x' * y' |
| 144 | + where |
| 145 | + y' = x' + 1 |
| 146 | + x' = x + 1 |
| 147 | +
|
| 148 | +State of affairs |
| 149 | +---------------------------------------------------- |
| 150 | +* Information vs. place |
| 151 | +* PLOP: New information replaces old |
| 152 | +* PLOP grew out of tiny computer memories |
| 153 | +* Information is simple, don't ruin it |
| 154 | +* We use valus on the wire, why not in our codes? |
| 155 | + |
| 156 | +The value of values |
| 157 | +---------------------------------------------------- |
| 158 | +* Values are immutable |
| 159 | +* Values can be shared |
| 160 | +* Values are easy to fabriacte |
| 161 | +* Values are language agnostic |
| 162 | +* Values aggregate. Objects don't (usually) |
| 163 | +* Values are stable: reproducible results |
| 164 | +* Values don't *need* methods |
| 165 | +* Values have representation, *not* implementation |
| 166 | + |
| 167 | +Composition |
| 168 | +---------------------------------------------------- |
| 169 | +* Compostition enables us to build complex behavior from simple components |
| 170 | +* We can reason about the components, and we can reason about the composite |
| 171 | +* Composition is key to managing complexity |
| 172 | +* Modularity does not imply simplicity, but is enabled by it |
| 173 | + |
| 174 | +.. image:: img/knit_vs_lego.jpg |
| 175 | + :scale: 15% |
| 176 | + |
| 177 | +How about object-oriented programming? |
| 178 | +---------------------------------------------------- |
| 179 | +* Encapsulation: Adding implementation to information? |
| 180 | +* Complects both state and information |
| 181 | +* OOP lures us to implement with little, moving machines |
| 182 | + |
| 183 | +.. image:: img/complex-machine.jpg |
| 184 | + :scale: 11% |
| 185 | + |
| 186 | +A base class |
| 187 | +---------------------------------------------------- |
| 188 | +.. code-block:: Python |
| 189 | +
|
| 190 | + class A(object): |
| 191 | + def __init__(self): |
| 192 | + self.a = 1 |
| 193 | +
|
| 194 | + def addone(self, x): |
| 195 | + self.a += 1 |
| 196 | + return x + self.a |
| 197 | +
|
| 198 | + def inc(self, x): |
| 199 | + return x + self.a |
| 200 | +
|
| 201 | +Hidden state, crouching dragon |
| 202 | +---------------------------------------------------- |
| 203 | +.. code-block:: Python |
| 204 | +
|
| 205 | + class B(A): |
| 206 | + def __init__(self): |
| 207 | + super(B,self).__init__() |
| 208 | +
|
| 209 | + def np1np2(self, x): |
| 210 | + a = self.addone(x) |
| 211 | + b = self.inc(x) |
| 212 | + return a * b |
| 213 | +
|
| 214 | + b = B() |
| 215 | + print b.np1np2(5) |
| 216 | +
|
| 217 | +The litmus test |
| 218 | +---------------------------------------------------- |
| 219 | +* Can you move sub-systems? |
| 220 | + * To another langage? |
| 221 | + * To another machine? |
| 222 | + * Without changing much? |
| 223 | + |
| 224 | +.. image:: img/under_the_hood.png |
| 225 | + :scale: 200% |
| 226 | + |
| 227 | +Code quality |
| 228 | +------------------------------------------------------ |
| 229 | +Every bug has passed both the typechecker and the test suite. |
| 230 | + |
| 231 | +.. image:: img/wtfs_per_minute_thumb.jpg |
| 232 | + :scale: 100% |
| 233 | + |
0 commit comments