SlideShare a Scribd company logo
Clean code:Stop wasting my time February 17, 2011 1
About me Volker Dusch / @__edorian Doing PHP for ~8 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! February 17, 2011 2
About you You seem to be smart people I guess you are motivated And I’m just going to assume that you work with smart people you respect February 17, 2011 3
This talk is about time About your time About my time About the next guys time February 17, 2011 4
So stop wasting time Don’t make me spend time trying to figure out what you are doing Don’t spend your own time writing stuff that isn’t going to help me anyways A little disclaimer: When I talk about ‘documentation’ I don’t mean @phpdoc tags for api docs (@param & @return) February 17, 2011 5
What I would talk about Good documentation means less documentation How does that work for your team Commit messages I LIKE to read Everything related you want to discussIf we don’t make it through the slides I’m happy February 17, 2011 6
Stuff you all know about SCM Unit testing Dependency Injection Why we don’t like singletons / static functions and other globals Other design mumbo jumbo If not: Read up on it. There are great resources out there February 17, 2011 7
Yay! Samples class myClass {     /**      * Constructor      */     public function __construct() {     }     // methods...  } February 17, 2011 8
Yay! Samples class myClass {     /**      * Create an instance of ‘myClass’      */     public function __construct() {     }     // methods...  } February 17, 2011 9
Yay! Samples class myClass {     /**      * @returnmyClass      */     public function __construct() {     }     // methods...  } February 17, 2011 10
Yay! Samples class myClass{     public function __construct() {     }     // methods...  } February 17, 2011 11
Yay! Samples class myClass{     // methods...  } February 17, 2011 12
So… Seems mundane? That stuff scales! But everything needs to have a docblock! But I might need it later That‘s just because it‘s in the template and I didn‘t delete it February 17, 2011 13
DOCUMENT EVERYTHING !!1eleven February 17, 2011 14 At least that’s what they told me How about that: 	Good code is hard to document 	Bad code is easy to document I prefer good code over a lot of docs
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) {…} February 17, 2011 15
Bettercode class user { 	public function getUserId() {…} 	public function getFirst/Last/DisplayName() {…}     /** @link … */ 	public function getBodyMassIndex() {…}    /** @param float $kilogramm */ 	public function setWeight($kilogramm) {…} February 17, 2011 16
Again Short and undescriptive function names make it very easy to write documentation Good ones make it hard to write meaningful stuff Sadly people will need to read your docs again and again and again February 17, 2011 17
Meaningful ? A small example February 17, 2011 18 class foo { 	/** 	 * Setter forproperty x 	 * @param string $x      */ 	public function setX($x) { 		$this->x = $x; 	} } Why ? ,[object Object]
Consistency ?
Improved readability through uniformity ?,[object Object]
Output – It‘s like autoloading <?php /**  * @package module_x  * @subpackage y_z  */ /**  * @package module_x   * @subpackage y_z  * @since creation_date  * @version 1.2.3.4  */ class myClass { } February 17, 2011 20
Know your user or coworker February 17, 2011 21
This is phpdoc &phpcs valid Well… after the build script <?php class myClass { } *You might need 2 phpcs standards? February 17, 2011 22
A final test See if you can spot the issues Or just guess what I‘d complain about February 17, 2011 23
February 17, 2011 24 abstract 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()) {
Another one? /** * Retrieves the uniform resource identifier for the current web request. * * @return string Unified resource identifier */ publicfunctiongetUri() /** * See if the client is using absolute uri * * @return boolean true, if is absolute uri otherwise false */ publicfunctionisAbsUri() February 17, 2011 25
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 February 17, 2011 26
Inline Sample public function generateReport() {   // get the db connection   $reg = GlobalStorage::get(“db“);   // auth   if(!$reg->getOne(“SELECT view_report FROM USER ….“)) {…}   // template   $id = $reg->getOne(“select … „);    // render   new ReportTemplate($id); // …. February 17, 2011 27
Inline Sample public function generateReport() {   $this->checkAuthentication();   $template = this->createReportTemplate();   $this->renderReport($template); } That's not perfect but the ‘// next block‘ comments are gone February 17, 2011 28
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 USEFUL comment. Know who you write docs for February 17, 2011 29
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 February 17, 2011 30
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. February 17, 2011 31
Git made this worse More smaller commits tend to make people just describe what they do and not why they did it Delete Tweak output Rename variable Add cacheTokensattribute Moved code from A to B February 17, 2011 32
To sum up Don’t write documentation you think has no use See if you can substitute documentation with more descriptive naming Always: Do what your team has agreed upon and if you don’t like it try to change it if there is a benefit others see too. February 17, 2011 33
Comments?Questions! Anything else? 34 Volker Dusch  @__edorian

More Related Content

Viewers also liked

Mit pune e prospectus
Mit pune e prospectusMit pune e prospectus
Mit pune e prospectus
MIT School oF distance education
 
Restorative practices at rahs -update board
Restorative practices at rahs -update boardRestorative practices at rahs -update board
Restorative practices at rahs -update board
Gregg Martinson
 
Online distance PG Diploma courses from MIT Pune
Online distance PG Diploma courses from MIT PuneOnline distance PG Diploma courses from MIT Pune
Online distance PG Diploma courses from MIT Pune
MIT School oF distance education
 
компьютерная мышь
компьютерная мышькомпьютерная мышь
компьютерная мышьyolkina548
 
Wordpress install setup
Wordpress install setupWordpress install setup
Wordpress install setup
Mohammed Nayeem
 
2118 F I N A L With Bg 2
2118  F I N A L With Bg 22118  F I N A L With Bg 2
2118 F I N A L With Bg 2
2118tibet
 
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
 
HMRC Update
HMRC UpdateHMRC Update
HMRC Update
Softworld
 
Alex j
Alex jAlex j
Harrison d.
Harrison d.Harrison d.
Harrison d.
Harmony Elementary
 
2118 Final With Bg 2
2118 Final With Bg 22118 Final With Bg 2
2118 Final With Bg 2
2118tibet
 
Energy Overview No Video Small
Energy Overview No Video   SmallEnergy Overview No Video   Small
Energy Overview No Video Small
Chris_Moore
 
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
MIT School oF distance education
 
Your (coding) standards matter
Your (coding) standards matterYour (coding) standards matter
Your (coding) standards matter
Edorian
 
MANO
MANOMANO
Pikas
PikasPikas
Chase A
Chase AChase A
Sydney h
Sydney hSydney h

Viewers also liked (20)

Livejournal
LivejournalLivejournal
Livejournal
 
Mit pune e prospectus
Mit pune e prospectusMit pune e prospectus
Mit pune e prospectus
 
Restorative practices at rahs -update board
Restorative practices at rahs -update boardRestorative practices at rahs -update board
Restorative practices at rahs -update board
 
Online distance PG Diploma courses from MIT Pune
Online distance PG Diploma courses from MIT PuneOnline distance PG Diploma courses from MIT Pune
Online distance PG Diploma courses from MIT Pune
 
компьютерная мышь
компьютерная мышькомпьютерная мышь
компьютерная мышь
 
Wordpress install setup
Wordpress install setupWordpress install setup
Wordpress install setup
 
2118 F I N A L With Bg 2
2118  F I N A L With Bg 22118  F I N A L With Bg 2
2118 F I N A L With Bg 2
 
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
 
HMRC Update
HMRC UpdateHMRC Update
HMRC Update
 
Alex j
Alex jAlex j
Alex j
 
Harrison d.
Harrison d.Harrison d.
Harrison d.
 
2118 Final With Bg 2
2118 Final With Bg 22118 Final With Bg 2
2118 Final With Bg 2
 
Energy Overview No Video Small
Energy Overview No Video   SmallEnergy Overview No Video   Small
Energy Overview No Video Small
 
Comic
ComicComic
Comic
 
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
 
Your (coding) standards matter
Your (coding) standards matterYour (coding) standards matter
Your (coding) standards matter
 
MANO
MANOMANO
MANO
 
Pikas
PikasPikas
Pikas
 
Chase A
Chase AChase A
Chase A
 
Sydney h
Sydney hSydney h
Sydney h
 

Similar to php unconference Europa: Clean code - Stop wasting my time

Clean Code: Stop wasting my time
Clean Code: Stop wasting my timeClean Code: Stop wasting my time
Clean Code: Stop wasting my time
Edorian
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
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
ciconf
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
OOP
OOPOOP
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
RookieOne
 
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Noah Sussman
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
형우 안
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
James Johnson
 
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
Edorian
 
Graphql
GraphqlGraphql
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetup
Brian Cardiff
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
AzRy LLC, Caucasus School of Technology
 
Rails 101
Rails 101Rails 101
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
Alfonso Garcia-Caro
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
DjangoCon2008
 

Similar to php unconference Europa: Clean code - Stop wasting my time (20)

Clean Code: Stop wasting my time
Clean Code: Stop wasting my timeClean Code: Stop wasting my time
Clean Code: Stop wasting my time
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
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
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
OOP
OOPOOP
OOP
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
 
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
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
 
Graphql
GraphqlGraphql
Graphql
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetup
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Rails 101
Rails 101Rails 101
Rails 101
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
 

More from Edorian

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
Edorian
 
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
Edorian
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
Edorian
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
Edorian
 
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
Edorian
 
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
Edorian
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
Edorian
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
Edorian
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
Edorian
 
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
Edorian
 

More from Edorian (10)

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
 
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
 
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
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
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
 

Recently uploaded

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 

Recently uploaded (20)

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 

php unconference Europa: Clean code - Stop wasting my time

  • 1. Clean code:Stop wasting my time February 17, 2011 1
  • 2. About me Volker Dusch / @__edorian Doing PHP for ~8 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! February 17, 2011 2
  • 3. About you You seem to be smart people I guess you are motivated And I’m just going to assume that you work with smart people you respect February 17, 2011 3
  • 4. This talk is about time About your time About my time About the next guys time February 17, 2011 4
  • 5. So stop wasting time Don’t make me spend time trying to figure out what you are doing Don’t spend your own time writing stuff that isn’t going to help me anyways A little disclaimer: When I talk about ‘documentation’ I don’t mean @phpdoc tags for api docs (@param & @return) February 17, 2011 5
  • 6. What I would talk about Good documentation means less documentation How does that work for your team Commit messages I LIKE to read Everything related you want to discussIf we don’t make it through the slides I’m happy February 17, 2011 6
  • 7. Stuff you all know about SCM Unit testing Dependency Injection Why we don’t like singletons / static functions and other globals Other design mumbo jumbo If not: Read up on it. There are great resources out there February 17, 2011 7
  • 8. Yay! Samples class myClass { /** * Constructor */ public function __construct() { } // methods... } February 17, 2011 8
  • 9. Yay! Samples class myClass { /** * Create an instance of ‘myClass’ */ public function __construct() { } // methods... } February 17, 2011 9
  • 10. Yay! Samples class myClass { /** * @returnmyClass */ public function __construct() { } // methods... } February 17, 2011 10
  • 11. Yay! Samples class myClass{ public function __construct() { } // methods... } February 17, 2011 11
  • 12. Yay! Samples class myClass{ // methods... } February 17, 2011 12
  • 13. So… Seems mundane? That stuff scales! But everything needs to have a docblock! But I might need it later That‘s just because it‘s in the template and I didn‘t delete it February 17, 2011 13
  • 14. DOCUMENT EVERYTHING !!1eleven February 17, 2011 14 At least that’s what they told me How about that: Good code is hard to document Bad code is easy to document I prefer good code over a lot of docs
  • 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) {…} February 17, 2011 15
  • 16. Bettercode class user { public function getUserId() {…} public function getFirst/Last/DisplayName() {…} /** @link … */ public function getBodyMassIndex() {…} /** @param float $kilogramm */ public function setWeight($kilogramm) {…} February 17, 2011 16
  • 17. Again Short and undescriptive function names make it very easy to write documentation Good ones make it hard to write meaningful stuff Sadly people will need to read your docs again and again and again February 17, 2011 17
  • 18.
  • 20.
  • 21. Output – It‘s like autoloading <?php /** * @package module_x * @subpackage y_z */ /** * @package module_x * @subpackage y_z * @since creation_date * @version 1.2.3.4 */ class myClass { } February 17, 2011 20
  • 22. Know your user or coworker February 17, 2011 21
  • 23. This is phpdoc &phpcs valid Well… after the build script <?php class myClass { } *You might need 2 phpcs standards? February 17, 2011 22
  • 24. A final test See if you can spot the issues Or just guess what I‘d complain about February 17, 2011 23
  • 25. February 17, 2011 24 abstract 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()) {
  • 26. Another one? /** * Retrieves the uniform resource identifier for the current web request. * * @return string Unified resource identifier */ publicfunctiongetUri() /** * See if the client is using absolute uri * * @return boolean true, if is absolute uri otherwise false */ publicfunctionisAbsUri() February 17, 2011 25
  • 27. 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 February 17, 2011 26
  • 28. Inline Sample public function generateReport() { // get the db connection $reg = GlobalStorage::get(“db“); // auth if(!$reg->getOne(“SELECT view_report FROM USER ….“)) {…} // template $id = $reg->getOne(“select … „); // render new ReportTemplate($id); // …. February 17, 2011 27
  • 29. Inline Sample public function generateReport() { $this->checkAuthentication(); $template = this->createReportTemplate(); $this->renderReport($template); } That's not perfect but the ‘// next block‘ comments are gone February 17, 2011 28
  • 30. 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 USEFUL comment. Know who you write docs for February 17, 2011 29
  • 31. 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 February 17, 2011 30
  • 32. 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. February 17, 2011 31
  • 33. Git made this worse More smaller commits tend to make people just describe what they do and not why they did it Delete Tweak output Rename variable Add cacheTokensattribute Moved code from A to B February 17, 2011 32
  • 34. To sum up Don’t write documentation you think has no use See if you can substitute documentation with more descriptive naming Always: Do what your team has agreed upon and if you don’t like it try to change it if there is a benefit others see too. February 17, 2011 33
  • 35. Comments?Questions! Anything else? 34 Volker Dusch @__edorian
  • 36. Thank your for your time Tell me if you liked it. And tell me if not!) Volker Dusch @__edorian 35