SlideShare a Scribd company logo
1 of 31
CLEAN CODE: STOP WASTEING MY TIME
Aboutme Volker Dusch / @__edorian Doing PHP for ~7 Years now I‘m sorry for the bullet points, i don‘t know any better. 	(There will be code, and cake, maybe) Feel free to interrupt me at any time !
Aboutyou You seem to be smarty people I guess you are motivated And I'm just going to assume you work with smart people you respect
This is about time About your time About my time About the next guys time
So stop wasting time Take more time writing code, you are only doing it once Make everyone waste less time reading code, that happens quite a lot Disclaimer: When saying ‘documentation‘ inever talk about @phpdoc for apis (@param, @return)
Oh yeah by that way I won’t be talking about ’design’ very much Bad design hurts… but you’ll get over it … or at least used to it Bad code hurts every day because it sucks differently every time
Samples are next Stuff I’d say you all know about: SCM Unit testing Dependency Injection That Singletons / Statics / Globals are evil Other design mumbo jumbo
Yay ! Samples	 class myClass {     /**      * Constructor      */     public function __construct() {     }     // methods...  }
Yay ! Samples	 class myClass {     /**      * Create an instance of ‘myClass’      */     public function __construct() {     }     // methods...  }
Yay ! Samples	 class myClass {     /**      * @return myClass      */     public function __construct() {     }     // methods...  }
Yay ! Samples	 class myClass {     public function __construct() {     }     // methods...  }
Yay ! Samples	 class myClass {     // methods...  }
So…	 But everything has to have a docblock ! It‘s in the guidelines ! But i might need it later ! That's just because it‘s in the template and i didn‘t delete it
DOCUMENT EVERYTHING !!1	 That's at least what they told me Provocation incoming: Good code is hard document  Bad code is easy to document
‘Bad‘ Code 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($weightInKg) {…}
‘Good‘ Code class user { 	public function getUserId() {…} 	public function getFirst/Last/DisplayName() {…}     /** @link … */ 	public function getBodyMassIndex() {…}    /** @param float $kilogramm */ 	public function setWeight($kilogramm) {…}
Again A short, undescriptive, function name like ‘calc‘ always make it easy to write documentation Sadly people will need to read it (again and again ..)
Another little example class foo { 	/** 	 * Setter forproperty x 	 * @paramstring $x      */ 	public function setX($x) { 		$this->x = $x; 	} } Why ? ,[object Object]
Consistency ?
Improved readability through uniformity ?,[object Object]
This is PHP_CodeSniffer valid  Well… after our Doc Prepare <?php class myClass { } Yes that breaks your IDEs sniffs
Output <?php /**  * @package module_x  * @subpackage y_z */ /**  * @package module_x   * @subpackage y_z  * @since creation_date  * @version 1.2.3.4 */ class myClass { }
Inline Comments $i++ // Increment $i by one Yeah.. we don‘t need to talk about that Can be great, especially when they tell you ‘WHY‘ something was done Most time aren‘t that great
Inline Sample public function generateReport() {   // get the db connection   $reg = GlobalStorage::get(“db“);   // auth   if(!$reg->getOne(“SELECT VIEW_REPORT FROM USER ….“)) {…}   $id = $reg->getOne(“select … „); // template   // render   new ReportTemplate($id); // ….
Inline Sample public function generateReport() {   $this->checkAuthentication();   $template = this->createReportTemplate();   $this->renderReport($template); } That's not perfect but the ‘// next block‘ comments are gone
No docs are not the answer I‘m not saying BE GONE all documentation Let‘s remove useless comments ! Let‘s (maybe ?) agree upon that sometimes there is no USEFULL comment. Know who you write docs for
It‘s not ONLY about the code Commit messages matter ! Commit message are like book covers, they raise expectations. The diff should tell a matching story  Don’t repeat the obvious, tell why you did it and then show me how in the diff
Commits Yes, this highly depends on your team Fixes #5232 Fixes #4523 with the last release the database structure changed Reworked the Authentication to account for the new SingleSignOn Fixed some problems Tidy | phpdoc | cleanup | etc.
One Commit – One Purpose Stuff you can do: Fix a bug Implement a feature Refractor something Tidy up some code ,[object Object]
More than one of the above at once,[object Object]
ANY MORE QUESTIONS OR COMMENTS ?

More Related Content

What's hot

Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101Nando Vieira
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Aaron Gustafson
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second LanguageRob Dunn
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Mir Nazim
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practicesSultan Khan
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryRefresh Events
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)Rajat Pratap Singh
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Jaroslaw Palka
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMarlon Jamera
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereLaurence Svekis ✔
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
Introduction to Javascript programming
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programmingFulvio Corno
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Programmers slang
Programmers slangProgrammers slang
Programmers slangbocribbz
 
Test automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubinTest automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubinOren Rubin
 

What's hot (20)

Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
Metaprogramming with javascript
Metaprogramming with javascriptMetaprogramming with javascript
Metaprogramming with javascript
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Clean Code
Clean CodeClean Code
Clean Code
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Introduction to Javascript programming
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programming
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Programmers slang
Programmers slangProgrammers slang
Programmers slang
 
Test automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubinTest automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubin
 

Viewers also liked

Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesEdorian
 
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Theo Jungeblut
 
Clean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampClean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampTheo Jungeblut
 
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersAccidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersTheo Jungeblut
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipTheo Jungeblut
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency InjectionTheo Jungeblut
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
Regulations, Acts, and everything else you need to know about payroll legisla...
Regulations, Acts, and everything else you need to know about payroll legisla...Regulations, Acts, and everything else you need to know about payroll legisla...
Regulations, Acts, and everything else you need to know about payroll legisla...Softworld
 
Clean code is not the goal - working software is
Clean code is not the goal - working software isClean code is not the goal - working software is
Clean code is not the goal - working software isEdorian
 
Facebook apresentação monkey business
Facebook  apresentação  monkey businessFacebook  apresentação  monkey business
Facebook apresentação monkey businessLucio Uberdan
 
Expotacuaral09
Expotacuaral09Expotacuaral09
Expotacuaral09TACUARAL
 
What to look for in a hosted supplier
What to look for in a hosted supplierWhat to look for in a hosted supplier
What to look for in a hosted supplierSoftworld
 
The Good/Bad of Power Point
The Good/Bad of Power PointThe Good/Bad of Power Point
The Good/Bad of Power PointGregg Martinson
 

Viewers also liked (20)

Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
Clean code
Clean codeClean code
Clean code
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
 
Clean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code CampClean Code Part I - Design Patterns at SoCal Code Camp
Clean Code Part I - Design Patterns at SoCal Code Camp
 
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering ManagersAccidentally Manager – A Survival Guide for First-Time Engineering Managers
Accidentally Manager – A Survival Guide for First-Time Engineering Managers
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean Code
Clean CodeClean Code
Clean Code
 
Regulations, Acts, and everything else you need to know about payroll legisla...
Regulations, Acts, and everything else you need to know about payroll legisla...Regulations, Acts, and everything else you need to know about payroll legisla...
Regulations, Acts, and everything else you need to know about payroll legisla...
 
Clean code is not the goal - working software is
Clean code is not the goal - working software isClean code is not the goal - working software is
Clean code is not the goal - working software is
 
Enfermedad de chagas
Enfermedad de chagasEnfermedad de chagas
Enfermedad de chagas
 
Shoham main projects 2010
Shoham main projects 2010Shoham main projects 2010
Shoham main projects 2010
 
Distance Learning P G D B A From M I T Pune
Distance Learning  P G D B A From  M I T  PuneDistance Learning  P G D B A From  M I T  Pune
Distance Learning P G D B A From M I T Pune
 
Facebook apresentação monkey business
Facebook  apresentação  monkey businessFacebook  apresentação  monkey business
Facebook apresentação monkey business
 
Expotacuaral09
Expotacuaral09Expotacuaral09
Expotacuaral09
 
What to look for in a hosted supplier
What to look for in a hosted supplierWhat to look for in a hosted supplier
What to look for in a hosted supplier
 
The Good/Bad of Power Point
The Good/Bad of Power PointThe Good/Bad of Power Point
The Good/Bad of Power Point
 

Similar to Clean Code: Stop wasting my time

CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mindciconf
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principlesEdorian
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
How to improve the quality of your TYPO3 extensions
How to improve the quality of your TYPO3 extensionsHow to improve the quality of your TYPO3 extensions
How to improve the quality of your TYPO3 extensionsChristian Trabold
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Christos Manios
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014Matthias Noback
 
The Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitThe Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitStephen Scaffidi
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?devObjective
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014Matthias Noback
 
The Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumThe Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumMatthias Noback
 
The Naked Bundle - Symfony Barcelona
The Naked Bundle - Symfony BarcelonaThe Naked Bundle - Symfony Barcelona
The Naked Bundle - Symfony BarcelonaMatthias Noback
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 
php unconference Europa: Clean code - Stop wasting my time
php unconference Europa: Clean code - Stop wasting my timephp unconference Europa: Clean code - Stop wasting my time
php unconference Europa: Clean code - Stop wasting my timeEdorian
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - TryoutMatthias Noback
 

Similar to Clean Code: Stop wasting my time (20)

Good Coding Practices with JavaScript
Good Coding Practices with JavaScriptGood Coding Practices with JavaScript
Good Coding Practices with JavaScript
 
CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mind
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
How to improve the quality of your TYPO3 extensions
How to improve the quality of your TYPO3 extensionsHow to improve the quality of your TYPO3 extensions
How to improve the quality of your TYPO3 extensions
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
The Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitThe Essential Perl Hacker's Toolkit
The Essential Perl Hacker's Toolkit
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
The Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup BelgiumThe Naked Bundle - Symfony Usergroup Belgium
The Naked Bundle - Symfony Usergroup Belgium
 
The Naked Bundle - Symfony Barcelona
The Naked Bundle - Symfony BarcelonaThe Naked Bundle - Symfony Barcelona
The Naked Bundle - Symfony Barcelona
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
php unconference Europa: Clean code - Stop wasting my time
php unconference Europa: Clean code - Stop wasting my timephp unconference Europa: Clean code - Stop wasting my time
php unconference Europa: Clean code - Stop wasting my time
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
OOP
OOPOOP
OOP
 
The Naked Bundle - Tryout
The Naked Bundle - TryoutThe Naked Bundle - Tryout
The Naked Bundle - Tryout
 

More from Edorian

Your (coding) standards matter
Your (coding) standards matterYour (coding) standards matter
Your (coding) standards matterEdorian
 
Nginx - The webserver you might actually like
Nginx - The webserver you might actually likeNginx - The webserver you might actually like
Nginx - The webserver you might actually likeEdorian
 
From dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneFrom dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneEdorian
 
Code review in practice
Code review in practiceCode review in practice
Code review in practiceEdorian
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best PracticesEdorian
 
Nginx & php fpm - the webserver you might actually like - php usergroup berlin
Nginx & php fpm - the webserver you might actually like - php usergroup berlinNginx & php fpm - the webserver you might actually like - php usergroup berlin
Nginx & php fpm - the webserver you might actually like - php usergroup berlinEdorian
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnitEdorian
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnitEdorian
 
Nginx The webserver you might actually like
Nginx   The webserver you might actually likeNginx   The webserver you might actually like
Nginx The webserver you might actually likeEdorian
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnitEdorian
 

More from Edorian (10)

Your (coding) standards matter
Your (coding) standards matterYour (coding) standards matter
Your (coding) standards matter
 
Nginx - The webserver you might actually like
Nginx - The webserver you might actually likeNginx - The webserver you might actually like
Nginx - The webserver you might actually like
 
From dev to ops and beyond - getting it done
From dev to ops and beyond - getting it doneFrom dev to ops and beyond - getting it done
From dev to ops and beyond - getting it done
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Nginx & php fpm - the webserver you might actually like - php usergroup berlin
Nginx & php fpm - the webserver you might actually like - php usergroup berlinNginx & php fpm - the webserver you might actually like - php usergroup berlin
Nginx & php fpm - the webserver you might actually like - php usergroup berlin
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
Nginx The webserver you might actually like
Nginx   The webserver you might actually likeNginx   The webserver you might actually like
Nginx The webserver you might actually like
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

Clean Code: Stop wasting my time

  • 1. CLEAN CODE: STOP WASTEING MY TIME
  • 2. Aboutme Volker Dusch / @__edorian Doing PHP for ~7 Years now I‘m sorry for the bullet points, i don‘t know any better. (There will be code, and cake, maybe) Feel free to interrupt me at any time !
  • 3. Aboutyou You seem to be smarty people I guess you are motivated And I'm just going to assume you work with smart people you respect
  • 4. This is about time About your time About my time About the next guys time
  • 5. So stop wasting time Take more time writing code, you are only doing it once Make everyone waste less time reading code, that happens quite a lot Disclaimer: When saying ‘documentation‘ inever talk about @phpdoc for apis (@param, @return)
  • 6. Oh yeah by that way I won’t be talking about ’design’ very much Bad design hurts… but you’ll get over it … or at least used to it Bad code hurts every day because it sucks differently every time
  • 7. Samples are next Stuff I’d say you all know about: SCM Unit testing Dependency Injection That Singletons / Statics / Globals are evil Other design mumbo jumbo
  • 8. Yay ! Samples class myClass { /** * Constructor */ public function __construct() { } // methods... }
  • 9. Yay ! Samples class myClass { /** * Create an instance of ‘myClass’ */ public function __construct() { } // methods... }
  • 10. Yay ! Samples class myClass { /** * @return myClass */ public function __construct() { } // methods... }
  • 11. Yay ! Samples class myClass { public function __construct() { } // methods... }
  • 12. Yay ! Samples class myClass { // methods... }
  • 13. So… But everything has to have a docblock ! It‘s in the guidelines ! But i might need it later ! That's just because it‘s in the template and i didn‘t delete it
  • 14. DOCUMENT EVERYTHING !!1 That's at least what they told me Provocation incoming: Good code is hard document Bad code is easy to document
  • 15. ‘Bad‘ Code 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($weightInKg) {…}
  • 16. ‘Good‘ Code class user { public function getUserId() {…} public function getFirst/Last/DisplayName() {…} /** @link … */ public function getBodyMassIndex() {…} /** @param float $kilogramm */ public function setWeight($kilogramm) {…}
  • 17. Again A short, undescriptive, function name like ‘calc‘ always make it easy to write documentation Sadly people will need to read it (again and again ..)
  • 18.
  • 20.
  • 21. This is PHP_CodeSniffer valid Well… after our Doc Prepare <?php class myClass { } Yes that breaks your IDEs sniffs
  • 22. Output <?php /** * @package module_x * @subpackage y_z */ /** * @package module_x * @subpackage y_z * @since creation_date * @version 1.2.3.4 */ class myClass { }
  • 23. Inline Comments $i++ // Increment $i by one Yeah.. we don‘t need to talk about that Can be great, especially when they tell you ‘WHY‘ something was done Most time aren‘t that great
  • 24. Inline Sample public function generateReport() { // get the db connection $reg = GlobalStorage::get(“db“); // auth if(!$reg->getOne(“SELECT VIEW_REPORT FROM USER ….“)) {…} $id = $reg->getOne(“select … „); // template // render new ReportTemplate($id); // ….
  • 25. Inline Sample public function generateReport() { $this->checkAuthentication(); $template = this->createReportTemplate(); $this->renderReport($template); } That's not perfect but the ‘// next block‘ comments are gone
  • 26. No docs are not the answer I‘m not saying BE GONE all documentation Let‘s remove useless comments ! Let‘s (maybe ?) agree upon that sometimes there is no USEFULL comment. Know who you write docs for
  • 27. It‘s not ONLY about the code Commit messages matter ! Commit message are like book covers, they raise expectations. The diff should tell a matching story Don’t repeat the obvious, tell why you did it and then show me how in the diff
  • 28. Commits Yes, this highly depends on your team Fixes #5232 Fixes #4523 with the last release the database structure changed Reworked the Authentication to account for the new SingleSignOn Fixed some problems Tidy | phpdoc | cleanup | etc.
  • 29.
  • 30.
  • 31. ANY MORE QUESTIONS OR COMMENTS ?
  • 32. THANK YOU FOR YOUR TIME