Stop wasting time through clean code#phpnw11Volker Dusch / @__edorian
So stop wasting time!Why are we here?2Introduction
Why are we hereto talk code and coding!3Introduction
});});});4Introduction
Me?5Introduction
Volker Dusch@__edorian6Introduction
PHP for around 9 years 7Introduction
I’m currently into TDD, CI, Clean Code and shipping8Introduction…amongst other stuff
9IntroductionJust go and buy those*Book covers used under fair use
            Get in touchTwitter: @__edorianXing / G+: Volker DuschStackoverflow:(visit us at http://chat.stackoverflow.com/rooms/11/phpIRC: edorianMail: php@wallbash.com10Introduction
Ask questions at any time!11IntroductionFirst question gets an elePHPantAnother question gets one too!
Why try to save time?12Motivation
Because we are professionals13Motivation
Even so our field is quite young14Motivation
Do you know how expensive it is to have you people around?15Motivation
16MotivationGerman numbers, ymmv€, £, Approx.. valuesYou get around 50k a year50.000 / YearAdding non-wage labor costs of around 60%80.000 / YearOffice space, water, hardware, coffee, plants, cleaning, drugs, travels, training100.000 / Year250 Days without weekends and holidays and your 30 holidays => 220 days455 / DayWhen working 8 hours a day55 Bucks per Hour!Your employer expects you to contribute over 100.000 Bucks in business value per year!
Wait why are we here again?17Motivation
To get things done, fast!Delivering is fun!18Motivation
Coding!19MotivationNot:Requirement engineering,
Scrum,
Kanban,
Organizational structures
Sane hardware
Sane working environments
ToolsWhat do we spent time on?20Time! It matters!
21Time! It matters!Not programmingChangingPlanningThinkingCreatingGrowing/BuildingAskingTypingReviewingReading
We spent time:22Time! It matters!Planning
Reading
Processing
Writing
Going to 10
Actual typing? Not that much23Time! It matters!Your codebase is just likethe database of a websiteRead:Write Ratio - 10:1and brains suck as caches
Goals:24Time! It matters!Cheap writesThe ability to change your software quicklyCheap readsThe ability to understand your software quicklyWrites require readsCheap reads25Time! It matters!People will read your code!again and again and again and againDoes it take 5 minutes or 2 hours to understand a module?
Why is our code hard to understand?26Clean code?Management?
Unclear requirements?
Customers?
Schedules?
Requirement changes?Because WE wrote it like that!We had our reasons but it still is our responsibility!27Clean code?
Rushing out stuff to make people happy“Well I’d go back and fix it but I can’t because $x”Is that comfortable?28Clean Code?
What we need:29Clean Code?A way to WRITE to our codebase so that we are able to keep our READ costs low!Fearing we might break something leads to us not making necessary changes
If we don‘t fix stuff we won‘t have a readable, maintainable codebaseWe need a “Pragmatic” approach for cheap writes30Pragmatic!
Pragmatic?31Pragmatic?Fast
Simple
Just get it done as fast as possible
Nobody cares how you do it
Micromanagement?‘Pragmatic’ === ‘TDD’32Pragmatic!My boss should NOT have to care about the fact that I’m writing unit tests!
If you can go faster when writing tests it is your responsibility to do that!
When not writing tests means “getting it done slower” nobody is asking you to do it!I don’t have time to sharpen my axe!There are so many trees that I need to cut down33Pragmatic!
This is not a TDD session34TDD! It saves kittens!A small TDD checklist:Write unit tests! TDD is just the fastest way.
Just do it. It’s not magic, don’t fear doing it!
Practice before you do it at work!
Tools? You don‘t need tools to get started!
watch –n1 'phpunit' and ¼ of a screen is ALL you need!Get the basics right35TDD! It saves kittens!A small TDD checklist (continued):Aim for 100% test coverage
Your tests should run REALLY fast
If you can‘t do that now use --filter
„You“ means everyone in your team!Writing unit tests is a SKILL36TDD! It saves kittens!You need to acquire it
You need to practice
It‘s just like any other tool and concept
Actually – Unit testing is really easy…
Writing testable code can be hard and NEEDS practice!Enough! Code! Now!37Enough! Code! Now!
What to focus on?Is there anything we can base our decisions on? 38Enough! Code! Now!
39I <2 off by one errors"There are only two hard problems in Computer Science: cache invalidation, naming things, and off-by-one errors.“- Phil Karlton
40Naming things!
We name everythingWe might want to get that right41Naming matters
The purpose of a name is to reveal intent42Naming matters
A good name tells you everything you need to know!43Examples!class User {	public function getId() {…}	public function getName() {…}    /** Calculate Body-Mass-Index @link … */	public function getBMI() {…}   /** @param float $kg Weight in Kilogramm */	public function setWeight($kg) {…}
You shouldn’t need comments44Code! Finally!class User {	public function getUserId() {…}	public function getFirst/Last/DisplayName() {…}    /** @link … */	public function getBodyMassIndex() {…}   /** @param float $kilogramm */	public function setWeight($kilogramm) {…}
Names already arecompliable documentation45Naming matters
Another example46Code!class Calendar {	public function getMonth($shortened = false) {…}}class Calendar {	public function getMonthNames() {…}	public function getShortendMonthNames() {…}}
Proper naming is important and easily neglectable47Names matter! A lot!Descriptive names communicate intent
They enable us to understand what‘s up
Misleading names can make it nearly impossible to navigate in a codebaseIt is easy to write code that a machine understands48Names matter! A lot!Writing code that ANOTHER human can understand is A LOT harder
Before we startnaming things49Let’s go!
50$pszError = &“E_FATAL\0“;Hungarian Notation?$aArray; $sString; $fFloat; $cCount;interface IUser {} class CUser {}For classes and interfaces we have IDEs
If you have long methods you might be interested in types 100 lines later
But that isn‘t the issue we want to adressLet’s name things!51Name everything!Namespaces
Classes
Functions
VariablesNamespaces52Name Namespaces!The things that come before the last underscore of your class name
Namespaces gave us the ability to get pretty class names
“User” vs“Framework_Util_Stuff_Foo_Auth_User”Namespaces53PSR-0The PHP world has mostly agreed that Namespaces  Directory structure
Is that a good idea?
Harder to change folder structure
Duplicate information
Just do it anyways. It’s the expected layout
It also pushes you to create modules!Classes54Classy class namesThe class name is the single most important definition of what fits into that class
Using generic names throws that away!
ApplicationManager, FrameworkDataInformationProvider, UtilityDataProcessorOne class, one purpose55Putting the “S” in “SOLID”Name it after its purpose
Single responsibility principle!
There should be only one reason to change a classProper class namesrelate to good methods56It’s good if it doesn’t fit!Think of the real world$user->getStoreDiscount() ?$userManager->getStoreDiscount(); ?Do we ask your customers how much they owe us or do we keep track of that?Proper class nameslead to smaller classes57Focus!Should we let our  Email class figure out attachment mime types?
By always asking if stuff fits we can ‘discover’ new classes in our applications
EmailAttachment, ImageEmailAttachment?And we care because?58OOP is there to help us!Big classes rob you of all OO benefits
You depend on way to much other stuff
Usually tightly coupled
You can extend from those classes and chances are you can’t swap out ether
You don’t get nice interfaces as wellA logger interface59Loggers log!interface Logger {	public function log($message);}
Composite?60Another logger interfaceinterface Logger {    public function log($logMessage);    public function setOutputFormat($format);    public function activate();    public function deactivate();    public function flush();public function setIncludeTimestamp($format);    public function addLogger(Logger $logger);}
All those rules! I want to get things done!61Rule 1: Segmentation faultThese are just guidelines
They exist to act as early warning signs
Not running into trouble two hours later can save an amazing amount of time62‘Util’ is the new ‘Manager’Util Because naming is harddjango/core/files/utils.pydjango/core/mail/utils.pydjango/db/backends/util.pydjango/db/utils.pydjango/forms/util.pydjango/http/utils.pydjango/test/utils.pydjango/utils/...           (django still rocks btw.)

Stop wasting-time-by-applying-clean-code-principles

  • 1.
    Stop wasting timethrough clean code#phpnw11Volker Dusch / @__edorian
  • 2.
    So stop wastingtime!Why are we here?2Introduction
  • 3.
    Why are wehereto talk code and coding!3Introduction
  • 4.
  • 5.
  • 6.
  • 7.
    PHP for around9 years 7Introduction
  • 8.
    I’m currently intoTDD, CI, Clean Code and shipping8Introduction…amongst other stuff
  • 9.
    9IntroductionJust go andbuy those*Book covers used under fair use
  • 10.
    Get in touchTwitter: @__edorianXing / G+: Volker DuschStackoverflow:(visit us at http://chat.stackoverflow.com/rooms/11/phpIRC: edorianMail: php@wallbash.com10Introduction
  • 11.
    Ask questions atany time!11IntroductionFirst question gets an elePHPantAnother question gets one too!
  • 12.
    Why try tosave time?12Motivation
  • 13.
    Because we areprofessionals13Motivation
  • 14.
    Even so ourfield is quite young14Motivation
  • 15.
    Do you knowhow expensive it is to have you people around?15Motivation
  • 16.
    16MotivationGerman numbers, ymmv€,£, Approx.. valuesYou get around 50k a year50.000 / YearAdding non-wage labor costs of around 60%80.000 / YearOffice space, water, hardware, coffee, plants, cleaning, drugs, travels, training100.000 / Year250 Days without weekends and holidays and your 30 holidays => 220 days455 / DayWhen working 8 hours a day55 Bucks per Hour!Your employer expects you to contribute over 100.000 Bucks in business value per year!
  • 17.
    Wait why arewe here again?17Motivation
  • 18.
    To get thingsdone, fast!Delivering is fun!18Motivation
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
    ToolsWhat do wespent time on?20Time! It matters!
  • 26.
    21Time! It matters!NotprogrammingChangingPlanningThinkingCreatingGrowing/BuildingAskingTypingReviewingReading
  • 27.
    We spent time:22Time!It matters!Planning
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
    Actual typing? Notthat much23Time! It matters!Your codebase is just likethe database of a websiteRead:Write Ratio - 10:1and brains suck as caches
  • 33.
    Goals:24Time! It matters!CheapwritesThe ability to change your software quicklyCheap readsThe ability to understand your software quicklyWrites require readsCheap reads25Time! It matters!People will read your code!again and again and again and againDoes it take 5 minutes or 2 hours to understand a module?
  • 34.
    Why is ourcode hard to understand?26Clean code?Management?
  • 35.
  • 36.
  • 37.
  • 38.
    Requirement changes?Because WEwrote it like that!We had our reasons but it still is our responsibility!27Clean code?
  • 39.
    Rushing out stuffto make people happy“Well I’d go back and fix it but I can’t because $x”Is that comfortable?28Clean Code?
  • 40.
    What we need:29CleanCode?A way to WRITE to our codebase so that we are able to keep our READ costs low!Fearing we might break something leads to us not making necessary changes
  • 41.
    If we don‘tfix stuff we won‘t have a readable, maintainable codebaseWe need a “Pragmatic” approach for cheap writes30Pragmatic!
  • 42.
  • 43.
  • 44.
    Just get itdone as fast as possible
  • 45.
  • 46.
    Micromanagement?‘Pragmatic’ === ‘TDD’32Pragmatic!Myboss should NOT have to care about the fact that I’m writing unit tests!
  • 47.
    If you cango faster when writing tests it is your responsibility to do that!
  • 48.
    When not writingtests means “getting it done slower” nobody is asking you to do it!I don’t have time to sharpen my axe!There are so many trees that I need to cut down33Pragmatic!
  • 49.
    This is nota TDD session34TDD! It saves kittens!A small TDD checklist:Write unit tests! TDD is just the fastest way.
  • 50.
    Just do it.It’s not magic, don’t fear doing it!
  • 51.
    Practice before youdo it at work!
  • 52.
    Tools? You don‘tneed tools to get started!
  • 53.
    watch –n1 'phpunit'and ¼ of a screen is ALL you need!Get the basics right35TDD! It saves kittens!A small TDD checklist (continued):Aim for 100% test coverage
  • 54.
    Your tests shouldrun REALLY fast
  • 55.
    If you can‘tdo that now use --filter
  • 56.
    „You“ means everyonein your team!Writing unit tests is a SKILL36TDD! It saves kittens!You need to acquire it
  • 57.
    You need topractice
  • 58.
    It‘s just likeany other tool and concept
  • 59.
    Actually – Unittesting is really easy…
  • 60.
    Writing testable codecan be hard and NEEDS practice!Enough! Code! Now!37Enough! Code! Now!
  • 61.
    What to focuson?Is there anything we can base our decisions on? 38Enough! Code! Now!
  • 62.
    39I <2 offby one errors"There are only two hard problems in Computer Science: cache invalidation, naming things, and off-by-one errors.“- Phil Karlton
  • 63.
  • 64.
    We name everythingWemight want to get that right41Naming matters
  • 65.
    The purpose ofa name is to reveal intent42Naming matters
  • 66.
    A good nametells you everything you need to know!43Examples!class User { public function getId() {…} public function getName() {…} /** Calculate Body-Mass-Index @link … */ public function getBMI() {…} /** @param float $kg Weight in Kilogramm */ public function setWeight($kg) {…}
  • 67.
    You shouldn’t needcomments44Code! Finally!class User { public function getUserId() {…} public function getFirst/Last/DisplayName() {…} /** @link … */ public function getBodyMassIndex() {…} /** @param float $kilogramm */ public function setWeight($kilogramm) {…}
  • 68.
    Names already arecompliabledocumentation45Naming matters
  • 69.
    Another example46Code!class Calendar{ public function getMonth($shortened = false) {…}}class Calendar { public function getMonthNames() {…} public function getShortendMonthNames() {…}}
  • 70.
    Proper naming isimportant and easily neglectable47Names matter! A lot!Descriptive names communicate intent
  • 71.
    They enable usto understand what‘s up
  • 72.
    Misleading names canmake it nearly impossible to navigate in a codebaseIt is easy to write code that a machine understands48Names matter! A lot!Writing code that ANOTHER human can understand is A LOT harder
  • 73.
    Before we startnamingthings49Let’s go!
  • 74.
    50$pszError = &“E_FATAL\0“;HungarianNotation?$aArray; $sString; $fFloat; $cCount;interface IUser {} class CUser {}For classes and interfaces we have IDEs
  • 75.
    If you havelong methods you might be interested in types 100 lines later
  • 76.
    But that isn‘tthe issue we want to adressLet’s name things!51Name everything!Namespaces
  • 77.
  • 78.
  • 79.
    VariablesNamespaces52Name Namespaces!The thingsthat come before the last underscore of your class name
  • 80.
    Namespaces gave usthe ability to get pretty class names
  • 81.
    “User” vs“Framework_Util_Stuff_Foo_Auth_User”Namespaces53PSR-0The PHPworld has mostly agreed that Namespaces  Directory structure
  • 82.
    Is that agood idea?
  • 83.
    Harder to changefolder structure
  • 84.
  • 85.
    Just do itanyways. It’s the expected layout
  • 86.
    It also pushesyou to create modules!Classes54Classy class namesThe class name is the single most important definition of what fits into that class
  • 87.
    Using generic namesthrows that away!
  • 88.
    ApplicationManager, FrameworkDataInformationProvider, UtilityDataProcessorOneclass, one purpose55Putting the “S” in “SOLID”Name it after its purpose
  • 89.
  • 90.
    There should beonly one reason to change a classProper class namesrelate to good methods56It’s good if it doesn’t fit!Think of the real world$user->getStoreDiscount() ?$userManager->getStoreDiscount(); ?Do we ask your customers how much they owe us or do we keep track of that?Proper class nameslead to smaller classes57Focus!Should we let our Email class figure out attachment mime types?
  • 91.
    By always askingif stuff fits we can ‘discover’ new classes in our applications
  • 92.
    EmailAttachment, ImageEmailAttachment?And wecare because?58OOP is there to help us!Big classes rob you of all OO benefits
  • 93.
    You depend onway to much other stuff
  • 94.
  • 95.
    You can extendfrom those classes and chances are you can’t swap out ether
  • 96.
    You don’t getnice interfaces as wellA logger interface59Loggers log!interface Logger { public function log($message);}
  • 97.
    Composite?60Another logger interfaceinterfaceLogger { public function log($logMessage); public function setOutputFormat($format); public function activate(); public function deactivate(); public function flush();public function setIncludeTimestamp($format); public function addLogger(Logger $logger);}
  • 98.
    All those rules!I want to get things done!61Rule 1: Segmentation faultThese are just guidelines
  • 99.
    They exist toact as early warning signs
  • 100.
    Not running intotrouble two hours later can save an amazing amount of time62‘Util’ is the new ‘Manager’Util Because naming is harddjango/core/files/utils.pydjango/core/mail/utils.pydjango/db/backends/util.pydjango/db/utils.pydjango/forms/util.pydjango/http/utils.pydjango/test/utils.pydjango/utils/... (django still rocks btw.)
  • 101.
    Reserved class names63Nameeverything!Some names already have meaning
  • 102.
    If you namestuff like a design pattern you’d better implement that pattern!
  • 103.
    Factory, DataMapper, Visitor,Composite, Strategy, Builder
  • 104.
    A Logger withouta log function?Functions!64Best thing since LJMPFirst unit of organization
  • 105.
    Functions are wherethe action is
  • 106.
    For a longtime functions where all we had!
  • 107.
    Calling one gotA LOT faster over the yearsFunction naming 65Starting off easyDoes it return a boolean?
  • 108.
    Call it hasXor isX66Implementation detailsHidden booleans$status = $user->getStatus();if($status == $user::STATUS_BANNED) {}if($user->isBanned()) {}
  • 109.
  • 110.
  • 111.
    Both should notmodify anything else
  • 112.
    Don’t make yoursetters into liarsSetters return null!68setTitle($this);Or maybe $this but nothing else!
  • 113.
    Return codes forugly IFs onto consumersif(!$config->set("key", "value")) {}if(!$config->has("key")) { $config->set("key", "value");}
  • 114.
    No boolean parameters69$user->setInactive(false);Ifyou don’t have a very good reason!$user->setAdminStatus(false);$user->setAdminStatus(true);vs$user->revokeAdminRights();$user->grantAdminRights();
  • 115.
    Classes are nounsFunctionsstart with verbs!70$title->show();->createStuff(); ->deleteStuff()->dispatchCall(); ->subscribeUser();But never$user->admin(); or $user->bag();$list->subscription();
  • 116.
    Agree on verbsfor actions71Don’t $dir->expunge();Can you tell me the difference between$directory->delete($entry);And$directory->remove($entry);$router->dispatch/delegate($call);$list->add/append($user);
  • 117.
    Different actions needdistinguishable names!72Name everything!Even if that makes function names longer
  • 118.
    Usually those functionsget created for “doing the same thing with different side effects but not wanting to call it that”
  • 119.
    If you canagree upon terms with your team that’s even better!Always favor longfunction names? NO!73Bigger is not always betterA short an precise public API is important
  • 120.
    But you wantlong privates$user->setUserNameOrThrowAn\ExceptionIfNotPossible();$logger->logMessageButDontDoAnything\IfYouCantWriteToTheBackend($message);Not even: $logger->logMessage($message);
  • 121.
    Public functions willbe called from many places74Bigger is not always betterThey should do one thing and maybe throw an exception if they can’t do that
  • 122.
    Precise names helpa lot to create readable client code
  • 123.
    Interally used functionscan be named as verbosely as needed to communicate their intent and behaviorReadable classes75implements humanReadableSome state
  • 124.
    Lots of smalldescripte methods
  • 125.
    Best arranged inorder of interestReadable classes?76sort($this) stuff outclass Log { private function writeToLogfile() {} private functionflushCurrentLogfileBuffer(){} public function log($message) {} private isLogfileWriteable {} public function __construct(SplFileInfo$logfile) {} private createLogfileIfNecaccary() {}}
  • 126.
  • 127.
  • 128.
  • 129.
    Most work happensin private methodsReadable classes?78sorted($this)class Log { public function __construct(SplFileInfo$logfile) {} public functionlog {} private functionisLogfileWriteable{} private function createLogfileIfNecaccary() {} private functionwriteToLogfile() {} private functionflushCurrentLogfileBuffer(){}}
  • 130.
    Maximum function length?79Nameeverything!LOC of the function body?
  • 131.
    Do you likereading functions that are:
  • 132.
  • 133.
  • 134.
    Over 7?6 Linesought to be enough for everybody?80Reading > WritingDoing only one thing shouldn’t take much space
  • 135.
    Can you splitit into 2 functions? Then do!Why long function bodies?81main::doEverything();It’s very easy to create
  • 136.
    You just haveto worry about functionality82Implements unreadableWhat is in a long function?Local variables and code that operates on thempublic function log($message) {$log = ''; $errors = array(); $log .= PHP_EOL . date('Y-m-d H:i:s') . ': '; if(!$message) { $errrors[] = 'No Message'; } else { $log .= $message; } if(!fwrite($this->log)) { $errors[] = 'Write E'; } return $errros;} // I'm really 12 lines long
  • 137.
    State and operations?83Weshall name it TimmyIt’s a class!
  • 138.
    Long functions arewhere classes hide!
  • 139.
    Even in thesmall example we could separate Log and LogFileWriterFunction overflow?84Methods everywhere!Good thing they have nice names
  • 140.
    And we wrappedthem in classes
  • 141.
    That’s good forread/write access!
  • 142.
    Calling overhead justdoesn’t matterSmaller is harder to write85Wrapping up functionsWriting ONLY small functions is a SKILL
  • 143.
    It is _easy_to write big functions!
  • 144.
    But the firstchange makes it all worth!
  • 145.
    If everything issmall it can even impact your coding standard ;) Last thing to nameVariables86We shall name it TimmyRules of thumb:
  • 146.
  • 147.
  • 148.
    Short scope: shortnameExample87We shall name it Timmyfor($i = 7; $i; --$i) { $this->doStuffToListItem($i);} vsfor($currentlistItemId = 7; $this->listItemIdIsValid($currentlistItemId); --$currentlistItemId) { $this->doStuffToListItem($currentlistItemId);}
  • 149.
    Descriptive members!88Class scopeis big scope!Members are accessed from many places. They should communicate intent!
  • 150.
    Local variables insmall classes are only used twice or thrice89Names matterWrapping up naming"A name, like an honorable human, should say what it means and mean what it says”Names are the basis of our communication!They can speed up things immensely!
  • 151.
    Arrays90Hash maps everywhere!PHPis hash-map-based programming
  • 152.
    Our constants arein hash maps
  • 153.
    Our variables arestored in hash maps
  • 154.
  • 155.
    We’d like toforeach over EVERYTHING!
  • 156.
    PHP Arrays letus create amazing data structures without much hassle91Hash maps everywhere!ArraysPHP Arrays also let us create amazingly complex and unmaintainable data structures$config['user'][$user['id']]['languages']['native'] ='en';But arrays are too way cool to not use them.Maybe we need OOP arrays?
  • 157.
    Value objects!92New themeverywhere!OOP Data structure
  • 158.
    You can createthem everywhere, no DI!
  • 159.
    Identity is basedon state! Think dates
  • 160.
    Lots of gettersand setters. If you really miss arrays you can implement ArrayAccess too
  • 161.
  • 162.
    Implement IteratorAggregate andyou get foreach back!Value objects!93New them everywhere!class List implementsIteratorAggregate, Countable {protected $list= array();publicfunctionadd($item) { $this->list[] = $item; }publicfunctioncount() { returncount($this->list); }publicfunctionremove($index) { if(!isset($this->list[$index])) {/* throw ... */ }unset($this->list[$index]); $this->list = array_merge($this->list); }publicfunctiongetIterator { returnnewArrayIterator($this->list); }}
  • 163.
    Value objects!94New themeverywhere!classMonthlyValuesimplementsIteratorAggregate {protected $values = array();publicfunction __construct(array $values) {if(count($values) != 12) {thrownnewInvalidArgumentException('...'); } $this->values = $values; }publicfunctionget($monthNumber) {return $this->values[$monthNumber]; } // ... publicfunctiongetIterator() ...
  • 164.
    Comments95New them everywhere!I’vespend a lot of time ranting about comments. Name things properly!
  • 165.
  • 166.
  • 167.
    http://www.slideshare.net/Edorian/php-unconference-europa-clean-code-stop-wasting-my-time96Find the methodbodyabstract class xyzRequest { /** * Initializes this xyzRequest. * * Available options: * * * logging: Whether to enable logging or not (false by default) * * @param xyzEventDispatcher $dispatcher An xyzEventDispatcher instance * @param array $parameters An associative array of initialization parameters * @param array $attributes An associative array of initialization attributes * @param array $options An associative array of options * * @return bool true, if initialization completes successfully, otherwise false * * @throws <b>xyzInitializationException</b> If an error occurs while initializing this xyzRequest */ public function initialize(xyzEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) {
  • 168.
    97Name everything!Error handlingIsa big topic that requires a whole session
  • 169.
    Just use exceptionsin favor of return codes
  • 170.
    Don‘t force IFstatements in client code$stuff = $factory->create('unkownStuff');$stuff->doWork(); // E_FATAL?Enable consumers to handle errors at a point of their choosing!Professionals deliver!98Wrapping upTesting makes you FASTER!
  • 171.
  • 172.
    Only tested codecan stay clean
  • 173.
    You can onlyfix what you can reproduce!
  • 174.
    JUST – DO– IT! YOU – ARE – IN – CHARGE!99Thanks a lot!Thank you for your time!Slides will be at: http://joind.in/3600the link will be at @__edorian too ;)Please leave me feedback!
  • 175.
    Recommended Reads100Rate mytalk please!Clean CodeManagementProfessionalism^ Best book in 2011 ^In my humble opinion*Book covers used under fair useMore:https://www.google.com/bookmarks/l#!threadID=GU46RJYjEsMU%2FBDcqV3woQ8eH4sOcl