SlideShare a Scribd company logo
1 of 13
Good coding style
A drama in 12 parts with an epilogue
Konstantin Osipov
Staff Engineer
Sun/MySQL
kostja@sun.com
These slides released under the Creative Commons 
Attribution­Noncommercial­Share Alike License
Agenda
●
It's all Monty's fault! Or maybe not?
● Define the problem
● What can be done
● Call to arms
●
Thank you & References
What's a good coding style?
●
C++ FAQ Lite:
Thank you for reading this answer rather than just trying to set your own
coding standards.
But beware that some people on comp.lang.c++ are very sensitive on this issue.
Nearly every software engineer has, at some point, been exploited by someone
who used coding standards as a "power play." Furthermore some attempts to set
C++ coding standards have been made by those who didn't know what they were
talking about, so the standards end up being based on what was the
state-of-the-art when the standards setters were writing code. Such
impositions generate an attitude of mistrust for coding standards.
Why is it a problem: the style is obsolete
kostja@bodhi:~/work/mysql-6.0-runtime/sql$ grep '<true>' *.{h,cc}
| grep -v sql_yacc.cc | wc -l
356356
kostja@bodhi:~/work/mysql-6.0-runtime/sql$ grep '<false>' *.
{h,cc} | grep -v sql_yacc.cc | wc -l
212
Why is it a problem: the style is ignored
struct st_bstream_snapshot_info
class QUICK_RANGE
class DsMrr_impl
class MDL_context and class DDL_blocker_class
typedef struct st_table_ref TABLE_REF
class NdbScanOperation and class TableEvent
class sp_head and sp_instr_jump
Why is it a problem: maintenance
Foo::Foo(int a_arg, int b_arg, int c_arg)
: a(a_arg), b(b_arg), c(c_arg)
-> rename or add a member
int descriptive_identifier_name1= 1;
char not_so_descriptive= 2;
-> now add a declaration of very_long_and_descriptive_identifier3
My_long_class_name::My_long_class_name(int param1, Type1 param 2,
Type2 param3);
-> rename the class or the method
Why is It a problem: practice
●
sheer neglect to copy constructors and
assignment operators
● all members are public, in new code as well
●
-> C++ practice guide is missing
Define a good coding style, attempt #2
●
helps readability
● prevents coding mistakes
● simplifies maintenance
● easy to learn
●
unambiguous
●
comes with a best practices guide
A change is called for!
Possible immediate steps:
● prefer new/delete to malloc()/free() wherever
possible
●
TRUE -> true, FALSE -> false switch
● m_ prefixes for private class members
● remove typedef st_name {} NAME constructs
● your pet peeve can be here, if it's also
everybody's
The criticism
●
what we have is good enough, and everybody is
used to it
● there are more important problems (AKA re-
engineering is our savior)
●
a change means the code is always half-way
through it. Doxygen comments adoption.
●
changes in the style is a revision history noise
What can be done?
●
let's talk about it, but not too much
● accept and follow the current status quo
● improve what we have, with care
Thank you!
References
●
MySQL coding guidelines :
http://forge.mysql.com/wiki/MySQL_Internals_Coding_Guidelines
●
C++ FAQ lite: http://www.parashift.com/c++-faq-lite/
●
Bjarne Stroustrup's FAQ: http://www.research.att.com/~bs/bs_faq.html
●
C++ Style Guide from Geosoft.no: http://geosoft.no/development/cppstyle.html
●
Collection of other styles: http://www.chris-lott.org/resources/cstyle/

More Related Content

What's hot

Test Driven Development in Python
Test Driven Development in PythonTest Driven Development in Python
Test Driven Development in Python
Anoop Thomas Mathew
 

What's hot (20)

Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
 
Exceptions: Why, When, How and Where!
Exceptions: Why, When, How and Where!Exceptions: Why, When, How and Where!
Exceptions: Why, When, How and Where!
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
 
