Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nomen est Omen - Naming things considered hard

Nomen est Omen - Naming things considered hard

About creating meaning by giving a thing a context.
@ Berlin PHP UG, September 2014

5fcfa864ae04004e92416a5ea05d5ffa?s=128

Anne-Julia Seitz

September 02, 2014
Tweet

Transcript

  1. NOMEN EST OMEN NAMING THINGS CONSIDERED HARD SEPTEMBER 2014 BEPHPUG

  2. WHO AM I ? Anne-Julia Scheuermann Born & raised in

    Berlin Still living in Berlin on github.com on twitter dazz when on board of c-base dazz @dazzlog
  3. WHAT I DO ALL DAY ? Like doing things SOLID.

    Naming things (mostly PHP) for over ten years now Have seen much of what I will show in a few minutes Application architecture & development for Imagine Easy Solutions Being part of Imagine Easy Solutions is awesome !
  4. WHY ARE WE NAMING THINGS ?

  5. CONTEXT ?

  6. THING + CONTEXT = MEANING

  7. DOES IT MATTER ?

  8. YES !

  9. SOME GUIDLINES TO FOLLOW

  10. AVD ABBRVTN. BAD: S r v M g r I

    n s t a n c e D e s c r i p t o r F a c t o r y $ c t r l , $ c t r $ t m p l $ l i s t - > s r t ( ) ; GOOD: I m p l e m e n t a t i o n $ c o n t r o l l e r $ t e m p l a t e $ l i s t - > s o r t ( )
  11. N U L L WORDS BAD: C o n n

    e c t i o n M a n a g e r , X m l H e l p e r O b j e c t D a t a H a n d l e r M a n a g e r B u i l d e r H e l p e r F a c t o r y $ t m p , $ t e m p , $ d a t a , $ v a r , $ a r r a y , $ k e y , . . . GOOD: C o n n e c t i o n X m l D o c u m e n t , X m l N o d e , e t c .
  12. LEGACY BAD: N e w H a n d l

    e r $ o b j - > b u i l d C o n t e x t F a s t e r ( ) ; GOOD: delete old code !!1!11
  13. NON-ENGLISH BAD: $ m e i n O b s

    t = " A p f e l ; H i m b e e r e ; T r a u b e " ; $ m e i n G e t e i l t e s O b s t = e x p l o d e ( " ; " , $ m e i n O b s t ) ; GOOD: O n l y ( a m e r i c a n ) e n g l i s h w i t h o u t e x c e p t i o n s ! e i n s ! e l f ! ! !
  14. UNICODE BAD: क = 1 ; कु ल = 0

    ; जब तक क छोटा है 1 0 से { कु ल + = क; } छापो कु ल; ALSO BAD: p u b l i c e n u m Т о в а р ы { Т е т р а д и = 2 , К а р а н д а ш и = 4 , В с ё = Т е т р а д и | К а р а н д а ш и }
  15. UNICODE FUNNY, EH?

  16. 1337 SP34K BAD: U b e r C o n

    t r o l l e r $ o b j - > k 1 l l 4 l l 3 n 3 m i 3 s ( ) ; $ n u m b 3 r GOOD: O n l y e n g l i s h w i t h o u t e x c e p t i o n s ! 1 ! 1 1 ! ! !
  17. SWEARING BAD: $ f u c k Y o u

    I d $ c o n t r o l l e r - > h e l l N o ( ) ; GOOD: / / n o t e v e n i n y o u r d a m n c o m m e n t s
  18. VARIABLES

  19. INCREMENTATION BAD: $ l i s t O n e

    $ k e y 2 GOOD: $ r o o m L i s t $ r o o m N a m e $ r o o m
  20. SINGLE CHARACTER BAD: $ w $ t $ f OK:

    $ i / / i n f o r - l o o p s $ j / / g n a . . . t h i s l e a d s t o n o g o o d
  21. FUNCTIONS

  22. SHORT BAD: $ l i s t - > g

    e t N u m b e r O f I t e m s ( ) ; GOOD: $ l i s t - > c o u n t ( ) ;
  23. TOO SHORT BAD: $ l i s t - >

    v e r i f y ( ) ; GOOD: $ l i s t - > c o n t a i n s N u l l ( ) ;
  24. USING VERBS BAD: $ l i s t - >

    r e f C o u n t ( ) ; GOOD: $ l i s t - > c l e a r ( ) ; $ l i s t - > s o r t ( ) ; $ o b j - > a d d R e f e r e n c e ( ) ;
  25. QUESTIONS FOR BOOLEAN BAD: $ l i s t -

    > e m p t y ( ) ; GOOD: $ l i s t - > i s E m p t y ( ) ; $ l i s t - > c o n t a i n s ( $ i t e m ) ;
  26. REDUNDENCY WITH ARGUMENT BAD: $ l i s t -

    > a d d I t e m ( $ i t e m ) ; $ h a n d l e r - > r e c e i v e M e s s a g e ( $ m e s s a g e ) ; GOOD: $ l i s t - > a d d ( $ i t e m ) ; $ h a n d l e r - > r e c e i v e ( $ m e s s a g e ) ;
  27. REDUNDENCY WITH RECEIVER BAD: $ l i s t -

    > a d d T o L i s t ( $ i t e m ) ; GOOD: $ l i s t - > a d d ( $ i t e m ) ;
  28. NO “AND” OR “OR” BAD: $ m a i l

    - > v e r i f y A d d r e s s A n d S e n d S t a t u s ( ) ; GOOD: $ m a i l - > v e r i f y A d d r e s s ( ) ; $ m a i l - > s e n d S t a t u s ( ) ;
  29. CLASSES

  30. NOUN PHRASE BAD: H a p p y GOOD: H

    a p p i n e s s
  31. NAMESPACES BAD: S y s t e m O n

    l i n e M e s s a g e GOOD: S y s t e m \ O n l i n e \ M e s s a g e
  32. CONCLUSION

  33. Once I’m happy with the names, I’m usually happy with

    the design.
  34. WHEN NOTHING FEELS RIGHT ...

  35. I DO Ask what is it supposed to do Find

    out more about the business domain Ask a collegue how he thinks it could be called Look on GitHub for similar code Decide that obvious is best
  36. NOUN + VERB + ( “ER” | “OR” )

  37. EXAMPLES C o n f i g u r a

    t i o n B u i l d e r Q u e r y D u m p e r R o u t i n g S t a t e P r e s e n t e r F o r m D e c o r a t o r
  38. NOUNS Attribute, Base, Bridge, Bucket, Chain, Collection, Configuration, Context, Command,

    Composite, Element, Entity, Exception, Field, Flag, Flyweight, Identity, Info, Item, Key, Method, Node, Null Object, Option, Proxy, Protocol, Peer, Query Record, Service, Strategy, Style, State, Target, Template Method, Type, Unit
  39. VERBS Adapter, Adjuster, Attacher, Binder, Builder, Calculator, Coordinator, Container, Converter,

    Controller, Connector, Collector, Configurer, Constructor, Composer, Commander, Creater, Debugger, Decorator, Decider, Designer, Delegator, Destroyer, Dispatcher, Dumper, Editor, Executor, Exporter, Extractor, Factory, Filter, Formatter, Generator, Handler, Initializer, Identifier, Interpreter, Inserter, Informer, Importer, Iterator, Listener, Limiter, Machine, Marker, Mediator, Memento, Matcher, Mapper, Messenger, Mover, Observer, Parser, Presenter, Provider, Preparer, Printer, Processor, Receiver, Reader, Recorder, Remover, Resolver, Sanitizer, Selector, Scheduler, Sender, Serializer, Sorter, Standardizer, Supporter, Synchronizer, Tokenizer, Tracer, Tracker, Validator, Viewer, Visitor, Writer
  40. THANK YOU !

  41. QUESTIONS ?

  42. SOURCES journal.stuffwithstuff.com github.com/AndrewVos/github-statistics programmers.stackexchange.com globalnerdy.com