SlideShare a Scribd company logo
On Coding GuidelinesmyNameis dilawar(@Home), theLover( in Chennai), theLawWere(an Iranian Prof. in IIT Bombay)March 16, 2010dilawar.in@gmail.com
The pursuit of goodness… To be good, according to the vulgar standard of goodness, is obviously quite easy. It merely requires a certain amount of sordid terror, a certain lack of imaginative thought, and a certain low passion for middle-class respectability.      -- Oscar Wilde (1854 - 1900)
Why do we need them?
Why Standard is Important?Person joining the group at later stage can pickup the code easily (once he is familiar with the standards). If care is taken to define the standard in such a way that it avoids problematic C++ idioms, then silly mistakescan be avoided. In start, It’s a burden to follow. At the end, it’s a pleasure that you’ve followed.
Naming conventionsMy name is Bond, James Bond!  -- Ian Fleming.It is very important to give meaningful names to all your constructs. A name like  getAverageHeight() or get_avg_height() gives us much more information then calculate().Globalsshould be named meaningfully. Be generous!!Use recognizable names in English.
General RulesThumb Rule: Bigger the scope, bigger the name!Keystrokes Vs Marginal Information:  Some names do have standard abbreviation, for e.g. max. So, calling a variable maxLength gives us the same amount of information as maximumLength, but using the former saves some keystrokes If an abbreviation is contained in a name, it should not be used in all uppercase form. for example: use getHtmlPage ; not getHTMLPage
Constants, Enums and #define-s, Macros#define constants should be avoided in favor of const.Constants and Enumerated types (enums) names should be distinguishable from variables.There are few conventions for it: All uppercase name, with _ as word separator: MAX_ERRORSMacrosLike global variables, macros should be avoided in favor of inline functions. But some times they become unavoidable (for e.gassert). Special care should be taken while defining Macros which themselves declare variables. Macro names should be distinguishable from function names. Again, there are few conventions for it: All uppercase name, with _ as word separator: GET_DATA()suffix _m in name: getData_m()Variables defined inside macro body should NEVER clash with name in the scope calling the macro, or havoc will result. It is a good idea to have an entirely different convention for naming variables defined inside macro body.
Classes, Variables and FunctionsClassesName of a class should communicate its purpose. It is always beneficial to identify and name all the major classes in the program at design stage itself. Class name should start with an uppercase alphabet. class DiodeDude;class TerrificTransistor;VariablesMajor variables, the ones which are shared by multiple functions and/or module should be identified and named at design stage itself.Variable name should start with a lowercase alphabet. kriti* firstKriti; FunctionsJust like Variables. Anyway we have () to distinguish them. Prefixes should be used in functions to make its meaning clear. This is specially useful for boolean functions. Some common prefixes are: is : isTeamLeaderHome()has: hasPages()can: canOpenBottle()get: getMaxLimit()set: setPath()
File Naming and OrganizationIt is not so important to know everything as to know the exact value of everything, to appreciate what we learn, and to arrange what we know.      -- Hannah More `-- SampleProject|-- 00_Documents | |-- 00_User_Requirements | |-- 01_Design_And_Dev_Approach  . .| |-- 12_Acceptance | |-- 13_References |-- 01_Hardware | |-- DaughterBoard| |-- README |-- 02_Software | |-- trunk | | |-- Module1 | | |-- Module2 | |-- tags | | |-- Tag1 | | |-- Tag2 | |-- branches | | |-- Branch1 | | |-- Branch2 | |-- README (This README contains the commit policy being followed.) |-- 03_Enclosure |-- 04 ... |-- 10_Releases |-- README
Classes The loftier the building, the deeper must the foundation be laid.      -- Thomas Kempis
Classes…Ensure that all the classes in your application have: default constructor, copy constructor, overloaded = operator identify classes that may need to modify the data of this class A and make those classes as friend of the class A.Separate the core algorithm/strategy to be implemented in a separate class.Ensure that your classes are not bloated. Ensure that all derivable classes have virtual destructor.
LibrariesLibraries are not made; they grow.-- Augustine Birrell
Libraries…  (Tips on STL)Don't usehash_mapsin STL, they are not portable across platforms (MSVC on Windows does not support hash_maps!). In case you need to use a hash_map, take an approval from appropriate person. When using maps in STL, make sure you have defined the LessThan function object. Maps need this function object for ordering of elements that are inserted in the map. You don't need to write this function object in case the key element in your map is an integer.Usetypedefto create iterator types or else the code becomes unnecessarily lengthy.For big data types (classes), use pointer to object instead of object itself to create STL data type (vector, set etc.). The reason for this is STL data types may move around their data lots of times. For big data, this means a lot of calls to copy constructor, which incurs run time penalty.
Pointers vs ReferencesYou will find it a very good practice always to verify your references sir.      -- Martin RouthIf coding in C++, encourage use of references instead of pointers. In fact a pointer should typically be passed to a function only in cases where you need to execute something on the pointer being null condition. Ref: http://www.embedded.com/story/OEG20010311S0024
Minimizing Bugs while CodingIf debugging is the art of removing bugs, then programming must be the art of inserting them.      -- Guy is still unknown
How to minimize bugs?Follow the guidelines!
Beware! We are living on a smarter planet?Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.      -- Rich Cook Embedded Dudes/Dudettes: http://www.ganssle.com/
Additional ReferencesThe man who doesn't read good books has no advantage over the man who can't read them.      -- Mark Twain (1835 - 1910) http://www.cse.iitb.ac.in/~karkare/Gc/coding/#NameGeneral (Prof. HemantKarkare – IIT Bombay, CSE)I have not read the following but they can be useful for one who wants a deep insight.1. http://cm.bell-labs.com/cm/cs/tpop Brian W. Kernighan and Rob Pike.2 . Effective C++, Scott Meyers.3. More Effective C++, Scott Meyers.4. Code Complete, Steve McConell.5. Writing Solid Code, Steve Maguire.6. http://www.possibility.com/Cpp/CppCodingStandard.html
Ad

More Related Content

What's hot (19)

Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
Zeeshan Ahmad
 
Part 2 Python
Part 2 PythonPart 2 Python
Part 2 Python
Mohamed Essam
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
Prasanna Kumar SM
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
Binay Kumar Ray
 
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
Structure Arrays
Structure ArraysStructure Arrays
Structure Arrays
manyamkusuma
 
The Awesome Python Class Part-5
The Awesome Python Class Part-5The Awesome Python Class Part-5
The Awesome Python Class Part-5
Binay Kumar Ray
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
PRASANYA K
 
M.c.a (sem iii) paper - i - object oriented programming
M.c.a (sem   iii) paper - i - object oriented programmingM.c.a (sem   iii) paper - i - object oriented programming
M.c.a (sem iii) paper - i - object oriented programming
रवींद्र वैद्य
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
Micheal Ogundero
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
Sujit Majety
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
brada
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
Dr.Neeraj Kumar Pandey
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
brada
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
talha ijaz
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
Binay Kumar Ray
 
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
The Awesome Python Class Part-5
The Awesome Python Class Part-5The Awesome Python Class Part-5
The Awesome Python Class Part-5
Binay Kumar Ray
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
PRASANYA K
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
Micheal Ogundero
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
Sujit Majety
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
brada
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
brada
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 

Viewers also liked (20)

Middle Class
Middle ClassMiddle Class
Middle Class
Wayne Rohde
 
Are You The Man
Are You The ManAre You The Man
Are You The Man
Don McClain
 
Weapons of Mass Disruption: Creating The Drowning
Weapons of Mass Disruption: Creating The DrowningWeapons of Mass Disruption: Creating The Drowning
Weapons of Mass Disruption: Creating The Drowning
Ben Cousins
 
How to Use HealthyCity.org to Influence Policy
How to Use HealthyCity.org to Influence PolicyHow to Use HealthyCity.org to Influence Policy
How to Use HealthyCity.org to Influence Policy
Healthy City
 
Strengthening Our Spiritual Family
Strengthening Our Spiritual FamilyStrengthening Our Spiritual Family
Strengthening Our Spiritual Family
Don McClain
 
2.28.2011
2.28.20112.28.2011
2.28.2011
claire9831
 
2.28.2011
2.28.20112.28.2011
2.28.2011
claire9831
 
Talking Ourselves Into Sin
Talking Ourselves Into SinTalking Ourselves Into Sin
Talking Ourselves Into Sin
Don McClain
 
Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011
george_pavel
 
Corporate Presentation Ro
Corporate Presentation RoCorporate Presentation Ro
Corporate Presentation Ro
george_pavel
 
Data sheet eng
Data sheet engData sheet eng
Data sheet eng
SEABERY
 
Cummins Actuarial Study 09
Cummins Actuarial Study 09Cummins Actuarial Study 09
Cummins Actuarial Study 09
Wayne Rohde
 
Tns nipo onderzoeksrapport hyves versus facebook
Tns nipo onderzoeksrapport hyves versus facebookTns nipo onderzoeksrapport hyves versus facebook
Tns nipo onderzoeksrapport hyves versus facebook
Marcel Maassen (Connectricity)
 
J Robert Hunter Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
J  Robert Hunter   Antitrust Senate Mc Carran Repeal Health Insurance Testimo...J  Robert Hunter   Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
J Robert Hunter Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
Wayne Rohde
 
Indian Middle Class : A bird-view
Indian Middle Class : A bird-viewIndian Middle Class : A bird-view
Indian Middle Class : A bird-view
DIlawar Singh
 
Who Is The Uninsured
Who Is The UninsuredWho Is The Uninsured
Who Is The Uninsured
Wayne Rohde
 
Carbon Presentation
Carbon PresentationCarbon Presentation
Carbon Presentation
gadgetic
 
Weapons of Mass Disruption: Creating The Drowning
Weapons of Mass Disruption: Creating The DrowningWeapons of Mass Disruption: Creating The Drowning
Weapons of Mass Disruption: Creating The Drowning
Ben Cousins
 
How to Use HealthyCity.org to Influence Policy
How to Use HealthyCity.org to Influence PolicyHow to Use HealthyCity.org to Influence Policy
How to Use HealthyCity.org to Influence Policy
Healthy City
 
Strengthening Our Spiritual Family
Strengthening Our Spiritual FamilyStrengthening Our Spiritual Family
Strengthening Our Spiritual Family
Don McClain
 
Talking Ourselves Into Sin
Talking Ourselves Into SinTalking Ourselves Into Sin
Talking Ourselves Into Sin
Don McClain
 
Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011
george_pavel
 
Corporate Presentation Ro
Corporate Presentation RoCorporate Presentation Ro
Corporate Presentation Ro
george_pavel
 
Data sheet eng
Data sheet engData sheet eng
Data sheet eng
SEABERY
 
Cummins Actuarial Study 09
Cummins Actuarial Study 09Cummins Actuarial Study 09
Cummins Actuarial Study 09
Wayne Rohde
 
J Robert Hunter Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
J  Robert Hunter   Antitrust Senate Mc Carran Repeal Health Insurance Testimo...J  Robert Hunter   Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
J Robert Hunter Antitrust Senate Mc Carran Repeal Health Insurance Testimo...
Wayne Rohde
 
Indian Middle Class : A bird-view
Indian Middle Class : A bird-viewIndian Middle Class : A bird-view
Indian Middle Class : A bird-view
DIlawar Singh
 
Who Is The Uninsured
Who Is The UninsuredWho Is The Uninsured
Who Is The Uninsured
Wayne Rohde
 
Carbon Presentation
Carbon PresentationCarbon Presentation
Carbon Presentation
gadgetic
 
Ad

Similar to On Coding Guidelines (20)

Finding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeFinding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento Code
Ben Marks
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
AlbanLevy
 
Coding standard
Coding standardCoding standard
Coding standard
Shwetketu Rastogi
 
Clean Code
Clean CodeClean Code
Clean Code
Dmytro Turskyi
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
Ganesh Samarthyam
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
rumanatasnim415
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
Ganesh Samarthyam
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
BlackRabbitCoder
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
nicolbiden
 
C++ Pogramming Language Course.docx Under
C++ Pogramming Language Course.docx UnderC++ Pogramming Language Course.docx Under
C++ Pogramming Language Course.docx Under
khushbhatti511
 
C++ Training
C++ TrainingC++ Training
C++ Training
SubhendraBasu5
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an Exporter
Brian Brazil
 
LEARN C#
LEARN C#LEARN C#
LEARN C#
adroitinfogen
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
Kaushik Raghupathi
 
C# interview
C# interviewC# interview
C# interview
ajeesharakkal
 
If I Had a Hammer...
If I Had a Hammer...If I Had a Hammer...
If I Had a Hammer...
Kevlin Henney
 
Code review
Code reviewCode review
Code review
Abhishek Sur
 
The Perfect Couple
The Perfect CoupleThe Perfect Couple
The Perfect Couple
Kevlin Henney
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
Srinivasa GV
 
Finding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeFinding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento Code
Ben Marks
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
AlbanLevy
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
Ganesh Samarthyam
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
BlackRabbitCoder
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
nicolbiden
 
C++ Pogramming Language Course.docx Under
C++ Pogramming Language Course.docx UnderC++ Pogramming Language Course.docx Under
C++ Pogramming Language Course.docx Under
khushbhatti511
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an Exporter
Brian Brazil
 
If I Had a Hammer...
If I Had a Hammer...If I Had a Hammer...
If I Had a Hammer...
Kevlin Henney
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
Srinivasa GV
 
Ad

Recently uploaded (20)

Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 

On Coding Guidelines

  • 1. On Coding GuidelinesmyNameis dilawar(@Home), theLover( in Chennai), theLawWere(an Iranian Prof. in IIT Bombay)March 16, [email protected]
  • 2. The pursuit of goodness… To be good, according to the vulgar standard of goodness, is obviously quite easy. It merely requires a certain amount of sordid terror, a certain lack of imaginative thought, and a certain low passion for middle-class respectability.      -- Oscar Wilde (1854 - 1900)
  • 3. Why do we need them?
  • 4. Why Standard is Important?Person joining the group at later stage can pickup the code easily (once he is familiar with the standards). If care is taken to define the standard in such a way that it avoids problematic C++ idioms, then silly mistakescan be avoided. In start, It’s a burden to follow. At the end, it’s a pleasure that you’ve followed.
  • 5. Naming conventionsMy name is Bond, James Bond! -- Ian Fleming.It is very important to give meaningful names to all your constructs. A name like getAverageHeight() or get_avg_height() gives us much more information then calculate().Globalsshould be named meaningfully. Be generous!!Use recognizable names in English.
  • 6. General RulesThumb Rule: Bigger the scope, bigger the name!Keystrokes Vs Marginal Information: Some names do have standard abbreviation, for e.g. max. So, calling a variable maxLength gives us the same amount of information as maximumLength, but using the former saves some keystrokes If an abbreviation is contained in a name, it should not be used in all uppercase form. for example: use getHtmlPage ; not getHTMLPage
  • 7. Constants, Enums and #define-s, Macros#define constants should be avoided in favor of const.Constants and Enumerated types (enums) names should be distinguishable from variables.There are few conventions for it: All uppercase name, with _ as word separator: MAX_ERRORSMacrosLike global variables, macros should be avoided in favor of inline functions. But some times they become unavoidable (for e.gassert). Special care should be taken while defining Macros which themselves declare variables. Macro names should be distinguishable from function names. Again, there are few conventions for it: All uppercase name, with _ as word separator: GET_DATA()suffix _m in name: getData_m()Variables defined inside macro body should NEVER clash with name in the scope calling the macro, or havoc will result. It is a good idea to have an entirely different convention for naming variables defined inside macro body.
  • 8. Classes, Variables and FunctionsClassesName of a class should communicate its purpose. It is always beneficial to identify and name all the major classes in the program at design stage itself. Class name should start with an uppercase alphabet. class DiodeDude;class TerrificTransistor;VariablesMajor variables, the ones which are shared by multiple functions and/or module should be identified and named at design stage itself.Variable name should start with a lowercase alphabet. kriti* firstKriti; FunctionsJust like Variables. Anyway we have () to distinguish them. Prefixes should be used in functions to make its meaning clear. This is specially useful for boolean functions. Some common prefixes are: is : isTeamLeaderHome()has: hasPages()can: canOpenBottle()get: getMaxLimit()set: setPath()
  • 9. File Naming and OrganizationIt is not so important to know everything as to know the exact value of everything, to appreciate what we learn, and to arrange what we know.      -- Hannah More `-- SampleProject|-- 00_Documents | |-- 00_User_Requirements | |-- 01_Design_And_Dev_Approach . .| |-- 12_Acceptance | |-- 13_References |-- 01_Hardware | |-- DaughterBoard| |-- README |-- 02_Software | |-- trunk | | |-- Module1 | | |-- Module2 | |-- tags | | |-- Tag1 | | |-- Tag2 | |-- branches | | |-- Branch1 | | |-- Branch2 | |-- README (This README contains the commit policy being followed.) |-- 03_Enclosure |-- 04 ... |-- 10_Releases |-- README
  • 10. Classes The loftier the building, the deeper must the foundation be laid.      -- Thomas Kempis
  • 11. Classes…Ensure that all the classes in your application have: default constructor, copy constructor, overloaded = operator identify classes that may need to modify the data of this class A and make those classes as friend of the class A.Separate the core algorithm/strategy to be implemented in a separate class.Ensure that your classes are not bloated. Ensure that all derivable classes have virtual destructor.
  • 12. LibrariesLibraries are not made; they grow.-- Augustine Birrell
  • 13. Libraries… (Tips on STL)Don't usehash_mapsin STL, they are not portable across platforms (MSVC on Windows does not support hash_maps!). In case you need to use a hash_map, take an approval from appropriate person. When using maps in STL, make sure you have defined the LessThan function object. Maps need this function object for ordering of elements that are inserted in the map. You don't need to write this function object in case the key element in your map is an integer.Usetypedefto create iterator types or else the code becomes unnecessarily lengthy.For big data types (classes), use pointer to object instead of object itself to create STL data type (vector, set etc.). The reason for this is STL data types may move around their data lots of times. For big data, this means a lot of calls to copy constructor, which incurs run time penalty.
  • 14. Pointers vs ReferencesYou will find it a very good practice always to verify your references sir.      -- Martin RouthIf coding in C++, encourage use of references instead of pointers. In fact a pointer should typically be passed to a function only in cases where you need to execute something on the pointer being null condition. Ref: http://www.embedded.com/story/OEG20010311S0024
  • 15. Minimizing Bugs while CodingIf debugging is the art of removing bugs, then programming must be the art of inserting them.      -- Guy is still unknown
  • 16. How to minimize bugs?Follow the guidelines!
  • 17. Beware! We are living on a smarter planet?Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.      -- Rich Cook Embedded Dudes/Dudettes: http://www.ganssle.com/
  • 18. Additional ReferencesThe man who doesn't read good books has no advantage over the man who can't read them.      -- Mark Twain (1835 - 1910) http://www.cse.iitb.ac.in/~karkare/Gc/coding/#NameGeneral (Prof. HemantKarkare – IIT Bombay, CSE)I have not read the following but they can be useful for one who wants a deep insight.1. http://cm.bell-labs.com/cm/cs/tpop Brian W. Kernighan and Rob Pike.2 . Effective C++, Scott Meyers.3. More Effective C++, Scott Meyers.4. Code Complete, Steve McConell.5. Writing Solid Code, Steve Maguire.6. http://www.possibility.com/Cpp/CppCodingStandard.html