TDD python ne-april-2014
TDD python ne-april-2014TDD python ne-april-2014
TDD python ne-april-2014
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Javascript: The good parts for humans (part 1)
Javascript: The good parts for humans (part 1)Javascript: The good parts for humans (part 1)
Javascript: The good parts for humans (part 1)
 
TDD for the masses
TDD for the massesTDD for the masses
TDD for the masses
 
TDD & Refactoring
TDD & RefactoringTDD & Refactoring
TDD & Refactoring
 
Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?
 
(6) cpp abstractions inheritance_part_i_exercises
(6) cpp abstractions inheritance_part_i_exercises(6) cpp abstractions inheritance_part_i_exercises
(6) cpp abstractions inheritance_part_i_exercises
 
Test Driven Development in Python
Test Driven Development in PythonTest Driven Development in Python
Test Driven Development in Python
 
Practical pointers for better code review
Practical pointers for better code reviewPractical pointers for better code review
Practical pointers for better code review
 
클린 테스트
클린 테스트클린 테스트
클린 테스트
 
SubTests are the Best
SubTests are the BestSubTests are the Best
SubTests are the Best
 
Lập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentLập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven development
 
Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1. Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1.
 
TDD er død. Lenge leve TDD!
TDD er død. Lenge leve TDD!TDD er død. Lenge leve TDD!
TDD er død. Lenge leve TDD!
 
SOLID refactoring - racing car katas
SOLID refactoring - racing car katasSOLID refactoring - racing car katas
SOLID refactoring - racing car katas
 
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
 
I'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itI'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit it
 

Viewers also liked

Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
Melanie Eisenberg
 
My talk at Topconf.com conference, Tallinn, 1st of November 2012
My talk at Topconf.com conference, Tallinn, 1st of November 2012My talk at Topconf.com conference, Tallinn, 1st of November 2012
My talk at Topconf.com conference, Tallinn, 1st of November 2012
Kostja Osipov
 

Viewers also liked (6)

Nossos projetos
Nossos projetosNossos projetos
Nossos projetos
 
Metadata locking in MySQL 5.5
Metadata locking in MySQL 5.5Metadata locking in MySQL 5.5
Metadata locking in MySQL 5.5
 
Nabucco..
  Nabucco..  Nabucco..
Nabucco..
 
Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
Emarketerwebinarresponsivedesignsolutionpublishersquestionmarketers 130725135...
 
Highload2o013 osipv
Highload2o013 osipvHighload2o013 osipv
Highload2o013 osipv
 
My talk at Topconf.com conference, Tallinn, 1st of November 2012
My talk at Topconf.com conference, Tallinn, 1st of November 2012My talk at Topconf.com conference, Tallinn, 1st of November 2012
My talk at Topconf.com conference, Tallinn, 1st of November 2012
 

Similar to Good coding-style, a talk made in 2008 to encourage changes in MySQL coding style

Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
Kathy Brown
 
Uvm cookbook-systemverilog-guidelines-verification-academy
Uvm cookbook-systemverilog-guidelines-verification-academyUvm cookbook-systemverilog-guidelines-verification-academy
Uvm cookbook-systemverilog-guidelines-verification-academy
Raghavendra Kamath
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
Mark Veltzer
 

Similar to Good coding-style, a talk made in 2008 to encourage changes in MySQL coding style (20)

Code sense
Code senseCode sense
Code sense
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and more
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Web performance
Web  performance Web  performance
Web performance
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 
Femmengeeniring_Kateryna Mishchenko.pdf
Femmengeeniring_Kateryna Mishchenko.pdfFemmengeeniring_Kateryna Mishchenko.pdf
Femmengeeniring_Kateryna Mishchenko.pdf
 
midterm_fa07.pdf
midterm_fa07.pdfmidterm_fa07.pdf
midterm_fa07.pdf
 
Effective C++
Effective C++Effective C++
Effective C++
 
