quality code - agile academy · what is quality code / clean code? “clean code is well-crafted...

16
Quality Code By Pieter Versteijnen and Harm Pauw @pieter28, @harmpauw

Upload: others

Post on 28-Jun-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Quality Code - Agile Academy · 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

Quality Code

By Pieter Versteijnen and Harm Pauw

@pieter28, @harmpauw

Page 2: Quality Code - Agile Academy · 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

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.”

Page 3: Quality Code - Agile Academy · 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

Transparancy – Dashboards - Monitoring

Page 4: Quality Code - Agile Academy · 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

Static code analysis

Page 5: Quality Code - Agile Academy · 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

Code reviews

Page 6: Quality Code - Agile Academy · 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

Specification by example – BDD/ATDD

Page 7: Quality Code - Agile Academy · 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

TDD

TDD Demo

Page 8: Quality Code - Agile Academy · 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

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

Page 9: Quality Code - Agile Academy · 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

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

Page 10: Quality Code - Agile Academy · 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

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

Page 11: Quality Code - Agile Academy · 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

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

Page 12: Quality Code - Agile Academy · 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

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

Page 13: Quality Code - Agile Academy · 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

Statement: Test code = Production code

What do you think?

Page 14: Quality Code - Agile Academy · 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

Start creating quality code today!

Page 15: Quality Code - Agile Academy · 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

• Pieter Versteijnen

[email protected]

• @pieter28

• https://www.linkedin.com/in/pieter28

• Harm Pauw

[email protected]

• @harmpauw

• https://www.linkedin.com/in/harmpauw

Page 16: Quality Code - Agile Academy · 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

Brassersplein 1

2601 CT Delft

Tel. 015 - 24 11 900

Mail: [email protected]

www.devon.nl