954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ coding standard

Hello.

Apart from practice and books (like C++ coding standards by Sutter and Alexandrescu) what is the fastest and surest way to acheive coding standards in c++?

Supriyo

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Don't know the fastest, but you could start here

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

Join the open std C++ mailing list.

omol
Junior Poster
156 posts since Jul 2004
Reputation Points: 10
Solved Threads: 10
 
Join the open std C++ mailing list.

Can you provide me any links to it?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
Don't know the fastest, but you could start here

Thanx.
Apart from this can you recommend any other sources?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

To learn the very basics of c++, go to http://www.cplusplus.com . More advanced can be learnt through books like complete reference and others.. Whatever u study, practice makes programming easier

xtrmR
Newbie Poster
13 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 
To learn the very basics of c++, go to http://www.cplusplus.com . More advanced can be learnt through books like complete reference and others.. Whatever u study, practice makes programming easier

Thanx.
But what are the rules of practice?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

What exactly do you mean by rules? There are no rules for Coding style - such coding standards are usually based upon one or more of:Personal Preference
Conventional wisdom (i.e. what do 'most other people' do?)
Consistency with existing code (If you're modifying someone else's code)
Style imposed by your employer/project leader (these are the only "rules" which exist)

If you really want a 'rule' to follow, then there's only one worth listening to, which is Be Consistent. i.e. don't write code in a whole mixed bag of styles - the most readable code is usually that which follows the same 'theme' throughout. If you can do this, then few people will complain, provided your code is well-formed.

You also might like to read this bit of advice from Bjarne Stroustrup
http://www2.research.att.com/~bs/bs_faq2.html#coding-standard

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 
What exactly do you mean by rules? There are no rules for Coding style - such coding standards are usually based upon one or more of:
  • Personal Preference
  • Conventional wisdom (i.e. what do 'most other people' do?)
  • Consistency with existing code (If you're modifying someone else's code)
  • Style imposed by your employer/project leader (these are the only "rules" which exist)

If you really want a 'rule' to follow, then there's only one worth listening to, which is Be Consistent. i.e. don't write code in a whole mixed bag of styles - the most readable code is usually that which follows the same 'theme' throughout. If you can do this, then few people will complain, provided your code is well-formed.

You also might like to read this bit of advice from Bjarne Stroustrup http://www2.research.att.com/~bs/bs_faq2.html#coding-standard

Thanx.
But how can I know whether my code is well-formed?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Can a standalone programmer design large scale C++ projects?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
Can a standalone programmer design large scale C++ projects?


In theory, if said programmer is very experienced. However, experience does not come by learning "good coding style rules" by heart.

Aranarth
Posting Whiz in Training
253 posts since May 2010
Reputation Points: 155
Solved Threads: 47
 
In theory, if said programmer is very experienced. However, experience does not come by learning "good coding style rules" by heart.

Thanx.
So the alternative is to work with a large team?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

>>Can a standalone programmer design large scale C++ projects?

No because one person doesn't have the time to do it. It takes a team of people to design them so that the project gets the benefits of all their ideas and knowledge. I know Windows Word and the Windows operating system were not designed by just one person but by a large team of people.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I have a very large program in C++ that is running without any errors from the compiler. But how can I know whether the code is well formed and mantaining coding standards?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
I have a very large program in C++ that is running without any errors from the compiler. But how can I know whether the code is well formed and mantaining coding standards?


By looking at it. Seriously though, there is no such thing asthe coding standards. Quality of code isn't something that can be determined by a computer program on a scale of 100 or something.

Some things that might be indicators for bad code are the following:
- lots of manual memory and resource management
- heavy use of C strings
- nondescript variable and function names
- no logical class structure
- little or no error checking and input validation
- unnecessary use of platform-dependant solutions
- hard to read and badly structured code
- ...

But in the end only a moderately experienced C++ programmer can truly give a well-founded opinion on the quality of the code.

Aranarth
Posting Whiz in Training
253 posts since May 2010
Reputation Points: 155
Solved Threads: 47
 

But since the project is very big will it possible to change it according to the opinions of a moderately experienced programmer or shall I have to start new?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

How to acheive the coding standards in C++?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 


I think the issue here is first to define "big". What does that mean to you, size of an OS kernel (2million lines) , size of a big application (500,000 lines) etc. That gives you an idea of how much time a rewrite will take.

Next define the problem, why do you care how it is written: is it because you are not confident in the results or it crashes often etc., are you extending it to something else or adding functionality, or maybe you need to maintain it in its current state and just fix use bugs, or do you need your users to understand the code. [The latter is encountered say in scientific software, when you may need the users to see that the code implements the algorithms correctly]

The you want to define how complex the field of the program is, is it highly mathematical were algorithmic errors are likely, or maybe numerical rounding errors etc, or is it simpler [in algorithmic complexity] e.g. a GUI.

Once you and we have some of those answers this discussion can go forward. I seem to think that you don't need a c++ standard but more likely to want a static analysis, e.g. like the converity systems [note: useful but very very expensive]

Beyond that, I agree with the posts above, there is no such thing as "the standard", but a lot of things in a code that make me worry and the first one is lack of consistency. After that, poor use of const, lack of references, poor variable/method/class names, lack of comments [particularly around algorithms], overly larger dependence trees etc.

Layout etc, is nearly irrelevant, because I just pass it via a layout manager and it formats the code the way I like it. (e.g. opening/closing braces lined up etc), whilst other developers lay the code out differently, that way the team all work on code in a format they individually prefer.

StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
 
But since the project is very big will it possible to change it according to the opinions of a moderately experienced programmer or shall I have to start new?

Don't change a program just to improve its coding style. "Don't fix it if it ain't broken". If the program is already finished or nearly finished then make style changes only when something else needs to be changed.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Can a small team of less than moderately experienced programmers design large scale C++ software?

Supriyo
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
 
View similar articles that have also been tagged: