SlideShare a Scribd company logo
On Coding Guidelines myNameis dilawar(@Home), theLover( in Chennai), theLawWere(an Iranian Prof. in IIT Bombay) March 16, 2010 dilawar.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 conventions My 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 Rules Thumb 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_ERRORS Macros Like 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 Functions Classes Name 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; Variables Major 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;  Functions Just 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 Organization It 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.
Libraries Libraries 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 References You 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 Coding If 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 References The 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

More Related Content

What's hot

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
 
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 LANGUAGEPRASANYA 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
 
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
 

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
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
Part 2 Python
Part 2 PythonPart 2 Python
Part 2 Python
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
The Awesome Python Class Part-4
The Awesome Python Class Part-4The Awesome Python Class Part-4
The Awesome Python Class Part-4
 
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...
 
Structure Arrays
Structure ArraysStructure Arrays
Structure Arrays
 
The Awesome Python Class Part-5
The Awesome Python Class Part-5The Awesome Python Class Part-5
The Awesome Python Class Part-5
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
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
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
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
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 

Viewers also liked

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
 
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 2011george_pavel
 
Corporate Presentation Ro
Corporate Presentation RoCorporate Presentation Ro
Corporate Presentation Rogeorge_pavel
 
Data sheet eng
Data sheet engData sheet eng
Data sheet engSEABERY
 
Cummins Actuarial Study 09
Cummins Actuarial Study 09Cummins Actuarial Study 09
Cummins Actuarial Study 09Wayne 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-viewDIlawar Singh
 
Who Is The Uninsured
Who Is The UninsuredWho Is The Uninsured
Who Is The UninsuredWayne Rohde
 
Carbon Presentation
Carbon PresentationCarbon Presentation
Carbon Presentation
gadgetic
 

Viewers also liked (20)

Middle Class
Middle ClassMiddle Class
Middle Class
 
Are You The Man
Are You The ManAre You The Man
Are You The Man
 
Hitoriaurrea
HitoriaurreaHitoriaurrea
Hitoriaurrea
 
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
 
Historiaurrea
HistoriaurreaHistoriaurrea
Historiaurrea
 
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
 
Strengthening Our Spiritual Family
Strengthening Our Spiritual FamilyStrengthening Our Spiritual Family
Strengthening Our Spiritual Family
 
Multiaventura
MultiaventuraMultiaventura
Multiaventura
 
2.28.2011
2.28.20112.28.2011
2.28.2011
 
2.28.2011
2.28.20112.28.2011
2.28.2011
 
Talking Ourselves Into Sin
Talking Ourselves Into SinTalking Ourselves Into Sin
Talking Ourselves Into Sin
 
Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011Prezentare generala Versa Media 2011
Prezentare generala Versa Media 2011
 
Corporate Presentation Ro
Corporate Presentation RoCorporate Presentation Ro
Corporate Presentation Ro
 
Data sheet eng
Data sheet engData sheet eng
Data sheet eng
 
Cummins Actuarial Study 09
Cummins Actuarial Study 09Cummins Actuarial Study 09
Cummins Actuarial Study 09
 
Tns nipo onderzoeksrapport hyves versus facebook
Tns nipo onderzoeksrapport hyves versus facebookTns nipo onderzoeksrapport hyves versus facebook
Tns nipo onderzoeksrapport hyves versus facebook
 
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...
 
Indian Middle Class : A bird-view
Indian Middle Class : A bird-viewIndian Middle Class : A bird-view
Indian Middle Class : A bird-view
 
Who Is The Uninsured
Who Is The UninsuredWho Is The Uninsured
Who Is The Uninsured
 
Carbon Presentation
Carbon PresentationCarbon Presentation
Carbon Presentation
 

Similar to On Coding Guidelines

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
 
Clean Code
Clean CodeClean Code
Clean Code
Dmytro Turskyi
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
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++TemplatesGanesh 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++ Training
C++ TrainingC++ Training
C++ Training
SubhendraBasu5
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
Kevlin Henney
 
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
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
Anilkumar Patil
 
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
 

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
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
 
Coding standard
Coding standardCoding standard
Coding standard
 
Clean Code
Clean CodeClean Code
Clean Code
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
 
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
 
LEARN C#
LEARN C#LEARN C#
LEARN C#
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
C# interview
C# interviewC# interview
C# interview
 
If I Had a Hammer...
If I Had a Hammer...If I Had a Hammer...
If I Had a Hammer...
 
Code review
Code reviewCode review
Code review
 
The Perfect Couple
The Perfect CoupleThe Perfect Couple
The Perfect Couple
 

Recently uploaded

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 

Recently uploaded (20)

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 

On Coding Guidelines

  • 1. On Coding Guidelines myNameis dilawar(@Home), theLover( in Chennai), theLawWere(an Iranian Prof. in IIT Bombay) March 16, 2010 dilawar.in@gmail.com
  • 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 conventions My 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 Rules Thumb 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_ERRORS Macros Like 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 Functions Classes Name 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; Variables Major 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; Functions Just 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 Organization It 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. Libraries Libraries 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 References You 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 Coding If 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 References The 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