quality code - agile academy · what is quality code / clean code? “clean code is well-crafted...
TRANSCRIPT
Quality Code
By Pieter Versteijnen and Harm Pauw
@pieter28, @harmpauw
What is quality code / clean code?
“Clean code is well-crafted code. Written
by programmers who do care about the
software they produce, making it easy to
maintain and understand. Professional
software developers do not write code for
machines, they write code for human
beings – carefully.”
Transparancy – Dashboards - Monitoring
Static code analysis
Code reviews
Specification by example – BDD/ATDD
TDD
TDD Demo
What are you going to create using TDD?
• Dutch IBAN check
– Correct NL IBAN: (Example: NL39 RABO 0300 0652 64)
• A country code of two letters according ISO 3166-1,
• A validation number existing of two numbers accoriding ISO 7064,
• An account identification exists of a maximum of 30 numbers and letters
– Netherlands (length 18): NLkk BBBB CCCC CCCC CK
• kk = validation number of the IBAN
• B = bankcode
• K = validationnumber (Already part of the national accountnumber)
• C = bankaccount number, if nescesarry added with zero’s
– The validationnumber is calculated by:
• Take the bankaccount identification
• Add the country code at the end
• Replace the letters by a two digit number, A=10, B=11, ..., Y=34, Z=35
• Add two zero’s at the end
• Take the result of the mod 97 of that number
• The validationnumber is a result of 98 minus the result of the mod
• When the validation number is below zero add a zero in front of it.
• Validate
– An IBAN should be validated by converting the complete IBAN to numbers. Then divide by 97 the number that’s left should be 1.
– The IBAN algoritm:
• Validate composition
• Move the first four characters to the end
• Replace the letters by a number, A = 10, B = 11, ..., Z = 35
• Calculate the mod 97
• If the result is 1 that the number should be a valid IBAN
What is the first unit test you will create?
• Dutch IBAN check
– Correct NL IBAN: (Example: NL39 RABO 0300 0652 64)
• A country code of two letters according ISO 3166-1,
• A validation number existing of two numbers accoriding ISO 7064,
• An account identification exists of a maximum of 30 numbers and letters
– Netherlands (length 18): NLkk BBBB CCCC CCCC CK
• kk = validation number of the IBAN
• B = bankcode
• K = validationnumber (Already part of the national accountnumber)
• C = bankaccount number, if nescesarry added with zero’s
– The validationnumber is calculated by:
• Take the bankaccount identification
• Add the country code at the end
• Replace the letters by a two digit number, A=10, B=11, ..., Y=34, Z=35
• Add two zero’s at the end
• Take the result of the mod 97 of that number
• The validationnumber is a result of 98 minus the result of the mod
• When the validation number is below zero add a zero in front of it.
• Validate
– An IBAN should be validated by converting the complete IBAN to numbers. Then divide by 97 the number that’s left should be 1.
– The IBAN algoritm:
• Validate composition
• Move the first four characters to the end
• Replace the letters by a number, A = 10, B = 11, ..., Z = 35
• Calculate the mod 97
• If the result is 1 that the number should be a valid IBAN
What is the first unit test you will create?
• Start with the happy flow. So start your test with a correct bank
account number
• Add unit tests for each rule after that
TDD best practises
The rules from Uncle Bob:1. You are not allowed to write any production code unless it is to
make a failing unit test pass.2. You are not allowed to write any more of a unit test than is
sufficient to fail; and compilation failures are failures.3. You are not allowed to write any more production code than is
sufficient to pass the one failing unit test.
Transformation Priority PremiseThe more detailed your tests become the more generic your code should be
Create the validator using TDD?
• Dutch IBAN check
– Correct NL IBAN: (Example: NL39 RABO 0300 0652 64)
• A country code of two letters according ISO 3166-1,
• A validation number existing of two numbers accoriding ISO 7064,
• An account identification exists of a maximum of 30 numbers and letters
– Netherlands (length 18): NLkk BBBB CCCC CCCC CK
• kk = validation number of the IBAN
• B = bankcode
• K = validationnumber (Already part of the national accountnumber)
• C = bankaccount number, if nescesarry added with zero’s
– The validationnumber is calculated by:
• Take the bankaccount identification
• Add the country code at the end
• Replace the letters by a two digit number, A=10, B=11, ..., Y=34, Z=35
• Add two zero’s at the end
• Take the result of the mod 97 of that number
• The validationnumber is a result of 98 minus the result of the mod
• When the validation number is below zero add a zero in front of it.
• Validate
– An IBAN should be validated by converting the complete IBAN to numbers. Then divide by 97 the number that’s left should be 1.
– The IBAN algoritm:
• Validate composition
• Move the first four characters to the end
• Replace the letters by a number, A = 10, B = 11, ..., Z = 35
• Calculate the mod 97
• If the result is 1 that the number should be a valid IBAN
The rules from Uncle Bob:1. You are not allowed to write any production
code unless it is to make a failing unit test pass.
2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
Transformation Priority PremiseThe more detailed your tests become the more generic your code should be
Statement: Test code = Production code
What do you think?
Start creating quality code today!
• Pieter Versteijnen
• @pieter28
• https://www.linkedin.com/in/pieter28
• Harm Pauw
• @harmpauw
• https://www.linkedin.com/in/harmpauw