Session 3 : Competitive programming 1
Session 3 : Competitive programming 1Session 3 : Competitive programming 1
Session 3 : Competitive programming 1
 
Uvm cookbook-systemverilog-guidelines-verification-academy
Uvm cookbook-systemverilog-guidelines-verification-academyUvm cookbook-systemverilog-guidelines-verification-academy
Uvm cookbook-systemverilog-guidelines-verification-academy
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptx
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Good coding-style, a talk made in 2008 to encourage changes in MySQL coding style

  • 1. Good coding style A drama in 12 parts with an epilogue Konstantin Osipov Staff Engineer Sun/MySQL kostja@sun.com These slides released under the Creative Commons  Attribution­Noncommercial­Share Alike License
  • 2. Agenda ● It's all Monty's fault! Or maybe not? ● Define the problem ● What can be done ● Call to arms ● Thank you & References
  • 3. What's a good coding style? ● C++ FAQ Lite: Thank you for reading this answer rather than just trying to set your own coding standards. But beware that some people on comp.lang.c++ are very sensitive on this issue. Nearly every software engineer has, at some point, been exploited by someone who used coding standards as a "power play." Furthermore some attempts to set C++ coding standards have been made by those who didn't know what they were talking about, so the standards end up being based on what was the state-of-the-art when the standards setters were writing code. Such impositions generate an attitude of mistrust for coding standards.
  • 4. Why is it a problem: the style is obsolete kostja@bodhi:~/work/mysql-6.0-runtime/sql$ grep '<true>' *.{h,cc} | grep -v sql_yacc.cc | wc -l 356356 kostja@bodhi:~/work/mysql-6.0-runtime/sql$ grep '<false>' *. {h,cc} | grep -v sql_yacc.cc | wc -l 212
  • 5. Why is it a problem: the style is ignored struct st_bstream_snapshot_info class QUICK_RANGE class DsMrr_impl class MDL_context and class DDL_blocker_class typedef struct st_table_ref TABLE_REF class NdbScanOperation and class TableEvent class sp_head and sp_instr_jump
  • 6. Why is it a problem: maintenance Foo::Foo(int a_arg, int b_arg, int c_arg) : a(a_arg), b(b_arg), c(c_arg) -> rename or add a member int descriptive_identifier_name1= 1; char not_so_descriptive= 2; -> now add a declaration of very_long_and_descriptive_identifier3 My_long_class_name::My_long_class_name(int param1, Type1 param 2, Type2 param3); -> rename the class or the method
  • 7. Why is It a problem: practice ● sheer neglect to copy constructors and assignment operators ● all members are public, in new code as well ● -> C++ practice guide is missing
  • 8. Define a good coding style, attempt #2 ● helps readability ● prevents coding mistakes ● simplifies maintenance ● easy to learn ● unambiguous ● comes with a best practices guide
  • 9. A change is called for! Possible immediate steps: ● prefer new/delete to malloc()/free() wherever possible ● TRUE -> true, FALSE -> false switch ● m_ prefixes for private class members ● remove typedef st_name {} NAME constructs ● your pet peeve can be here, if it's also everybody's
  • 10. The criticism ● what we have is good enough, and everybody is used to it ● there are more important problems (AKA re- engineering is our savior) ● a change means the code is always half-way through it. Doxygen comments adoption. ● changes in the style is a revision history noise
  • 11. What can be done? ● let's talk about it, but not too much ● accept and follow the current status quo ● improve what we have, with care
  • 13. References ● MySQL coding guidelines : http://forge.mysql.com/wiki/MySQL_Internals_Coding_Guidelines ● C++ FAQ lite: http://www.parashift.com/c++-faq-lite/ ● Bjarne Stroustrup's FAQ: http://www.research.att.com/~bs/bs_faq.html ● C++ Style Guide from Geosoft.no: http://geosoft.no/development/cppstyle.html ● Collection of other styles: http://www.chris-lott.org/resources/cstyle/