Slide 1

Slide 1 text

@TheQuinnGil https://QuinnGil.com with Technical Practices for Sustainable Code Feature Parity in 25% of the Dev Hours

Slide 2

Slide 2 text

@TheQuinnGil https://QuinnGil.com Technical Practices for Sustainable Code

Slide 3

Slide 3 text

@TheQuinnGil https://QuinnGil.com Quinn Gil Blog -- QuinnGil.com Twitter -- TheQuinnGil Github -- Fyzxs

Slide 4

Slide 4 text

@TheQuinnGil https://QuinnGil.com This is for you.

Slide 5

Slide 5 text

@TheQuinnGil https://QuinnGil.com Sustainable Code

Slide 6

Slide 6 text

@TheQuinnGil https://QuinnGil.com Why? Sustainable Code

Slide 7

Slide 7 text

@TheQuinnGil https://QuinnGil.com What’s Our Job? Sustainable Code - Why?

Slide 8

Slide 8 text

@TheQuinnGil https://QuinnGil.com Sustainably grow the value of the company’s digital assets. Sustainable Code - What’s our job?

Slide 9

Slide 9 text

@TheQuinnGil https://QuinnGil.com I’m Lazy Sustainable Code

Slide 10

Slide 10 text

@TheQuinnGil https://QuinnGil.com How? Sustainable Code

Slide 11

Slide 11 text

@TheQuinnGil https://QuinnGil.com Mindset Change Sustainable Code - How?

Slide 12

Slide 12 text

@TheQuinnGil https://QuinnGil.com Technical Practices Sustainable Code - How?

Slide 13

Slide 13 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices

Slide 14

Slide 14 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 15

Slide 15 text

@TheQuinnGil https://QuinnGil.com But First!

Slide 16

Slide 16 text

@TheQuinnGil https://QuinnGil.com Fully Test Behaviors Sustainable Code - Testing!

Slide 17

Slide 17 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 18

Slide 18 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 19

Slide 19 text

@TheQuinnGil https://QuinnGil.com No Getters / No Setters Technical Practices

Slide 20

Slide 20 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters / No Setters class FizzBuzzBag{ public int Input{ get; set; } public string Result{ get; set; } } class FizzBuzzBag: def __init__(self): self._result = None self._input = None @property def result(self): return self._result @result.setter def result(self, value): self._result = value @property def input(self): return self._input @input.setter def input(self, value): self._input = value class FizzBuzzBag{ private int input; private String result; public String getResult(){ return result; } public void setResult(String value){ result = value; } public int getInput(){ return input; } public void setInput(int value){ input = value; } } class FizzBuzzBag attr_accessor :input attr_accessor :result end

Slide 21

Slide 21 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters / No Setters No Way

Slide 22

Slide 22 text

@TheQuinnGil https://QuinnGil.com No Getters / No Setters Technical Practices

Slide 23

Slide 23 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters Why?

Slide 24

Slide 24 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Setters Why?

Slide 25

Slide 25 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters / No Setters How?

Slide 26

Slide 26 text

@TheQuinnGil https://QuinnGil.com No Getters / No Setters - How? The Class Does It

Slide 27

Slide 27 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters / No Setters public class FizzBuzz{ public int Input { get; set; } public string Result { get; set; } } public static class FizzBuzzUtils{ public static void Calculate(FizzBuzz fb){ if (fb.Input % 3 == 0){ fb.Result = "Fizz"; } if (fb.Input % 5 == 0){ if (fb.Result == null){ fb.Result = "Buzz"; } else { fb.Result += "Buzz"; } } if (string.IsNullOrEmpty(fb.Result)){ fb.Result = fb.Input.ToString(); } } }

Slide 28

Slide 28 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Getters / No Setters public class FizzBuzz{ private readonly int _input; public FizzBuzz(int input) => _input = input; public string Result(){ string result = null; if (_input % 3 == 0) result = "Fizz"; if (_input % 5 == 0){ if (result == null) result = "Buzz"; else result += "Buzz"; } if (string.IsNullOrEmpty(result)){ result = _input.ToString(); } return result; } } public class FizzBuzz{ public int Input { get; set; } public string Result { get; set; } } public static class FizzBuzzUtils{ public static void Calculate(FizzBuzz fb){ if (fb.Input % 3 == 0){ fb.Result = "Fizz"; } if (fb.Input % 5 == 0){ if (fb.Result == null){ fb.Result = "Buzz"; } else { fb.Result += "Buzz"; } } if (string.IsNullOrEmpty(fb.Result)){ fb.Result = fb.Input.ToString(); } } }

