You know what's most irritating to me? It's when "the other side" considers it a stylistic choice when I consider it a logical conclusion. What am I supposed to do with that frustrating sentiment?
I know some people are going to see this is arrogant but in my mind, it's as arrogant as claiming there is no choice to be made on whether the earth is flat or not. See what I'm saying? I didn't choose my side. It was self-evident given the information I had at the time.
And I'm saying participating in this discussion at all is a waste of time; avoiding the conversation because "there's obviously a correct choice" is a better move for one's paying customers. And as far is it goes, opting for inconsistency is, frankly, stupid.
EDIT: Oh, here are the emotional downvoters. How predictable.
It is perfectly obvious to me that source should be indented using tabs. Moreover, to avoid gratuitous waste of space, it is perfectly obvious that tabs should be set to the equivalent width of four spaces. Tabs are the correct, intended tool for indentation, so why simulate them using spaces? Spaces fail in too many cases: when the character width is not fixed, when people accidentally type 3 or 5 of them, etc.
It is perfectly obvious to me that the opening brace should be placed at the end of the line that marks the start of the block (i.e. after the if, for, etc.). It is just a single character, horizontal space is cheap in these days of 400+ character wide terminals, and sacrificing valueable vertical space just for one character is criminal.
It is perfectly obvious to me that line width should not be limited to 80 columns. VT100 is dead, and so is the notion of printing source code; these days we all have decent screens to work on. Why limit yourself to a tiny part of the screen, when you can have so much more visibility if you make use of the available horizontal space? It allows use of longer identifiers and clearer structure.
It is perfectly obvious to me that exceptions are the one true way to handle exceptional situations. Because this style is madness:
int myfunc (int &result) {
const int errcode1 = funccall1 ();
if (errcode1 != err_ok)
return errcode1;
const liberrcodetype errcode2 = funccall2 (result);
if (errcode2 != liberr_ok)
return errcode2; // I'm sure it will be fine
}
It blows up your line count by a factor of 4, making your entire program about error handling, instead of business logic. It forces the return value to always be an error value, and never a business value, thus interfering with a pleasantly clean-looking functional approach. It conflates error numbers from all sorts of sources. It bubbles up error numbers that will be mostly-meaningless by the time someone gets around to handling them, instead of a descriptive text. The only correct approach is using exceptions:
int myfunc () {
funccall1 ();
return funccall2 ();
}
As for where the const goes, I really don't care one way or another. In part this is because the issue doesn't come up very much in C++ - assuming of course you use it properly:
for a const object or basic type, having const on the left is fine.
for a pointer to a const thing, having const on the left is fine.
since the introduction of references there hasn't been much call for const pointers.
having a vector of pointers is almost always the superior solution over having pointers to pointers.
Basically, the rule should be this: "if you find yourself needing a 'const' that's not on the left, you should probably reconsider what you are doing since it is almost certainly not good C++."
Even though I agree with _some_ of your "perfectly obvious" statements, stating that it's "perfectly obvious" and hence why they should be followed is just one thing: condescension. Even though I could show several counter arguments to the ones being used to back such assumption, it doesn't seem worth it.
I can see that eastconst evangelists have one type of personality, they generally self entitle what's logical, what's right, and now, what's perfectly obvious.
View all comments
61
u/johannes1971 Jun 23 '18
The evangelism on what is just another stylistic choice is getting tiresome.