C++ and Ranting

I was reading the C++ FQA, C++ Frequently Questioned Answers. It’s a C++-hater rant, cleverly disguised as a point-by-point refutation of the C++ FAQ Lite (which happens to be, for example, the top Google result for “C++ FAQ”).

Let me repeat that: The C++ FAQ Lite is the top Google result (in my world, that translates to “most popular and important”) result for C++ FAQ. If someone is told to “read the FAQ”, this is what they’re likely to read. Let us assume, for the sake of discussion, that this is not the result of a Google bomb — that most C++ bloggers and wiki-writers think this is the best link.

Why do I think that this assumption is not trivial? Because of this:

[18.8] What does “const X& x” mean?

const X& x and X const& x are equivalent. The real question is which should be used.

Answer: absolutely no one should pretend they can make decisions for your organization until they know something about your organization. One size does not fit all; there is no “right” answer for all organizations, so do not allow anyone to make a knee-jerk decision in either direction. “Think” is not a four-letter word.

Yes, this reader. This is not a joke. The FAQ actually tries to say with a straight face that the form of const usage is a business issue. A business issue? Seriously? They think that it matters to a business which is used, other than it be consistent?

Sometimes, saying something like “this is a mistake in the language definition, but it’s really redundant — just pick some version, and be consistent about it” is more honorable than continuing:

Use a style that is appropriate for your organization’s average maintenance programmer. Not the gurus, not the morons, but the average maintenance programmer. Unless you’re willing to fire them and hire new ones, make sure that they understand your code.

Really? Really? They think it that different programmers have different ways of coping with the placement of a FREAKIN’ CONST QUALIFIER???

When I read the FQA, I assumed they were quoting out of context. They’re not. Neither am I. The FAQ is, actually, that silly.

6 Responses to C++ and Ranting

  1. Alon says:

    c++; /* this makes c bigger but returns the old value */

  2. עדי סתיו says:

    I’m flabbergasted.

    But… The FAQ subtly suggests[1] that the move to the “X const& x” is a new fashion, and that “const X& x” was what old programmers used to do, and so I must assume that it resulted from a more general move to postfix rather than prefix “const” keyword. Now why is that? Do you know of some known advantage to prefix const? Perhaps the old postfix const was the “mistake in the language specification” that you referred to?

    [1] Which is impressively unhelpful. FAQs should be very explicit, detail the underlying assumptions, and explain the results. They should not show passive-aggressive attitudes like “well, if you can’t see that for yourself then I’m certainly not going to tell you”.

  3. Jamu says:

    The section you’ve quoted does sound very strange, indeed. What they should have said was:

    Always put const to the right of the thing that is const. It makes it easy to understand what the code means, for example:

    int const – A const integer
    int const& – A reference to a const integer
    int& const – A const reference to a mutable integer
    int const* const – A const pointer to a const integer
    int* const – A const pointer to a mutable integer

    This simple “const affects the thing to the left” rule makes code more readable and you don’t end up scratching your head trying to figure out how things work.

  4. Evan says:

    Ha! I like that Jamu actually answers the question that the FAQ goes on and on nonsensically about.

    If I ask what something means in code, I don’t need someone telling me about style guidelines or that I should think or that I should be writing style that fits the average guy (I have no idea what that even means). Just tell me the answer.

    Good job Jamu.

  5. Elazar Leibovich says:

    The logic of “coding standard relates to business decision” is, since the question of what to do, relates to the actual state of your code.

    Say, if you’re already having lots of code in standard A, just stick to the standard.

    If you’re having a lot of code in standard A which you think is inferior, some code in standard B which you think is superior. Then you might want to put the time to convert A to B and make B the standard (waste lots of time, but better standard), or convert B to A, and make A the standard. Or decide standard doesn’t matter so much in this case, and let everyone do what they want (no time lost, least quality of standard).

    Depends how much you think this coding standard is important, and how many resources you have.

  6. Xamuel says:

    Here’s a very concise C++ FAQ:

    Q: Why would anybody use this crufty language?
    A: It’s a mystery science will never solve. Use C instead.

Leave a comment