$30 off During Our Annual Pro Sale. View Details »

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.

Frank Kleine

January 26, 2017
Tweet

More Decks by Frank Kleine

Other Decks in Programming

Transcript

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

    ▸ @bovigo Taken at dotGo 2016 in Paris on October 10, 2016 by Nicolas Ravelli
  2. 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
  3. 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
  4. 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
  5. IF NAMES BE NOT CORRECT, LANGUAGE IS NOT IN ACCORDANCE

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

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

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

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

    process, not a single step, by Arlo Belshee
  13. 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.
  14. 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
  15. 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
  16. 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"] }
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. IF YOU HAVE NAMING CONVENTIONS, FOLLOW THEM. BUT CHANGE THEM

    IF THEY LEAD TO INFERIOR NAMING. me NAMING CONVENTIONS