From: tony_in_da_uk on
Hi all,

Having overhauled thousands of lines of code in the last couple days,
I'm wondering what other C++ programmer's pet peeves are. I think
there's some small value in this, as hopefully some of us will see
things we do and stop, or have someone explain a pet peeve and it won't
bother us in future. Am I going mad? Anyway, here are a few of mine,
all trivial...

- consecutive streaming statements to the same stream, especially
when they flush the stream unnecessarily
(e.g. cout << "a " << a << endl;
cout << "b " << b << endl;)

- failure to take advantage of string literal concatenation
(e.g. cout << "ab" << "\n"
<< "xyz";
vs
cout << "ab\n"
"xyz";)

- people using const references to pass ints and bools

- people using ( and ) unnecessarily after return and sizeof

Cheers, Tony


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ulrich Eckhardt on
tony_in_da_uk(a)yahoo.co.uk wrote:
> Anyway, here are a few of mine, all trivial...
[...]
> - failure to take advantage of string literal concatenation
> (e.g. cout << "ab" << "\n"
> << "xyz";
> vs
> cout << "ab\n"
> "xyz";)

.... or not knowing at all about string literal concatenation. Other than
that, using double quotes to insert a single character into a stream. ;)

Over all, I share your feelings, although I'd like to point out that there
are worse errors and many more that drive me nuts, like forcing things that
don't describe an object into a class, redundant comments, not obeying the
'Law of Three', to name the ones I see most often. All of them don't cause
bugs by themselves but make code harder to read, debug and maintain.

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Torsten Robitzki on
tony_in_da_uk(a)yahoo.co.uk wrote:
> Hi all,
>
> Having overhauled thousands of lines of code in the last couple days,
> I'm wondering what other C++ programmer's pet peeves are. I think
> there's some small value in this, as hopefully some of us will see
> things we do and stop, or have someone explain a pet peeve and it won't
> bother us in future. Am I going mad? Anyway, here are a few of mine,
> all trivial...

I've saw checking if a container is empty before iterating over it
several times today:

if ( !v.empty() )
{
for ( v::iterator i ...)
...
;
}

Sometimes I see v.size() == 0 or even v == std::vector<int>() instead of
simply empty().

regards
Torsten

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: mzdude on
pet peeve is when programmers don't declare and init in the same
statement.

bool x; // unitialized variable, dangerous
x = MyFunction();

or better yet

bool x = false; // initialized, and then immediately overwritten
x = MyFuntion();
if( x == true ) {
// do something
}


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Palik Imre on
tony_in_da_uk(a)yahoo.co.uk writes:

> - people using ( and ) unnecessarily after return and sizeof

Some old sun compilers saying something like `Error: Unexpected type
name "DrvByte" encountered'. if you don't put those () after sizeof.

But there are worse things around than these small blemishes. I mean
couple hundred characters long code lines, in couple hundred lines
long methods, in a monolithic class, that also has a few friends
around, just to make the maintainer's life more miserable.

ImRe

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11
Prev: Special container
Next: map within map