48
votes
12answers
3k views

Is it reasonable to null guard every single dereferenced pointer?

At a new job, I've been getting flagged in code reviews for code like this: PowerManager::PowerManager(IMsgSender* msgSender) : msgSender_(msgSender) { } void PowerManager::SignalShutdown() { ...
4
votes
3answers
274 views

Is it OK to use same variable to store similar stuff sequentially? [duplicate]

Say I have a variable name len in a function and several strings. Can I use this to store length of those strings one after the other or should I create separate variables? Basically this: size_t ...
6
votes
6answers
619 views

Should my team use some common well-regarded coding standard as a basis for own own?

The R&D team I'm in has decided to adopt a coding standard. We have only recently formed, and have too little code and common coding time of our own to base our standards/conventions document on ...
4
votes
2answers
657 views

Java naming conventions vs. C++/C naming conventions

I am a Java developer who is starting to pick up more and more C++/C (yes I know they're different, bear with me). One thing that struck me as odd was the different naming conventions used by these ...
1
vote
4answers
1k views

Is using `continue`, `break` in non-`switch` loops and `?:` bad practice? [duplicate]

Back in college I've been told that using break; and continue; outside switch statements (e.g. to escape for or while loops) is wrong, bad practice and bad habits at the same time because it only ...
-1
votes
1answer
423 views

What is the C++ convention, if any, for naming to differentiate between structure types and other types? [closed]

In general, should I use some sort of convention for structure names which is distinct from other type name? I was thinking about this when my professor started talking about structures. I had the ...
1
vote
1answer
297 views

Where does the “mm” come from in GTKmm, glibmm, etc

I understand that the "mm" suffix [in various GTK-associated C++ binding libraries] means "minus minus," but where exactly does it come from? I understand that there is a programming language called ...
12
votes
4answers
634 views

Co-worker uses ridiculous commenting convention, how to cope? [closed]

A co-worker in the small start-up I work at writes (C++) code like this: // some class class SomeClass { // c'tor SomeClass(); // d'tor ~SomeClass(); // some function void ...
10
votes
7answers
957 views

In C and C++, what methods can prevent accidental use of the assignment(=) where equivalence(==) is needed?

In C and C++, it is very easy to write the following code with a serious error. char responseChar = getchar(); int confirmExit = 'y' == tolower(responseChar); if (confirmExit = 1) { exit(0); } ...
2
votes
4answers
324 views

What kind of interface should a double container offer?

I want to write a class which offers two sequences of elements to its users. The first one (lets call it "primary") is the main of the class and will be use 80% of the time. The second one (lets call ...
17
votes
13answers
2k views

Is it an appropriate use of #define to make typing repeated code easier?

Is there any view on whether using the #define to define full lines of code for simplifying coding is good or bad programming practice? For example, if I needed to print a bunch of words together, I'd ...
3
votes
7answers
4k views

Is there a common capitalization convention in C++?

I do a lot of work in Python and Java, and both those languages have fairly common (though not universal) conventions on how capitalization should be used in identifiers: both use PascalCase for class ...
2
votes
3answers
476 views

What are pros and cons of using temporary “references”?

In C and C++ (and I guess other languages that allow taking a "reference" to an array element or something similar), when you have an array like type, accessing individual elements of such an array ...
10
votes
8answers
9k views

Best practices for constants

How do you guys handle constants, especially in Java (static final) and C++ (define)? Do you use dedicated headers (C++) or classes (Java) for all constants? Do you turn all literal values into ...
3
votes
4answers
1k views

C/C++: Who uses the logical operator macros from iso646.h and why?

There has been some debate at work about using the merits of using the alternative spellings for C/C++ logical operators in iso646.h: and && and_eq &= bitand & bitor ...
9
votes
9answers
439 views

Studies on code documentation productivity gains/losses

After much searching, I have failed to answer a basic question pertaining to an assumed known in the software development world: WHAT IS KNOWN: Enforcing a strict policy on adequate code ...
8
votes
9answers
2k views

What C++ coding standard do you use? [closed]

For some time now, I've been unable to settle on a coding standard and use it concistently between projects. When starting a new project, I tend to change some things around (add a space there, remove ...