Slide 1

Slide 1 text

NAMING A LITTLE THEORY ABOUT

Slide 2

Slide 2 text

HELLO AGAIN FRANK KLEINE ▸ Software Architect at 1&1 Internet ▸ @bovigo Taken at dotGo 2016 in Paris on October 10, 2016 by Nicolas Ravelli

Slide 3

Slide 3 text

EXAMPLE WTF? CONTAINER? MANAGER? Code snippet: Laravel Capsule for buildung SQL queries by @SenseException

Slide 4

Slide 4 text

A COMMON FALLACY IS TO ASSUME AUTHORS OF INCOMPREHENSIBLE CODE WILL SOMEHOW BE ABLE TO EXPRESS THEMSELVES LUCIDLY AND CLEARLY IN COMMENTS. Kevlin Henney COMMENTS https://twitter.com/KevlinHenney/status/381021802941906944

Slide 5

Slide 5 text

THERE ARE ONLY TWO HARD THINGS IN COMPUTER SCIENCE: CACHE INVALIDATION AND NAMING THINGS. Phil Karlton NAMING IS HARD http://martinfowler.com/bliki/TwoHardThings.html

Slide 6

Slide 6 text

THERE ARE TWO PROBLEMS IN COMPUTER SCIENCE: THERE’S ONLY ONE JOKE, AND IT ISN’T FUNNY. Peter Hilton IS IT? From: Why naming things is hard

Slide 7

Slide 7 text

IF NAMES BE NOT CORRECT, LANGUAGE IS NOT IN ACCORDANCE WITH THE TRUTH OF THINGS. Confucius IMPORTANCE From: The Analects of Confucius

Slide 8

Slide 8 text

DEFINITION WIKIPEDIA ABOUT PRODUCT NAMING Naming is the discipline of deciding what a product will be called, and is very similar in concept and approach to the process of deciding on a name for a company or organization. Product naming is considered a critical part of the branding process, which includes all of the marketing activities that affect the brand image, such as positioning and the design of logo, packaging and the product itself. The process involved in product naming can take months or years to complete. Some key steps include specifying the objectives of the branding, developing the product name itself, evaluating names through target market testing and focus groups, choosing a final product name, and finally identifying it as a trademark for protection. https://en.wikipedia.org/wiki/Product_naming

Slide 9

Slide 9 text

PRODUCT THE CODE IS YOUR PRODUCT API classes & interfaces & methods functions constants & variables

Slide 10

Slide 10 text

NAMES AND ATTRIBUTES MUST BE ACCOMMODATED TO THE ESSENCE OF THINGS, AND NOT THE ESSENCE TO THE NAMES, SINCE THINGS COME FIRST AND NAMES AFTERWARDS. Galileo Galilei INITIAL NAMES From: Discoveries and Opinions of Galileo

Slide 11

Slide 11 text

NAMES: ASAP* *As Specific As Possible

Slide 12

Slide 12 text

KEY STEPS Learn and understand the domain Rename things Use a thesaurus Rename things Learn and understand the domain Rename things

Slide 13

Slide 13 text

AN OBJECT IS NOT SO LINKED TO ITS NAME THAT ONE CAN NOT FIND FOR IT ANOTHER ONE WHICH IS MORE SUITABLE. René Magritte RENAMING From: Le mots et les images

Slide 14

Slide 14 text

NAMES ARE NOT ALWAYS WHAT THEY SEEM. Mark Twain ITERATE From: Following the Equator: A Journey Around the World

Slide 15

Slide 15 text

THE 7 STAGES OF NAMING From: Good naming is a process, not a single step, by Arlo Belshee

Slide 16

Slide 16 text

MEASURE ARE DOMAIN KEYWORDS RECOGNIZABLE?

Slide 17

Slide 17 text

VFSSTREAM

Slide 18

Slide 18 text

BOVIGO/ASSERT

Slide 19

Slide 19 text

BITEXPERT/DISCO

Slide 20

Slide 20 text

