clean code in small companies - pasztor.at code in small companies.pdf · clean code in small...

109
Clean Code in Small Companies

Upload: others

Post on 16-Jul-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Clean Code in Small Companies

Page 2: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 3: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Stock photo, not actual developer

Page 4: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Stock photo, not actual developer

Page 5: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 6: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Stock photo, not actual developer

Page 7: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Robert C. Martin“Uncle Bob”

Page 8: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 9: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

1. Reading code is hard

Page 10: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

1. Reading code is hard

2. We all have to read code

Page 11: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

1. Reading code is hard

2. We all have to read code

3. Surprises are bad

Page 12: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Code in these Slides

Page 13: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$iAmAVariable

Page 14: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller {}

Class name Parent class name

Page 15: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { private $memberVariable;}

Access modifier

Page 16: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { public function someMethod( Request $request ) { }}

Method name

Parameter type hint

Page 17: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

https://pasztor.at

Page 18: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

A few words on testing...More on this later

Page 19: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) {

}}

Page 20: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testRegistration() {

}

Page 21: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake();

}

Page 22: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake(); $userController = new UserController( $userBusinessLogic );

}

Page 23: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake(); $userController = new UserController( $userBusinessLogic ); //Test the user controller}

Page 24: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Dependency InjectionDon’t look for things!

Page 25: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 26: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 27: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')

Page 28: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')

Page 29: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')

Page 30: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')

Page 31: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

UserController

Page 32: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

UserController

Magic?

Page 33: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

UserController

Magic?

security.authorization_checker

Page 34: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 35: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller {

}

Page 36: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller {

}

Page 37: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function __construct( ) { }

}

Page 38: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController {

public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { }

}

Page 39: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker ; }

}

Page 40: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker; }

/** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ($this->securityAuthorizationChecker->isGranted('ROLE_SUPER_ADMIN')) { return $this->redirectToRoute( 'admin_dashboard'); } }}

Page 41: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker; }

/** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ($this->securityAuthorizationChecker->isGranted('ROLE_SUPER_ADMIN')) { return $this->redirectToRoute( 'admin_dashboard'); } }}

Page 42: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Dependency InjectorsMoving the Magic out of your Program

Page 43: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

UserController

UserBusinessLogic

UserStorage

Page 44: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}

Page 45: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}class UserBusinessLogic { public function __construct( UserStorage $userStorage ) { }}

Page 46: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}class UserBusinessLogic { public function __construct( UserStorage $userStorage ) { }}class UserStorage {}

Page 47: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$uc = new UserController( new UserBusinessLogic( new UserStorage() ));

Page 48: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$injector = new Injector();

Page 49: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$injector = new Injector();

$uc = $injector->make(UserController::class);

Page 50: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class MySQLConnection { public function __construct( string $server, string $username, string $password, string $db ) { }}

Page 51: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$injector->define(MySQLConnection::class, [ 'server' => 'localhost', 'user' => 'root', 'password' => 'changeme', 'db' => 'app']);

Page 52: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

● PHP: Auryn, Laravel Service Container, Symfony Service Container

● Java: Gource, Dagger, Dagger2, Opsbears Web Components DIC

● Python: dependency_injector

● Javascript: InversifyJS

Page 53: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 54: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 55: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 56: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 57: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Static Function CallsMight Be Bad For Your Code Quality

Page 58: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 59: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( SecurityAuthorizationChecker ::isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}

Page 60: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

$uc = new UserController();

Page 61: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Immutable ObjectsAvoiding Surprises

Page 62: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}

Page 63: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

new User()

Page 64: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}

Page 65: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}

Page 66: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class User { private $id; public function __construct($id) { $this->id = $id; } public function getId() { return $this->id; }}

Page 67: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserStorage { private $users = []; public function store(User $user) { $this->users[$user->getId()] = $user; } }

Page 68: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserStorage { private $users = []; public function store(User $user) { $this->users[$user->getId()] = $user; } public function retrieve($id) { if (isset($this->users[$id])) { return $this->users[$id]; } else { throw new UserNotFoundException($id); } }}

Page 69: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Less Code in One ClassYour All-In-One Weightloss Program

Page 70: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserController { public function register() {}

public function search() {}

public function get() {}

public function update() {}

public function delete() {}}

Page 71: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Route::get( '/users', function (

) { return 'User list'; });

Page 72: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Route::get( '/users', function ( UserBusinessLogic $userBusinessLogic ) { return 'User list'; });

Page 73: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

class UserRegisterController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }

public function register() { }}

Page 74: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Static TypingSaves you from a **** ton of issues

Page 75: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function search( $needle, $haystack) {

}

Page 76: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function search( string $needle, array $haystack) {

}

Page 77: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

mypyPythonbuiltinJava

phpstanPHP

JavaScript Typescript

Page 78: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Strict TypingBecause your String is not an Integer

Page 79: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

<?php

declare(strict_types=1);PHP

Page 80: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

<?php

declare(strict_types=1);

Typescript

PHP

JavaScript

Page 81: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Structuring your CodeBecause your Code is not a Clown Car

Page 82: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

/controller

UserRegisterController.php

UserListController.php

/model

/view

Page 83: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

/user

/controller

UserRegisterController.php

UserListController.php

/business

/storage

/blog

/controller

/business

/storage

Page 84: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

TestingYou test your code, right?

Page 85: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Application

Page 86: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

User Interface

Application

Page 87: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

User Interface

Application

Test Code

Page 88: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

User Interface

ApplicationDatabase Connector

Test Code

Page 89: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

User Interface

ApplicationDatabase Connector

Test Database

Test Code

Page 90: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

User Interface

ApplicationDatabase Connector

Test Database

Test Code

Page 91: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Application

Page 92: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Application

Test Code

Page 93: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Application

Test Code

Fake Database Connector

Page 94: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Application

Test Code

Fake Database Connector

Page 95: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Test Code

Fake Application

User Interface

Page 96: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testGetShouldReturnUser(){ //region Setup $userStorage = new UserStorageFake(); $userStorage->backingStorage['test-user'] = UserFactory::create( "test-user", "Test User", "[email protected]", "*" ); $business = new UserGetBusinessLogicImpl($userStorage); //endregion

//region Execute...

//region Asset...}

Page 97: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

function testGetShouldReturnUser(){ //region Setup...

//region Execute $user = $business->getById("test-user"); //endregion

//region Assert assertEquals("test-user", $user->getId()); //endregion}

Page 98: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Putting it togetherBuilding an actual system

Page 99: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Many thanks to: Cristina Laskar

Page 100: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 101: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 102: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 103: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

API

Business Logic

Storage

MySQL or HSQLDB

Single Page Application

HTT

P

Page 104: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

API

Business Logic

Storage

DataMapper / ORM

Routing / Object Decoding

MySQL or HSQLDB

Single Page Application

HTT

P

Page 105: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock
Page 106: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

Non-technical WaysCustomer Communication is Important

Page 107: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

UX design by @gogospaso

Page 108: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock

More informationBecause one talk is not enough

Page 109: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock