Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# Java PHP Humor
I want to know the programming style of all good programmers all over the world.
Programmer in Microsoft C++, Programmer in Linux, companies and many good students, professors everywhere and anybody who thinks she/he is a good programmer.
 
In brief, I only want to have one criterion.
 
Example:
__STD::swap(_M_start, __x._M_start);
__STD::swap(_M_finish, __x._M_finish);
__STD::swap(_M_end_of_storage, __x._M_end_of_storage);
 
I don't like _ and __ and what do they mean.
Posted 6-Dec-09 3:00am
Edited 2-Jun-10 12:04pm
Moak11.4K
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

May be you'll not like my answer but ... there is no answer for such a question.
 
Programming style is somewhat personal. There can be guidelines in use in companies, communities etc. but -as far my experience is(30 yers of programming)- they are always more or less violated by their own programmers.
 
The only recommendation I can give is to find yourself a style that lets you comfortable and -more important- be coherent with it. Don't change it halfway in a file, project etc.
 
Serious companies and programmers will understand it and follow it when using your sources.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Emilio gave you a good answer.
 
One thing I can recommend is to follow the style of the standard library for the language you are using. For instance, with C or C++ that would be the K&R style[^] (yes, lots of underscores Smile | :) ).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I know that : There are many answers for one question like many styles in programming.
 
I am not easy when i read their code, because i don't know their style code. If they share code i think they should share programming style.
 
Many styles, but i want they are followed guidelines. Guidelines followed them, i don't care but i want to know when they share code.
 
I think if i know the rules, i will work better.
 
I always wait new answers. Thank all you.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Obviously, your example is from the C++ standard library.
the underline prefix __ is often seen in a library source.
because this style can avoid conflicting variable name with client code(the code using the library)
 
If not coding a library. I don't think this style is a good idea any more.
 
so, there is no criterion. just satisfy your needs.
think about it, what problem the style solves?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Look at the context of the code you're reading - it's taken from a standard library implementation and the authors wanted to make sure their code works with a wide variety of compilers. So for really old festering piles of bits that don't understand namespaces they can just do something like:
 
#define __STD
 
and hey presto it'll compile.
 
So why do they use double underscores? Well if you read the C++ standard you'll see that identifiers with two underscores ANYWHERE in the name are reserved. That means compiler vendors only. Using double underscores is a great way of a compiler vendor keeping their identifiers out of the collision scope of user programs.
 
Identifiers starting with single underscores are reserved for library vendors for the same reasons.
 
Cheers,
 
Ash
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 590
1 OriginalGriff 535
2 CPallini 285
3 Peter Leow 185
4 RyanDev 161
0 OriginalGriff 5,784
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,009
3 Maciej Los 2,894
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 2 Jun 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100