Slide 29

Slide 29 text

@TheQuinnGil https://QuinnGil.com Technical Practices - No Setters Benefits

Slide 30

Slide 30 text

@TheQuinnGil https://QuinnGil.com No Getters / No Setters Technical Practices

Slide 31

Slide 31 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 32

Slide 32 text

@TheQuinnGil https://QuinnGil.com `if` Only As Guard Clause Technical Practices

Slide 33

Slide 33 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause No Way

Slide 34

Slide 34 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause Success Path

Slide 35

Slide 35 text

@TheQuinnGil https://QuinnGil.com `if` Only As Guard Clause - Success Path public class FizzBuzz{ private readonly int _input; public FizzBuzz(int input) => _input = input; public string Result(){ string result = null; if (_input % 3 == 0) result = "Fizz"; if (_input % 5 == 0){ if (result == null) result = "Buzz"; else result += "Buzz"; } if (string.IsNullOrEmpty(result)){ result = _input.ToString(); } return result; } }

Slide 36

Slide 36 text

@TheQuinnGil https://QuinnGil.com `if` Only As Guard Clause - Success Path public class FizzBuzz{ public string Result(){ if (_input % 15 == 0) return "FizzBuzz"; if (_input % 3 == 0) return "Fizz"; if (_input % 5 == 0) return "Buzz"; return _input.ToString(); } } public class FizzBuzz{ private readonly int _input; public FizzBuzz(int input) => _input = input; public string Result(){ string result = null; if (_input % 3 == 0) result = "Fizz"; if (_input % 5 == 0){ if (result == null) result = "Buzz"; else result += "Buzz"; } if (string.IsNullOrEmpty(result)){ result = _input.ToString(); } return result; } }

Slide 37

Slide 37 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause Cascading Changes

Slide 38

Slide 38 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause How?

Slide 39

Slide 39 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause public class FizzBuzz{ public string Result(){ if (_input % 15 == 0) return "FizzBuzz"; if (_input % 3 == 0) return "Fizz"; if (_input % 5 == 0) return "Buzz"; return _input.ToString(); } }

Slide 40

Slide 40 text

@TheQuinnGil https://QuinnGil.com Technical Practices - `if` Only As Guard Clause public class FizzBuzz{ public string Result(){ if (_input % 15 == 0) return "FizzBuzz"; if (_input % 3 == 0) return "Fizz"; if (_input % 5 == 0) return "Buzz"; return _input.ToString(); } } public class FizzBuzz{ public string Result(){ if (IsFizzBuzz()) return "FizzBuzz"; if (IsFizz()) return "Fizz"; if (IsBuzz()) return "Buzz"; return InputToString(); } }

Slide 41

Slide 41 text

@TheQuinnGil https://QuinnGil.com `if` Only As Guard Clause Technical Practices

Slide 42

Slide 42 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 43

Slide 43 text

@TheQuinnGil https://QuinnGil.com Isolate Their Code Technical Practices

Slide 44

Slide 44 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Isolate Their Code - 3rd Party public class FizzBuzz{ private readonly string _input; public FizzBuzz(string input) => _input = input; public string Result(){ JObject jObject = JObject.Parse(_input); int input = jObject.Value("number"); if (IsFizzBuzz(input)) return "FizzBuzz"; if (IsFizz(input)) return "Fizz"; if (IsBuzz(input)) return "Buzz"; return input.ToString(); } }

Slide 45

Slide 45 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Isolate Their Code - 3rd Party public class FizzBuzz{ private readonly string _input; private readonly IParser _parser; public FizzBuzz(string input) => _input = input; public string Result(){ IParsedObject pObject = _parser.Parse(_input); int input = pObject.IntValue("input"); if (IsFizzBuzz(input)) return "FizzBuzz"; if (IsFizz(input)) return "Fizz"; if (IsBuzz(input)) return "Buzz"; return input.ToString(); } }

Slide 46

Slide 46 text

@TheQuinnGil https://QuinnGil.com Isolate Their Code Technical Practices

Slide 47

Slide 47 text

@TheQuinnGil https://QuinnGil.com Operating System Technical Practices - Isolate Their Code

Slide 48

Slide 48 text

@TheQuinnGil https://QuinnGil.com How? Technical Practices - Isolate Their Code

Slide 49

