![Page 1: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/1.jpg)
Is what you’ve coded what you mean?
Dave Liddament (@daveliddament)
![Page 2: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/2.jpg)
A confession….
@DaveLiddament
![Page 3: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/3.jpg)
First let’s talk about bugs….
@DaveLiddament
![Page 4: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/4.jpg)
Question 1: Who puts bugs in
their code?
@DaveLiddament
![Page 5: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/5.jpg)
Question 2: When is the best
time to find a bug?
@DaveLiddament
![Page 6: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/6.jpg)
Best time to find a bug?
@DaveLiddament
![Page 7: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/7.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
![Page 8: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/8.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
![Page 9: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/9.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
![Page 10: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/10.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
![Page 11: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/11.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
Testing
![Page 12: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/12.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
Testing
![Page 13: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/13.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
Testing Writing code
![Page 14: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/14.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
Testing Writing code
![Page 15: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/15.jpg)
Best time to find a bug?
@DaveLiddament
Months into
operation
Feature is first used
Testing Writing code
Before writing code
![Page 16: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/16.jpg)
@DaveLiddament
Why do bugs happen?
![Page 17: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/17.jpg)
@DaveLiddament
What the code should do
Why do bugs happen?
![Page 18: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/18.jpg)
@DaveLiddament
What the code should do
What the code actually does
Why do bugs happen?
![Page 19: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/19.jpg)
@DaveLiddament
What the code should do
What the code actually does
What the developer thinks the code does
Why do bugs happen?
![Page 20: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/20.jpg)
@DaveLiddament
What the code should do
What the code actually does
What the developer thinks the code does
Why do bugs happen?
![Page 21: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/21.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Why this talk?
![Page 22: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/22.jpg)
@DaveLiddament
What the code should do What the
code actually does
What the developer thinks the code does
How we reduce cost of bugs
![Page 23: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/23.jpg)
Pay attention!
@DaveLiddament
Dave Liddament @daveliddament
Lamp Bristol
15+ years software development (PHP, Java, Python, C)
Organise PHP-SW user group and Bristol PHP Training
![Page 24: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/24.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
![Page 25: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/25.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Obvious code
![Page 26: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/26.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Obvious code
Run time analysis
![Page 27: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/27.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Obvious code
Run time analysis
Static analysis
![Page 28: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/28.jpg)
@DaveLiddament
Static analysis
![Page 29: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/29.jpg)
@DaveLiddament
function process($user) { // some implementation }
$a = 1; process($a);
Is this code valid?
![Page 30: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/30.jpg)
function process(User $user) { // some implementation }
$a = 1; process($a);
@DaveLiddament
Is this code valid?
![Page 31: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/31.jpg)
function process(User $user) { // some implementation }
$a = 1; process($a);
@DaveLiddament
Is this code valid?
![Page 32: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/32.jpg)
function process(User $user) { // some implementation }
$a = 1; process($a);
@DaveLiddament
Is this code valid?
![Page 33: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/33.jpg)
function process(User $user) { // some implementation }
$a = 1; process($a);
@DaveLiddament
Is this code valid?
![Page 34: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/34.jpg)
@DaveLiddament
![Page 35: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/35.jpg)
@DaveLiddament
![Page 36: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/36.jpg)
function process(User $user) { // some implementation }
$a = 1; process($a);
@DaveLiddament
Type hinting has helped
![Page 37: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/37.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
![Page 38: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/38.jpg)
@DaveLiddament
More type hinting with PHP 7
function duplicateString ( string $value, int $times) :string
![Page 39: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/39.jpg)
@DaveLiddament
More type hinting with PHP 7
function duplicateString ( string $value, int $times) :string
![Page 40: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/40.jpg)
@DaveLiddament
More type hinting with PHP 7
function duplicateString ( string $value, int $times) :string
![Page 41: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/41.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 42: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/42.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 43: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/43.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 44: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/44.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 45: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/45.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 46: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/46.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 47: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/47.jpg)
@DaveLiddament
Is this code valid?
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(12); process($a);
![Page 48: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/48.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Win Win
![Page 49: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/49.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Win Win
![Page 50: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/50.jpg)
@DaveLiddament
Language level validation
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(“dave”); process($a);
![Page 51: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/51.jpg)
@DaveLiddament
Language level validation
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(“dave”); process($a);
![Page 52: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/52.jpg)
@DaveLiddament
Language level validation
function getUser(int $id): User {…}
function process(User $user): void {…}
$a = getUser(“dave”); process($a);
![Page 53: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/53.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 54: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/54.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 55: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/55.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 56: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/56.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 57: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/57.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 58: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/58.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 59: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/59.jpg)
@DaveLiddament
Static analysis can cover language gapsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getAccountNumber(); }
![Page 60: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/60.jpg)
@DaveLiddament
Static analysis can find errorsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getSomething(); }
![Page 61: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/61.jpg)
@DaveLiddament
Static analysis can find errorsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getSomething(); }
![Page 62: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/62.jpg)
@DaveLiddament
Static analysis can find errorsclass User { public function getAccountNumber() :string {…} }
/** * @return User[] */ function getUsers(): array { … }
$users = getUsers(); foreach($users as $user) { $accountNumber = $user->getSomething(); }
![Page 63: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/63.jpg)
Static analysis helps developers
![Page 64: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/64.jpg)
@DaveLiddament
Static analysis recap
![Page 65: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/65.jpg)
@DaveLiddament
Static analysis recap• Analyse code without running it
![Page 66: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/66.jpg)
@DaveLiddament
Static analysis recap• Analyse code without running it
• Prevent bugs even entering the code base
![Page 67: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/67.jpg)
@DaveLiddament
Static analysis recap• Analyse code without running it
• Prevent bugs even entering the code base
• Type hinting and doc blocks comments help static analysis tools
•which in turn help developers
![Page 68: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/68.jpg)
@DaveLiddament
Static analysis recap• Analyse code without running it
• Prevent bugs even entering the code base
• Type hinting and doc blocks comments help static analysis tools
•which in turn help developers
• Use an IDE that offers static analysis
![Page 69: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/69.jpg)
@DaveLiddament
Run time checks
![Page 70: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/70.jpg)
@DaveLiddament
Run time checks
• Tests
![Page 71: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/71.jpg)
@DaveLiddament
Run time checks
• Tests
• Assertions
![Page 72: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/72.jpg)
@DaveLiddament
Tests are assertions
![Page 73: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/73.jpg)
@DaveLiddament
Tests are assertions
If I apply a discount code “SPEAKER”
![Page 74: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/74.jpg)
@DaveLiddament
Tests are assertions
If I apply a discount code “SPEAKER”
My conference ticket is reduced to £90
![Page 75: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/75.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Benefits of testing
![Page 76: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/76.jpg)
@DaveLiddament
What the code should do
What the code actually does
Benefits of testing
![Page 77: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/77.jpg)
@DaveLiddament
What the code should do
What the code actually does
Benefits of testing
![Page 78: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/78.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Benefits of testing
What the code should do
![Page 79: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/79.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Benefits of testing
What the code should do
![Page 80: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/80.jpg)
@DaveLiddament
Assertions in code
![Page 81: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/81.jpg)
@DaveLiddament
Assertions in code
Statements that the developer believes should always be true
![Page 82: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/82.jpg)
@DaveLiddament
Code that worries me…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; }
sendMessage($message);
![Page 83: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/83.jpg)
@DaveLiddament
Code that worries me…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; }
sendMessage($message);
![Page 84: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/84.jpg)
@DaveLiddament
Code that worries me…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; }
sendMessage($message);
![Page 85: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/85.jpg)
@DaveLiddament
Code that worries me…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; }
sendMessage($message);
![Page 86: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/86.jpg)
@DaveLiddament
Now I’m happier…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; } else { throw new Exception(“Invalid type”); } sendMessage($message);
![Page 87: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/87.jpg)
@DaveLiddament
Now I’m happier…if ($type == 1) { $message = ‘hello’; } elseif ($type == 2) { $message = ‘goodbye’; } else { throw new Exception(“Invalid type”); } sendMessage($message);
![Page 88: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/88.jpg)
public function setStatus(string $status){ $this->status = $status; }
@DaveLiddament
Can we improve this code
![Page 89: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/89.jpg)
const REGISTERED = ‘registered’; const STARTED = ‘started’; const FINISHED = ‘finished’; const QUIT = ‘quit’;
public function setStatus(string $status){ $this->status = $status; }
@DaveLiddament
Improvement 1: Add constants
![Page 90: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/90.jpg)
const REGISTERED = ‘registered’; const STARTED = ‘started’; const FINISHED = ‘finished’; const QUIT = ‘quit’;
public function setStatus(string $status){ $this->status = $status; }
@DaveLiddament
Improvement 1: Add constants
![Page 91: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/91.jpg)
@DaveLiddament
Improvement 2: Add assertion… constants defined as before …
public function setStatus(string $status){ if (!in_array($status,[self::REGISTERED, self::STARTED, self::FINISHED]) { throw new Exception(“Invalid status”); } $this->status = $status; }
![Page 92: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/92.jpg)
@DaveLiddament
Improvement 2: Add assertion… constants defined as before …
public function setStatus(string $status){ if (!in_array($status,[self::REGISTERED, self::STARTED, self::FINISHED]) { throw new Exception(“Invalid status”); } $this->status = $status; }
![Page 93: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/93.jpg)
@DaveLiddament
Improvement 2: Add assertion… constants defined as before …
public function setStatus(string $status){ if (!in_array($status,[self::REGISTERED, self::STARTED, self::FINISHED]) { throw new Exception(“Invalid status”); } $this->status = $status; }
![Page 94: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/94.jpg)
@DaveLiddament
Improving error messages
![Page 95: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/95.jpg)
@DaveLiddament
Improving error messages
Invalid type
![Page 96: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/96.jpg)
@DaveLiddament
Improving error messages
Invalid type
Invalid type [$type]
![Page 97: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/97.jpg)
@DaveLiddament
Improving error messages
Invalid type
Invalid type [$type]
Invalid type [$type] for user [$userId]
![Page 98: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/98.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Wins from asserts
![Page 99: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/99.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Wins from asserts
![Page 100: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/100.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Benefits of assertions
![Page 101: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/101.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Benefits of assertions and a good test suite
![Page 102: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/102.jpg)
@DaveLiddament
Obvious code
![Page 103: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/103.jpg)
@DaveLiddament
Obvious code• Value Objects
![Page 104: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/104.jpg)
@DaveLiddament
Obvious code• Value Objects
• Rename and Refactor
![Page 105: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/105.jpg)
@DaveLiddament
Value Objects
![Page 106: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/106.jpg)
@DaveLiddament
Can we improve this code?class MarketingCampaign {
… some methods …
public function addAddress(string $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“[email protected]”)
![Page 107: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/107.jpg)
@DaveLiddament
Can we improve this code?class MarketingCampaign {
… some methods …
public function addAddress(string $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“[email protected]”)
![Page 108: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/108.jpg)
@DaveLiddament
These are all strings…
fredblogs.comfred.blogs
6 Lower Park Row, Bristol
![Page 109: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/109.jpg)
@DaveLiddament
These are all strings…
fredblogs.comfred.blogs
6 Lower Park Row, Bristol
![Page 110: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/110.jpg)
@DaveLiddament
class MarketingCampaign {
.. some methods ..
public function addAddress(string $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“6 Lower Park Row, Bristol”)
This is wrong (and our IDE can’t spot mistake)
![Page 111: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/111.jpg)
@DaveLiddament
class MarketingCampaign {
.. some methods ..
public function addAddress(string $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“6 Lower Park Row, Bristol”)
This is wrong (and our IDE can’t spot mistake)
![Page 112: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/112.jpg)
@DaveLiddament
EmailAddress object instead of primitiveclass EmailAddress {
private $emailAddress; public function __construct(string $emailAddress) { $this->emailAddress = $emailAddress; }
public function getEmailAddress(): string { return $this->emailAddress; } }
![Page 113: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/113.jpg)
@DaveLiddament
EmailAddress object instead of primitiveclass EmailAddress {
private $emailAddress; public function __construct(string $emailAddress) { $this->emailAddress = $emailAddress; }
public function getEmailAddress(): string { return $this->emailAddress; } }
![Page 114: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/114.jpg)
@DaveLiddament
EmailAddress object instead of primitiveclass EmailAddress {
private $emailAddress; public function __construct(string $emailAddress) { $this->emailAddress = $emailAddress; }
public function getEmailAddress(): string { return $this->emailAddress; } }
![Page 115: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/115.jpg)
@DaveLiddament
EmailAddress object instead of primitiveclass EmailAddress {
private $emailAddress; public function __construct(string $emailAddress) { $this->emailAddress = $emailAddress; }
public function getEmailAddress(): string { return $this->emailAddress; } }
![Page 116: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/116.jpg)
@DaveLiddament
Using EmailAddressclass MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $emailAddress = new EmailAddress(“[email protected]”) $campaign->addAddress($emailAddress)
![Page 117: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/117.jpg)
@DaveLiddament
Using EmailAddressclass MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $emailAddress = new EmailAddress(“[email protected]”) $campaign->addAddress($emailAddress)
![Page 118: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/118.jpg)
@DaveLiddament
Using EmailAddressclass MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $emailAddress = new EmailAddress(“[email protected]”) $campaign->addAddress($emailAddress)
![Page 119: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/119.jpg)
@DaveLiddament
Using EmailAddressclass MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $emailAddress = new EmailAddress(“[email protected]”) $campaign->addAddress($emailAddress)
![Page 120: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/120.jpg)
@DaveLiddament
class MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“6 Lower Park Row, Bristol”)
This will fail (and your IDE will warn you)
![Page 121: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/121.jpg)
@DaveLiddament
class MarketingCampaign {
.. some methods ..
public function addAddress(EmailAddress $address); }
$campaign = new MarketingCampaign(); $campaign->addAddress(“6 Lower Park Row, Bristol”)
This will fail (and your IDE will warn you)
![Page 122: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/122.jpg)
@DaveLiddament
$emailAddress = new EmailAddress(“6 Lower Park Row”);
But this is wrong
![Page 123: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/123.jpg)
@DaveLiddament
$emailAddress = new EmailAddress(“6 Lower Park Row”);
But this is wrong
![Page 124: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/124.jpg)
@DaveLiddament
public function __construct(string $emailAddress) { if ( … check email address is valid… == false) { throw new Exception( “Invalid email address [$emailAddress]”); }
$this->emailAddress = $emailAddress; }
Add validation
![Page 125: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/125.jpg)
@DaveLiddament
public function __construct(string $emailAddress) { if ( … check email address is valid… == false) { throw new Exception( “Invalid email address [$emailAddress]”); }
$this->emailAddress = $emailAddress; }
Add validation
![Page 126: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/126.jpg)
We’re guaranteed that EmailAddress represents a correctly formatted email
address.
@DaveLiddament
Big win
![Page 127: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/127.jpg)
@DaveLiddament
Are these email addresses the same?
![Page 128: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/128.jpg)
@DaveLiddament
Store canonical form
public function __construct(string $emailAddress) {
… validate email address … $this->emailAddress = $this->getCanonical($emailAddress); }
![Page 129: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/129.jpg)
@DaveLiddament
Store canonical form
public function __construct(string $emailAddress) {
… validate email address … $this->emailAddress = $this->getCanonical($emailAddress); }
![Page 130: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/130.jpg)
@DaveLiddament
Postcodes formats
Normal: No spaces: Fixed width:
B1 1AB B11AB B1 1AB
![Page 131: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/131.jpg)
@DaveLiddament
Add domain specific logic
public function getPostcode(): string {…}
public function getNoSpacesPostcode(): string {…}
public function getFixedWidthPostcode(): string {…}
![Page 132: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/132.jpg)
@DaveLiddament
Are these positions equal?
A
B C
![Page 133: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/133.jpg)
@DaveLiddament
Are these positions equal?
A
B C
![Page 134: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/134.jpg)
@DaveLiddament
Add equals methodclass Point { const TOLERANCE = 10;
… Other methods …
public function equals(Point $other): bool { $distance = calculateDistance($this, $other); return $distance < self::TOLERANCE; } }
![Page 135: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/135.jpg)
@DaveLiddament
Add equals methodclass Point { const TOLERANCE = 10;
… Other methods …
public function equals(Point $other): bool { $distance = calculateDistance($this, $other); return $distance < self::TOLERANCE; } }
![Page 136: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/136.jpg)
@DaveLiddament
Be careful comparing objects… if ($point1 == $point2) { … some code … }
if ($point1->equals($point2)) { … some code … }
![Page 137: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/137.jpg)
@DaveLiddament
Be careful comparing objects… if ($point1 == $point2) { … some code … }
if ($point1->equals($point2)) { … some code … }
![Page 138: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/138.jpg)
@DaveLiddament
Be careful comparing objects… if ($point1 == $point2) { … some code … }
if ($point1->equals($point2)) { … some code … }
![Page 139: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/139.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Benefits of Value Objects
![Page 140: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/140.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Wins from Value Objects
![Page 141: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/141.jpg)
@DaveLiddament
What the code actually does
What the developer thinks the code does
Wins from Value Objects
![Page 142: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/142.jpg)
@DaveLiddament
Rename and Refactor
![Page 143: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/143.jpg)
Kno
wle
ge
Time on project
![Page 144: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/144.jpg)
@DaveLiddament
Renamingclass User { public function getName() {…} }
class Game { public function getName() {…} }
![Page 145: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/145.jpg)
@DaveLiddament
Renamingclass User { public function getName() {…} }
class Game { public function getName() {…} }
![Page 146: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/146.jpg)
@DaveLiddament
Renamingclass User { public function getName() {…} }
class Game { public function getQuest() {…} }
![Page 147: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/147.jpg)
@DaveLiddament
Renamingclass User { public function getName() {…} }
class Game { public function getQuest() {…} }
![Page 148: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/148.jpg)
@DaveLiddament
Renamingfunction getUser();
function getGame();
$user = getUser(); $game = getGame();
echo ‘Hello ‘ . $user->getName(); echo ‘You are playing ‘ . $game->getName();
![Page 149: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/149.jpg)
@DaveLiddament
Renamingfunction getUser();
function getGame();
$user = getUser(); $game = getGame();
echo ‘Hello ‘ . $user->getName(); echo ‘You are playing ‘ . $game->getName();
![Page 150: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/150.jpg)
@DaveLiddament
Renamingfunction getUser(): User;
function getGame(): Game;
$user = getUser(); $game = getGame();
echo ‘Hello ‘ . $user->getName(); echo ‘You are playing ‘ . $game->getQuest();
![Page 151: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/151.jpg)
@DaveLiddament
Renamingfunction getUser(): User;
function getGame(): Game;
$user = getUser(); $game = getGame();
echo ‘Hello ‘ . $user->getName(); echo ‘You are playing ‘ . $game->getQuest();
![Page 152: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/152.jpg)
@DaveLiddament
Renamingfunction getUser(): User;
function getGame(): Game;
$user = getUser(); $game = getGame();
echo ‘Hello ‘ . $user->getName(); echo ‘You are playing ‘ . $game->getQuest();
![Page 153: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/153.jpg)
@DaveLiddament
Win-Win: Rename and refactor
![Page 154: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/154.jpg)
Months into
operation
Feature is first used
Testing Writing code
Before writing code
Summary
![Page 155: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/155.jpg)
@DaveLiddament
What the code should do What the
code actually does
What the developer thinks the code does
Summary
![Page 156: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/156.jpg)
@DaveLiddament
Summary
![Page 157: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/157.jpg)
@DaveLiddament
Summary
• Type hint everything you can
![Page 158: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/158.jpg)
@DaveLiddament
Summary
• Type hint everything you can• Use docblock for language gaps
![Page 159: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/159.jpg)
@DaveLiddament
Summary
• Type hint everything you can• Use docblock for language gaps• Write tests
![Page 160: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/160.jpg)
@DaveLiddament
Summary
• Type hint everything you can• Use docblock for language gaps• Write tests• Add assertions
![Page 161: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/161.jpg)
@DaveLiddament
Summary
• Type hint everything you can• Use docblock for language gaps• Write tests• Add assertions• Use Value Objects
![Page 162: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/162.jpg)
@DaveLiddament
Summary
• Type hint everything you can• Use docblock for language gaps• Write tests• Add assertions• Use Value Objects• Rename and refactor
![Page 163: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/163.jpg)
@DaveLiddament
Summary
• Use a modern IDE
![Page 164: Is what you’ve coded what you mean? - Dave Liddament · 2020. 5. 28. · First let’s talk about bugs…. @DaveLiddament. Question 1: Who puts bugs in their code? @DaveLiddament](https://reader034.vdocuments.site/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fb/html5/thumbnails/164.jpg)
@DaveLiddament
Questions