The Principled Developer Gerardo Gonzalez | @fmizzell | The - - PowerPoint PPT Presentation

the principled developer
SMART_READER_LITE
LIVE PREVIEW

The Principled Developer Gerardo Gonzalez | @fmizzell | The - - PowerPoint PPT Presentation

The Principled Developer Gerardo Gonzalez | @fmizzell | The Principle The Principle | Definitions Principle: A rule or standard, especially of good behavior Software: (...) and symbolic languages that control the


slide-1
SLIDE 1

The Principled Developer

Gerardo Gonzalez | @fmizzell |

slide-2
SLIDE 2

“The” Principle

slide-3
SLIDE 3

➔ Principle: A rule or standard, especially of good behavior ➔ Software: (...) and symbolic languages that control the functioning of the hardware (...) ➔ Develop: To aid in the growth of; strengthen.

“The” Principle | Definitions

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-4
SLIDE 4

➔ To strengthen communications between humans and machines by improving our common language(s)

“The” Principle | Mission Statement

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-5
SLIDE 5

➔ Are machines the only audience of our communications? ➔ NO!!!: Our future self, other developers, the DOMAIN experts, etc

“The” Principle | Anything Missing?

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-6
SLIDE 6

➔ To strengthen communications between humans <-> machines by improving our common language(s) ➔ Improve: Clear, Dense/Powerful, Unambiguous, Simple/Accessible

“The” Principle | Improved Mission Statement

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-7
SLIDE 7

PHP and Drupal

slide-8
SLIDE 8

➔ Close to the metal: Primitive data types (string, integer, boolean, etc), operations, If statements ➔ Beyond the metal: Variables, arrays, loops, functions, classes, objects

PHP and Drupal | PHP

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-9
SLIDE 9

➔ Data in Drupal is represented by Entities. A node is the type of entity used for content. Content can have different structures. Different types of nodes can be created and are known as content types. Each content type is characterized by which fields it possesses

PHP and Drupal | Drupal

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-10
SLIDE 10

➔ Does the code match the idea?

PHP and Drupal | Drupal

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

class Node extends ContentEntityBase implements NodeInterface { }

slide-11
SLIDE 11

Software Design Principles

slide-12
SLIDE 12

➔ S: Single responsibility principle ➔ O: Open/Closed principle ➔ L: Liskov substitution principle ➔ I: Interface segregation principle ➔ D: Dependency Inversion principle

Software Design Principles | SOLID

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-13
SLIDE 13

➔ Every subclass/derived class should be substitutable for their base/parent class

Software Design Principles | Liskov substitution principle

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

class Feline { public function meows() { return TRUE; }} class Tiger extends Feline { public function meows() { return "ROOOOOAAAARRRR!!!"; }}

slide-14
SLIDE 14

➔ A class should have one and only one reason to change, meaning that a class should have only one job

Software Design Principles | Single responsibility principle | 1

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

print "<p>Hello World!!!<\p>";

slide-15
SLIDE 15

➔ A class should have one and only one reason to change, meaning that a class should have only one job

Software Design Principles | Single responsibility principle | 2

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

$outputter->output( $formatter->format("Hello World!!!") );

slide-16
SLIDE 16

➔ Objects or entities should be open for extension, but closed for modification ➔ "Never Hack Core" ◆ hooks, events, plugins, DIC

Software Design Principles | Open/Closed principle

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-17
SLIDE 17

➔ A client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.

Software Design Principles | Interface segregation principle | 1

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-18
SLIDE 18

interface CacheInterface { public function set($cid, $data); public function get($cid); public function expire($timestamp); }

Software Design Principles | Interface segregation principle | 2

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-19
SLIDE 19

interface CacheInterface { public function set($cid, $data); public function get($cid); } interface ExpirableCacheInterface extends CacheInterface { public function expire($timestamp); }

Software Design Principles | Interface segregation principle | 3

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-20
SLIDE 20

➔ Entities must depend on abstractions not on

  • concretions. It states that the high level

module must not depend on the low level module, but they should depend on abstractions

Software Design Principles | Dependency inversion principle | 1

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-21
SLIDE 21

Software Design Principles | Dependency inversion principle | 2

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-22
SLIDE 22

➔ Engine -> Clutch

Software Design Principles | Dependency inversion principle | 3

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

class Engine { private $clutch; public function __construct() { $this->clutch = new Clutch(); } }

slide-23
SLIDE 23

➔ Engine -> ClutchInterface <- Clutch

Software Design Principles | Dependency inversion principle | 4

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

class Engine { private $clutch; public function __construct(ClutchInterface $clutch) { $this->clutch = $clutch; } }

slide-24
SLIDE 24

What about improved communications?

slide-25
SLIDE 25

➔ Principles are useful ➔ "What-if" is the enemy of "what-is" ➔ Overengineering? ➔ But, isn’t a more principled system a better system?

What about improved communications? | Recap

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-26
SLIDE 26

➔ You do not know the correct language around a problem/solution until you do ➔ Abstractions inject complexity ➔ No abstractions are better than bad abstractions

What about improved communications? | Problem

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-27
SLIDE 27

➔ Let the code express the idea ➔ Languages should evolve naturally ➔ The YAGNI principle ◆ You ain’t going to need it

What about improved communications? | Solution | 1

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-28
SLIDE 28

➔ “Domain/Knowledge Driven Refactoring” ◆ Agile, failing fast, lean development ➔ “Lots of Refactoring Means Lots of Tests” ◆ Lock your intentions

What about improved communications? | Solution | 2

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-29
SLIDE 29

Conclusion

slide-30
SLIDE 30

➔ Always improve communications by developing a better languages ➔ SOLID is solid but YAGNI ➔ Let better languages evolve through Domain/Knowledge Driven Refactoring

Conclusion

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-31
SLIDE 31

Open Discussion

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS

slide-32
SLIDE 32

Thank you.

DRUPAL GOVCON 2017 | THE PRINCIPLED DEVELOPER | GERARDO GONZALEZ | @FMIZZELL | @CIVICACTIONS