Ein wenig Theorie über Naming @ PHPUGMRN V/2016

Ein wenig Theorie über Naming @ PHPUGMRN V/2016

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

October 27, 2016
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 Code snippet: Laravel Capsule for buildung SQL queries by

    @SenseException
  4. EXAMPLE CONTAINER? Code snippet: Laravel Capsule for buildung SQL queries

    by @SenseException
  5. EXAMPLE CONTAINER? MANAGER? Code snippet: Laravel Capsule for buildung SQL

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

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

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

    & methods functions constants & variables
  13. 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
  14. KEY STEPS Learn and understand the domain Rename things Use

    a thesaurus Rename things Learn and understand the domain Rename things
  15. NAMES ARE NOT ALWAYS WHAT THEY SEEM. Mark Twain ITERATE

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

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

  18. VFSSTREAM

  19. None
  20. BOVIGO/ASSERT

  21. BITEXPERT/DISCO

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

  25. 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
  26. 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
  27. 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"] }
  28. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert
  29. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert
  30. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert
  31. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert
  32. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert THERE’S NO NEED FOR THAT EXCEPT THAT THE TEST FRAMEWORK REQUIRES IT
  33. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert THERE’S NO NEED FOR THAT EXCEPT THAT THE TEST FRAMEWORK REQUIRES IT
  34. 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 = KinderSurprise(); assert($valueForUser, isOfSize(3)); } } bovigo/assert
  35. BUT WHAT ABOUT NAMING CONVENTIONS? you NAMING CONVENTIONS

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

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

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

  39. THANK YOU. @bovigo