A little theory about naming @ PHPUGKA

A little theory about naming @ PHPUGKA

Wie wir alle wissen ist Naming eines der schwersten Probleme in der Softwareentwicklung. Wir schauen uns an warum Naming wichtig ist, was Persönlichkeiten aus der Zeit vor der Softwareentwicklung darüber sagten, wie wir unsere eigenen Naming-Fähigkeiten weiterentwickeln können, und natürlich Beispiele für gutes und schlechtes Naming. Aber Achtung: einige der vorgestellten Dinge könnten gegen Deine Ansichten verstoßen, insbesondere im Hinblick auf die im PHP-Umfeld üblichen Namenswahlen. Das aber lässt Freiraum zur Diskussion und Reflexion über häufig genutzte Namen.

Dd04c77354394458bbd4afd64bf7e8b3?s=128

Frank Kleine

January 26, 2017
Tweet

Transcript

  1. NAMING A LITTLE THEORY ABOUT

  2. HELLO AGAIN FRANK KLEINE ▸ Software Architect at 1&1 Internet

    ▸ @bovigo Taken at dotGo 2016 in Paris on October 10, 2016 by Nicolas Ravelli
  3. EXAMPLE WTF? CONTAINER? MANAGER? Code snippet: Laravel Capsule for buildung

    SQL queries by @SenseException
  4. 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
  5. 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
  6. 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
  7. IF NAMES BE NOT CORRECT, LANGUAGE IS NOT IN ACCORDANCE

    WITH THE TRUTH OF THINGS. Confucius IMPORTANCE From: The Analects of Confucius
  8. 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
  9. PRODUCT THE CODE IS YOUR PRODUCT API classes & interfaces

    & methods functions constants & variables
  10. 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
  11. NAMES: ASAP* *As Specific As Possible

  12. KEY STEPS Learn and understand the domain Rename things Use

    a thesaurus Rename things Learn and understand the domain Rename things
  13. 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
  14. NAMES ARE NOT ALWAYS WHAT THEY SEEM. Mark Twain ITERATE

    From: Following the Equator: A Journey Around the World
  15. THE 7 STAGES OF NAMING From: Good naming is a

    process, not a single step, by Arlo Belshee
  16. MEASURE ARE DOMAIN KEYWORDS RECOGNIZABLE?

  17. VFSSTREAM

  18. BOVIGO/ASSERT

  19. BITEXPERT/DISCO

  20. 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.
  21. BE PRECISE ELIMINATE UNNECESSARY NOISE SubscriptionsService ConnectionFailureException RequestInterface getVvalue()

  22. 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
  23. 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
  24. 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"] }
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. BUT WHAT ABOUT NAMING CONVENTIONS? you NAMING CONVENTIONS

  31. IF YOU HAVE NAMING CONVENTIONS, FOLLOW THEM. BUT CHANGE THEM

    IF THEY LEAD TO INFERIOR NAMING. me NAMING CONVENTIONS
  32. LEARN MORE https://skillsmatter.com/skillscasts/5747

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

  34. FINAL TIP

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