TOWARDS DOMAIN KEYWORDS $portfolioIdsByTraderId = …; … if (isset($portfolioIdsByTraderId[$trader->getId()][$portfolioId])) {…} Adapted from: 97 Things Every Programmer Should Know, Chapter: Code in the Language of the Domain by Dan North if ($trader->canView($portfolio)) {...} VS.

Slide 21

Slide 21 text

BE PRECISE ELIMINATE UNNECESSARY NOISE SubscriptionsService ConnectionFailureException RequestInterface getVvalue()

Slide 22

Slide 22 text

STRUCTURE SUPPORT BY The World's First Hyperboloid Lattice Diagrid Structure in Polibino, Lipetsk Oblast. Inside view. Image by Sergei Arssenev, CC-SA-BY-3.0

Slide 23

Slide 23 text

SOMETIMES, THE ELEGANT IMPLEMENTATION IS JUST A FUNCTION. NOT A METHOD. NOT A CLASS. NOT A FRAMEWORK. JUST A FUNCTION. John Carmack NAMING AND STRUCTURES http://www.azquotes.com/quote/1022779

Slide 24

Slide 24 text

PHP & FUNCTIONS E_TOO_MANY_CLASSES ▸ Don’t undervalue functions ▸ Put them in namespaces, but group them in a file ▸ Autoload the file with Composer "autoload": { "files": ["src/functions.php"] }

Slide 25

Slide 25 text

FUNCTION USAGE namespace my\example; use function bovigo\assert\assert; use function bovigo\assert\predicate\isOfSize; class KinderSurpriseTest extends \PHPUnit_Framework_TestCase { /** @test */ public function isThreeThingsInOne() { $valueForUser = PurchaseKinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert

Slide 26

Slide 26 text

FUNCTION USAGE namespace my\example; use function bovigo\assert\assert; use function bovigo\assert\predicate\isOfSize; class KinderSurpriseTest extends \PHPUnit_Framework_TestCase { /** @test */ public function isThreeThingsInOne() { $valueForUser = PurchaseKinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert

Slide 27

Slide 27 text

FUNCTION USAGE namespace my\example; use function bovigo\assert\assert; use function bovigo\assert\predicate\isOfSize; class KinderSurpriseTest extends \PHPUnit_Framework_TestCase { /** @test */ public function isThreeThingsInOne() { $valueForUser = PurchaseKinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert

Slide 28

Slide 28 text

STILL ROOM FOR IMPROVEMENT namespace my\example; use function bovigo\assert\assert; use function bovigo\assert\predicate\isOfSize; class KinderSurpriseTest extends \PHPUnit_Framework_TestCase { /** @test */ public function isThreeThingsInOne() { $valueForUser = PurchaseKinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert THERE’S NO NEED FOR THAT EXCEPT THAT THE TEST FRAMEWORK REQUIRES IT

Slide 29

Slide 29 text

NO UNNECESSARY NOISE namespace my\example; use function bovigo\assert\assert; use function bovigo\assert\predicate\isOfSize; class KinderSurprise {Test extends \PHPUnit_Framework_TestCase /** @test */ public function isThreeThingsInOne() { $valueForUser = PurchaseKinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert

Slide 30

Slide 30 text

BUT WHAT ABOUT NAMING CONVENTIONS? you NAMING CONVENTIONS

Slide 31

Slide 31 text

IF YOU HAVE NAMING CONVENTIONS, FOLLOW THEM. BUT CHANGE THEM IF THEY LEAD TO INFERIOR NAMING. me NAMING CONVENTIONS

Slide 32

Slide 32 text

LEARN MORE https://skillsmatter.com/skillscasts/5747

Slide 33

Slide 33 text

MUCH MORE https://www.youtube.com/watch?v=CzJ94TMPcD8

Slide 34

Slide 34 text

FINAL TIP

Slide 35

Slide 35 text

THANK YOU. @bovigo Rate the talk! https://joind.in/talk/d12ea