SlideShare a Scribd company logo
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

PDF
What is-pmd
PDF
Code analyzer: FindBugs and PMD
PDF
Pmd naming-rules
PDF
Day1 - TDD (Lecture SS 2015)
PPTX
Code Smells - Refactoring
PPTX
CL Mock Tests for CAT
PDF
Tdd in practice
PDF
Why coding convention ?
What is-pmd
Code analyzer: FindBugs and PMD
Pmd naming-rules
Day1 - TDD (Lecture SS 2015)
Code Smells - Refactoring
CL Mock Tests for CAT
Tdd in practice
Why coding convention ?

What's hot (20)

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

Viewers also liked (6)

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

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

PPTX
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
PDF
Presentation
PPTX
COMPUTER PROGRAMMING LANGUAGE C++ 1.pptx
PDF
ANSI ISO C Professional Programmer S Handbook
PPT
lecture02-cpp.ppt
PPT
c++ ppt.ppt
PPTX
C Programming- Harsh Sharma
PPT
Introduction to C++,Computer Science
PPTX
POLITEKNIK MALAYSIA
PPT
Beginning with C++.ppt thus us beginnunv w
PPTX
C++ Made simple .pptx
PPT
Learn cpp at amc square learning
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
C++ - A powerful and system level language
PPT
Intro cpp
PPTX
presentation slides of Week 3 for 1st.pptx
PPTX
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Presentation
COMPUTER PROGRAMMING LANGUAGE C++ 1.pptx
ANSI ISO C Professional Programmer S Handbook
lecture02-cpp.ppt
c++ ppt.ppt
C Programming- Harsh Sharma
Introduction to C++,Computer Science
POLITEKNIK MALAYSIA
Beginning with C++.ppt thus us beginnunv w
C++ Made simple .pptx
Learn cpp at amc square learning
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
C++ - A powerful and system level language
Intro cpp
presentation slides of Week 3 for 1st.pptx
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Spectroscopy.pptx food analysis technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

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 [email protected] 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/