SlideShare a Scribd company logo
1 of 31
I Don’t HateYou,
I Just Hate Your Code
— B R I A N R I C H A R D S —
@rzen // WPSessions.com // WebDevStudios.com
— C H A P T E R O N E —
Formatting is
important.
@rzen
— C H A P T E R O N E —
Formatting
indicator of buggy code
#1
Inconsistent spacing is the
@rzen
— C H A P T E R O N E —
Formatting
"When people look under the hood, we want them to be
impressed with the neatness, consistency, and attention to
detail that they perceive.We want them to perceive that
professionals have been at work. If they see a scrambled
mess that looks like it was written by drunken sailors, they
will conclude that the same inattention to detail pervades
every other aspect of the project."
— Robert Martin, Clean Code
— C H A P T E R O N E —
Formatting
If you do nothing else,
at least be consistent.
If you’re going to be consistent,
why not be consistently GOOD?
@rzen
— C H A P T E R T W O —
You’re a decent human being,
you should have standards.
@rzen
— C H A P T E R T W O —
Standards
http://make.wordpress.org/core/handbook/coding-standards/ @rzen
— C H A P T E R T W O —
Standards
http://wp.tutsplus.com/articles/cheat-sheets
/the-wordpress-coding-standards-an-introduction/
Tom McFarlin goes into great
detail about why these matter
and are good for the planet:
@rzen
— C H A P T E R T W O —
Standards
if ( $this_thing == true ) {
// some code
}
if ( true == $this_thing ) {
// some code
}
S T A N D A R D :
Y O D A :
@rzen
— C H A P T E R T H R E E —
Working Fast = Working Clean
@rzen
— C H A P T E R F O U R —
Meaningful Names:
Clarity is King
@rzen
function proj_breadcrumb() {
// some code
}
function proj_get_breadcrumb() {
// some code
}
— C H A P T E R F O U R —
Meaningful Names
Y O U R C O D E :
B E T T E R C O D E :
@rzen
— C H A P T E R F O U R —
Meaningful Names
function do_awesome( $p = 0, $u = 0 ) {
// some code
}
Y O U R C O D E :
function do_awesome( $post_id = 0, $user_id = 0 ) {
// some code
}
B E T T E R C O D E :
@rzen
— C H A P T E R F I V E —
Functions should do one thing,
they should do it well,
they should do it only.
@rzen
— C H A P T E R F I V E —
Functions
The first rule of functions
is that they should be small.
The second rule of functions
is that they should be
smaller than that.
@rzen
— C H A P T E R F I V E —
Functions
BAD Function:
346 Lines, does logic, HTML, JS & CSS
@rzen
— C H A P T E R F I V E —
Functions
/**
* Return a user's points.
*
* @since 1.0.0
*
* @param integer $user_id User ID.
* @return integer Total Points.
*/
function badgeos_get_user_points( $user_id = 0 ) {
if ( ! $user_id ) {
$user_id = get_current_user_id();
}
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
GOOD Function:
4 lines long, does one thing
@rzen
Your functions should accept
as few parameters as possible.
Zero is best, followed by one,
followed by two, followed by
a serious re-evaluation.
— C H A P T E R F I V E —
Functions
@rzen
— C H A P T E R S I X —
Don’t comment bad code,
rewrite it.
@rzen
— C H A P T E R S I X —
Commenting
— P R E F A C E —
You should document
EVERYTHING.
@rzen
— C H A P T E R S I X —
Commenting
1.Obvious behavior
2.Misinformation
3.Information better
stored elsewhere
4.Unused functionality
T H E N , E L I M I N A T E T H E S E C O M M E N T S :
@rzen
— C H A P T E R S I X —
Commenting
function badgeos_get_user_points( $user_id = 0 ) {
// Get the current user ID if none specified
if ( ! $user_id ) {
$user_id = get_current_user_id();
}
// Return points cast as a positive integer (or 0, if invalid data)
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
1.Obvious behavior
@rzen
— C H A P T E R S I X —
Commenting
function badgeos_get_user_points( $user_id = 0 ) {
// Get the site ID first
// Then get the current user ID, if none specified
if ( ! $user_id ) {
$user_id = get_current_user_id();
}
// If user has negative points, set value to zero
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
2.Misinformation
@rzen
— C H A P T E R S I X —
Commenting
function badgeos_get_user_points( $user_id = 0 ) {
// Updated May 10, 2014
if ( ! $user_id ) {
$user_id = get_current_user_id();
}
// Modified by BR
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
3.Information better stored elsewhere
@rzen
— C H A P T E R S I X —
Commenting
function badgeos_get_user_points( $user_id = 0 ) {
// Get current user ID
// Removed May 10, 2014
// if ( ! $user_id ) {
// $user_id = get_current_user_id();
// }
return absint( get_user_meta( $user_id, '_badgeos_points', true ) );
}
4.Unused Functionality
@rzen
— C H A P T E R S E V E N —
Leave code better
than you found it.
@rzen
— C H A P T E R S E V E N —
Be a Good Code Scout
Incremental
improvement
is better than
NO improvement.
@rzen
— C H A P T E R S E V E N —
Be a Good Code Scout
1.Apply standard formatting
2.Rename for clarity
3.Break apart a big function
4.Add a DocBlock
5.Eliminate bad comments
E V E N J U S T O N E F I X I S G R E A T :
@rzen
— C H A P T E R E I G H T —
Clean code
is HardWork™
@rzen
— B R I A N R I C H A R D S —
@ R Z E N
W P S E S S I O N S . C O M
W E B D E V S T U D I O S . C O M
fin.
I Don't Hate You, I Just Hate Your Code

More Related Content

Viewers also liked

Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsVolodymyr Voytyshyn
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocitySam Newman
 
Back to basics: как ставить задачи?
Back to basics: как ставить задачи?Back to basics: как ставить задачи?
Back to basics: как ставить задачи?Nimax
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricksJavier Eguiluz
 
DevOps модное слово или следующая ступень эволюции
DevOps модное слово или следующая ступень эволюцииDevOps модное слово или следующая ступень эволюции
DevOps модное слово или следующая ступень эволюцииAndrey Rebrov
 
A Beginners Guide to noSQL
A Beginners Guide to noSQLA Beginners Guide to noSQL
A Beginners Guide to noSQLMike Crabb
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureP. Taylor Goetz
 

Viewers also liked (10)

Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
 
Back to basics: как ставить задачи?
Back to basics: как ставить задачи?Back to basics: как ставить задачи?
Back to basics: как ставить задачи?
 
Intro to DevOps
Intro to DevOpsIntro to DevOps
Intro to DevOps
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
DevOps модное слово или следующая ступень эволюции
DevOps модное слово или следующая ступень эволюцииDevOps модное слово или следующая ступень эволюции
DevOps модное слово или следующая ступень эволюции
 
A Beginners Guide to noSQL
A Beginners Guide to noSQLA Beginners Guide to noSQL
A Beginners Guide to noSQL
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm Architecture
 
DevOps
DevOpsDevOps
DevOps
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 

Similar to I Don't Hate You, I Just Hate Your Code

Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesAsao Kamei
 
PyLadies Talk: Learn to love the command line!
PyLadies Talk: Learn to love the command line!PyLadies Talk: Learn to love the command line!
PyLadies Talk: Learn to love the command line!Blanca Mancilla
 
Asynchronous data processing
Asynchronous data processingAsynchronous data processing
Asynchronous data processingAndrea Giuliano
 
Puppet Camp London 2015 - Helping Data Teams with Puppet
Puppet Camp London 2015 - Helping Data Teams with PuppetPuppet Camp London 2015 - Helping Data Teams with Puppet
Puppet Camp London 2015 - Helping Data Teams with PuppetPuppet
 
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Sergii Khomenko
 
Rails in the enterprise
Rails in the enterpriseRails in the enterprise
Rails in the enterprisealexrothenberg
 
Getting Up and Running with BDD on Rails
Getting Up and Running with BDD on RailsGetting Up and Running with BDD on Rails
Getting Up and Running with BDD on Railselliando dias
 
Getting Up and Running with BDD on Rails
Getting Up and Running with BDD on RailsGetting Up and Running with BDD on Rails
Getting Up and Running with BDD on RailsNicholas Cancelliere
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutesOwen Winkler
 

Similar to I Don't Hate You, I Just Hate Your Code (11)

Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 Slides
 
Clean code
Clean codeClean code
Clean code
 
PyLadies Talk: Learn to love the command line!
PyLadies Talk: Learn to love the command line!PyLadies Talk: Learn to love the command line!
PyLadies Talk: Learn to love the command line!
 
Asynchronous data processing
Asynchronous data processingAsynchronous data processing
Asynchronous data processing
 
Puppet Camp London 2015 - Helping Data Teams with Puppet
Puppet Camp London 2015 - Helping Data Teams with PuppetPuppet Camp London 2015 - Helping Data Teams with Puppet
Puppet Camp London 2015 - Helping Data Teams with Puppet
 
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
 
Rails in the enterprise
Rails in the enterpriseRails in the enterprise
Rails in the enterprise
 
Getting Up and Running with BDD on Rails
Getting Up and Running with BDD on RailsGetting Up and Running with BDD on Rails
Getting Up and Running with BDD on Rails
 
Getting Up and Running with BDD on Rails
Getting Up and Running with BDD on RailsGetting Up and Running with BDD on Rails
Getting Up and Running with BDD on Rails
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutes
 

More from Brian Richards

Awarding Behavior & Altering Businesses with WordPress
Awarding Behavior & Altering Businesses with WordPressAwarding Behavior & Altering Businesses with WordPress
Awarding Behavior & Altering Businesses with WordPressBrian Richards
 
Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Brian Richards
 
Learn Something Useful Every Day
Learn Something Useful Every DayLearn Something Useful Every Day
Learn Something Useful Every DayBrian Richards
 
WPGR - Intro to Git (on the Command Line)
WPGR - Intro to Git (on the Command Line)WPGR - Intro to Git (on the Command Line)
WPGR - Intro to Git (on the Command Line)Brian Richards
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command LineBrian Richards
 
Using a Framework Won't Box You In
Using a Framework Won't Box You InUsing a Framework Won't Box You In
Using a Framework Won't Box You InBrian Richards
 
Developing for Success -or- Any Fool Can Do This
Developing for Success -or- Any Fool Can Do ThisDeveloping for Success -or- Any Fool Can Do This
Developing for Success -or- Any Fool Can Do ThisBrian Richards
 

More from Brian Richards (7)

Awarding Behavior & Altering Businesses with WordPress
Awarding Behavior & Altering Businesses with WordPressAwarding Behavior & Altering Businesses with WordPress
Awarding Behavior & Altering Businesses with WordPress
 
Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2
 
Learn Something Useful Every Day
Learn Something Useful Every DayLearn Something Useful Every Day
Learn Something Useful Every Day
 
WPGR - Intro to Git (on the Command Line)
WPGR - Intro to Git (on the Command Line)WPGR - Intro to Git (on the Command Line)
WPGR - Intro to Git (on the Command Line)
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command Line
 
Using a Framework Won't Box You In
Using a Framework Won't Box You InUsing a Framework Won't Box You In
Using a Framework Won't Box You In
 
Developing for Success -or- Any Fool Can Do This
Developing for Success -or- Any Fool Can Do ThisDeveloping for Success -or- Any Fool Can Do This
Developing for Success -or- Any Fool Can Do This
 

Recently uploaded

Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....santhyamuthu1
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technologyabdulkadirmukarram03
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationMohsinKhanA
 
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxIT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxSAJITHABANUS
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Amil baba
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxjasonsedano2
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfRedhwan Qasem Shaddad
 
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfRenewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfodunowoeminence2019
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Amil baba
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxLMW Machine Tool Division
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxwendy cai
 
Test of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxTest of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxHome
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Projectreemakb03
 
Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfGiovanaGhasary1
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 

Recently uploaded (20)

Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technology
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software Simulation
 
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptxIT3401-WEB ESSENTIALS PRESENTATIONS.pptx
IT3401-WEB ESSENTIALS PRESENTATIONS.pptx
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptx
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdf
 
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfRenewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
 
Lecture 2 .pdf
Lecture 2                           .pdfLecture 2                           .pdf
Lecture 2 .pdf
 
Présentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdfPrésentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdf
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptx
 
Test of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptxTest of Significance of Large Samples for Mean = µ.pptx
Test of Significance of Large Samples for Mean = µ.pptx
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Project
 
Multicomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdfMulticomponent Spiral Wound Membrane Separation Model.pdf
Multicomponent Spiral Wound Membrane Separation Model.pdf
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 

I Don't Hate You, I Just Hate Your Code

  • 1. I Don’t HateYou, I Just Hate Your Code — B R I A N R I C H A R D S — @rzen // WPSessions.com // WebDevStudios.com
  • 2. — C H A P T E R O N E — Formatting is important. @rzen
  • 3. — C H A P T E R O N E — Formatting indicator of buggy code #1 Inconsistent spacing is the @rzen
  • 4. — C H A P T E R O N E — Formatting "When people look under the hood, we want them to be impressed with the neatness, consistency, and attention to detail that they perceive.We want them to perceive that professionals have been at work. If they see a scrambled mess that looks like it was written by drunken sailors, they will conclude that the same inattention to detail pervades every other aspect of the project." — Robert Martin, Clean Code
  • 5. — C H A P T E R O N E — Formatting If you do nothing else, at least be consistent. If you’re going to be consistent, why not be consistently GOOD? @rzen
  • 6. — C H A P T E R T W O — You’re a decent human being, you should have standards. @rzen
  • 7. — C H A P T E R T W O — Standards http://make.wordpress.org/core/handbook/coding-standards/ @rzen
  • 8. — C H A P T E R T W O — Standards http://wp.tutsplus.com/articles/cheat-sheets /the-wordpress-coding-standards-an-introduction/ Tom McFarlin goes into great detail about why these matter and are good for the planet: @rzen
  • 9. — C H A P T E R T W O — Standards if ( $this_thing == true ) { // some code } if ( true == $this_thing ) { // some code } S T A N D A R D : Y O D A : @rzen
  • 10. — C H A P T E R T H R E E — Working Fast = Working Clean @rzen
  • 11. — C H A P T E R F O U R — Meaningful Names: Clarity is King @rzen
  • 12. function proj_breadcrumb() { // some code } function proj_get_breadcrumb() { // some code } — C H A P T E R F O U R — Meaningful Names Y O U R C O D E : B E T T E R C O D E : @rzen
  • 13. — C H A P T E R F O U R — Meaningful Names function do_awesome( $p = 0, $u = 0 ) { // some code } Y O U R C O D E : function do_awesome( $post_id = 0, $user_id = 0 ) { // some code } B E T T E R C O D E : @rzen
  • 14. — C H A P T E R F I V E — Functions should do one thing, they should do it well, they should do it only. @rzen
  • 15. — C H A P T E R F I V E — Functions The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. @rzen
  • 16. — C H A P T E R F I V E — Functions BAD Function: 346 Lines, does logic, HTML, JS & CSS @rzen
  • 17. — C H A P T E R F I V E — Functions /** * Return a user's points. * * @since 1.0.0 * * @param integer $user_id User ID. * @return integer Total Points. */ function badgeos_get_user_points( $user_id = 0 ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } return absint( get_user_meta( $user_id, '_badgeos_points', true ) ); } GOOD Function: 4 lines long, does one thing @rzen
  • 18. Your functions should accept as few parameters as possible. Zero is best, followed by one, followed by two, followed by a serious re-evaluation. — C H A P T E R F I V E — Functions @rzen
  • 19. — C H A P T E R S I X — Don’t comment bad code, rewrite it. @rzen
  • 20. — C H A P T E R S I X — Commenting — P R E F A C E — You should document EVERYTHING. @rzen
  • 21. — C H A P T E R S I X — Commenting 1.Obvious behavior 2.Misinformation 3.Information better stored elsewhere 4.Unused functionality T H E N , E L I M I N A T E T H E S E C O M M E N T S : @rzen
  • 22. — C H A P T E R S I X — Commenting function badgeos_get_user_points( $user_id = 0 ) { // Get the current user ID if none specified if ( ! $user_id ) { $user_id = get_current_user_id(); } // Return points cast as a positive integer (or 0, if invalid data) return absint( get_user_meta( $user_id, '_badgeos_points', true ) ); } 1.Obvious behavior @rzen
  • 23. — C H A P T E R S I X — Commenting function badgeos_get_user_points( $user_id = 0 ) { // Get the site ID first // Then get the current user ID, if none specified if ( ! $user_id ) { $user_id = get_current_user_id(); } // If user has negative points, set value to zero return absint( get_user_meta( $user_id, '_badgeos_points', true ) ); } 2.Misinformation @rzen
  • 24. — C H A P T E R S I X — Commenting function badgeos_get_user_points( $user_id = 0 ) { // Updated May 10, 2014 if ( ! $user_id ) { $user_id = get_current_user_id(); } // Modified by BR return absint( get_user_meta( $user_id, '_badgeos_points', true ) ); } 3.Information better stored elsewhere @rzen
  • 25. — C H A P T E R S I X — Commenting function badgeos_get_user_points( $user_id = 0 ) { // Get current user ID // Removed May 10, 2014 // if ( ! $user_id ) { // $user_id = get_current_user_id(); // } return absint( get_user_meta( $user_id, '_badgeos_points', true ) ); } 4.Unused Functionality @rzen
  • 26. — C H A P T E R S E V E N — Leave code better than you found it. @rzen
  • 27. — C H A P T E R S E V E N — Be a Good Code Scout Incremental improvement is better than NO improvement. @rzen
  • 28. — C H A P T E R S E V E N — Be a Good Code Scout 1.Apply standard formatting 2.Rename for clarity 3.Break apart a big function 4.Add a DocBlock 5.Eliminate bad comments E V E N J U S T O N E F I X I S G R E A T : @rzen
  • 29. — C H A P T E R E I G H T — Clean code is HardWork™ @rzen
  • 30. — B R I A N R I C H A R D S — @ R Z E N W P S E S S I O N S . C O M W E B D E V S T U D I O S . C O M fin.