Slide 49 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Isolate Their Code - How? internal class HttpClientBookEnd : IHttpClientBookEnd{ private static HttpClient _testClient; #if DEBUG public static void SetTestClient(HttpClient testClient) => _testClient = testClient; #endif private readonly HttpClient _httpClient; public HttpClientBookEnd() : this(new HttpClient()){} private HttpClientBookEnd(HttpClient httpClient) => _httpClient = httpClient; public void SendRequestAsync(HttpRequestMessage msg) => HttpClient().SendAsync(msg); private HttpClient HttpClient() => _testClient ?? _httpClient; }

Slide 50

Slide 50 text

@TheQuinnGil https://QuinnGil.com User Interface Technical Practices - Isolate Their Code

Slide 51

Slide 51 text

@TheQuinnGil https://QuinnGil.com Isolate Their Code Technical Practices

Slide 52

Slide 52 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 53

Slide 53 text

@TheQuinnGil https://QuinnGil.com Never `null` Technical Practices

Slide 54

Slide 54 text

@TheQuinnGil https://QuinnGil.com Why? Technical Practices - Never `null`

Slide 55

Slide 55 text

@TheQuinnGil https://QuinnGil.com How? Technical Practices - Never `null`

Slide 56

Slide 56 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Never `null` public string CalculateThing(ICanBeNull canBeNull) { if (canBeNull == null) return "Default"; IAlsoNull alsoNull = canBeNull.Example(); if (alsoNull == null) return "Default"; string sample = alsoNull.Sample(); if (sample == null) return "Default"; return sample; }

Slide 57

Slide 57 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Never `null` public string CalculateThing(ICanNotBeNull canNotBeNull) { return canNotBeNull.Example().Sample(); } public string CalculateThing(ICanBeNull canBeNull) { if (canBeNull == null) return "Default"; IAlsoNull alsoNull = canBeNull.Example(); if (alsoNull == null) return "Default"; string sample = alsoNull.Sample(); if (sample == null) return "Default"; return sample; }

Slide 58

Slide 58 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Never `null` public string CalculateThing(ICanBeNull canBeNull) { if (canBeNull == null) return "Default"; IAlsoNull alsoNull = canBeNull.Example(); if (alsoNull == null) return "Default"; string sample = alsoNull.Sample(); if (sample == null) return "Default"; return sample; } public string CalculateThing(ICanNotBeNull canNotBeNull) { return canNotBeNull.Example().Sample(); } public void Foo(){ string thing = _bar.CalculateThing(_canBeNull); //Do something with `thing` }

Slide 59

Slide 59 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Never `null` public string CalculateThing(ICanBeNull canBeNull) { if (canBeNull == null) return "Default"; IAlsoNull alsoNull = canBeNull.Example(); if (alsoNull == null) return "Default"; string sample = alsoNull.Sample(); if (sample == null) return "Default"; return sample; } public string CalculateThing(ICanNotBeNull canNotBeNull) { return canNotBeNull.Example().Sample(); } public void Foo(){ string thing = _bar.CalculateThing(_canBeNull); //Do something with `thing` } public void Foo(){ string thing = _canNotBeNull.Example().Sample(); //Do something with `thing` }

Slide 60

Slide 60 text

@TheQuinnGil https://QuinnGil.com Technical Practices - Never `null` public string CalculateThing(ICanBeNull canBeNull) { if (canBeNull == null) return "Default"; IAlsoNull alsoNull = canBeNull.Example(); if (alsoNull == null) return "Default"; string sample = alsoNull.Sample(); if (sample == null) return "Default"; return sample; } public string CalculateThing(ICanNotBeNull canNotBeNull) { return canNotBeNull.Example().Sample(); } public class NullObject : ICanNotBeNull{ public IAlsoNotNull Example() => new NullObjectAlso(); } public class NullObjectAlso : IAlsoNotNull{ public string Sample() => "Default"; }

Slide 61

Slide 61 text

@TheQuinnGil https://QuinnGil.com Languages and Null

Slide 62

Slide 62 text

@TheQuinnGil https://QuinnGil.com Never `null` Technical Practices

Slide 63

Slide 63 text

@TheQuinnGil https://QuinnGil.com Sustainable Code through Technical Practices ● No Getters / No Setters ● `if` Only As Guard Clause ● Isolate Their Code ● Never `null` ● Limit Object Creation ● Composition, Not Inheritance ● ● Be Immutable ● No Primitives ● Extract Cohesion ● No Public Statics ● Never Reflection

Slide 64

Slide 64 text

@TheQuinnGil https://QuinnGil.com THANK YOU!