Slide 1

Slide 1 text

Divide & Conquer: An Iterative Approach To Writing Software Mark Crossfield, July 2018 whose pronoun.is/he

Slide 2

Slide 2 text

Structure Introduction Feedback loops Requirements Slicing Turning requirements into code Summary 2

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

Requirements • Users must supply a username and a password to authenticate • Their username and password must be checked against the database table of known users • If the username is found and the password matches then they must be authenticated • If the username is not found then the user must not be authenticated • If the user is found but the password does not match then the user must not be authenticated 4

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Slicing: Getting a (little) bit of everything 6

Slide 7

Slide 7 text

Slicing tip: Cheat—start with a simpler problem

Slide 8

Slide 8 text

Slicing tip: Start with empty inputs

Slide 9

Slide 9 text

Slicing tip: Ignore part of the requirements

Slide 10

Slide 10 text

Slicing tip: Work towards the ‘happy path’

Slide 11

Slide 11 text

Do literally anything you can to simplify the problem Section title

Slide 12

Slide 12 text

Converting Requirements into Code 12

Slide 13

Slide 13 text

Coding Tip: Keep focussed on the next simplest bit of the requirements

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘sesame’ Then the user is authenticated

Slide 16

Slide 16 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘letmein’ Then the user is not authenticated

Slide 17

Slide 17 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 18

Slide 18 text

What can our first step be? 18

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 24

Slide 24 text

Coding Tip: Start at the outside

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Coding Tip: Test each stage against your expectations

Slide 29

Slide 29 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 30

Slide 30 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘sesame’ Then the user is authenticated

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

32

Slide 33

Slide 33 text

33

Slide 34

Slide 34 text

Coding Tip: Let the code guide you—start with intent

Slide 35

Slide 35 text

Don’t jump ahead, call code before you define it, so that you know what it needs to do

Slide 36

Slide 36 text

36

Slide 37

Slide 37 text

37

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39

Slide 40

Slide 40 text

40

Slide 41

Slide 41 text

Coding tip: Fake bits of the implementation… hard code stuff!

Slide 42

Slide 42 text

42

Slide 43

Slide 43 text

43

Slide 44

Slide 44 text

44

Slide 45

Slide 45 text

45

Slide 46

Slide 46 text

46

Slide 47

Slide 47 text

47

Slide 48

Slide 48 text

48

Slide 49

Slide 49 text

49

Slide 50

Slide 50 text

50

Slide 51

Slide 51 text

51

Slide 52

Slide 52 text

52

Slide 53

Slide 53 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘sesame’ Then the user is authenticated

Slide 54

Slide 54 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 55

Slide 55 text

55

Slide 56

Slide 56 text

56

Slide 57

Slide 57 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 58

Slide 58 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘sesame’ Then the user is authenticated

Slide 59

Slide 59 text

59

Slide 60

Slide 60 text

60

Slide 61

Slide 61 text

61

Slide 62

Slide 62 text

62

Slide 63

Slide 63 text

63

Slide 64

Slide 64 text

64

Slide 65

Slide 65 text

65

Slide 66

Slide 66 text

66

Slide 67

Slide 67 text

67

Slide 68

Slide 68 text

68

Slide 69

Slide 69 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘sesame’ Then the user is authenticated

Slide 70

Slide 70 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 71

Slide 71 text

71

Slide 72

Slide 72 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘mark’ and password ‘sesame’ Then the user is not authenticated

Slide 73

Slide 73 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘letmein’ Then the user is not authenticated

Slide 74

Slide 74 text

74

Slide 75

Slide 75 text

Given a user exists with username ‘james’ and password ‘sesame’ When a user logs in with username ‘james’ and password ‘letmein’ Then the user is not authenticated

Slide 76

Slide 76 text

Summary Shorten Feedback Loops Start with the smallest thing… cheat if necessary Work from the outside towards the happy path Do one thing at once Fake things Call code before writing it Test all the time Practice your practices! 76

Slide 77

Slide 77 text

Learning Resources Structured exercises—work locally • http://exercism.io/ Structured exercises you can do in the browser • https://www.hackerrank.com/ • http://www.codewars.com/ Generic problems you can try to solve in any language • http://codingdojo.org/kata/ • Book: 57 Challenges to Develop Your Coding Skills https://pragprog.com/book/bhwb/exercises-for-programmers 77

Slide 78

Slide 78 text

Any questions? Section title 78