r/cpp • • Jun 23 '18

East const Central

http://slashslash.info/eastconst/
0 Upvotes

42 comments sorted by

61

u/johannes1971 Jun 23 '18

The evangelism on what is just another stylistic choice is getting tiresome.

14

u/Ameisen vemips, avr, rendering, systems Jun 24 '18

Especially when they are a bunch of heretics going against the glorious Constodox Church.

-3

u/Middlewarian github.com/Ebenezer-group/onwards Jun 24 '18

13

u/Ameisen vemips, avr, rendering, systems Jun 24 '18

std::burn<std::stake>!

1

u/notyouravgredditor Jun 23 '18

I thought this was tongue-in-cheek...

-18

u/MotherOfTheShizznit Jun 23 '18

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.

21

u/[deleted] Jun 23 '18

What am I supposed to do with that frustrating sentiment?

Think more about creating actual business value for your paying customers.

-5

u/dodheim Jun 24 '18

Like promoting west const does? This post makes no sense.

10

u/Fyrenh8 Jun 24 '18

He's saying the waste of time is lamenting "there's an obviously correct choice and how can someone dare say it's just style."

-6

u/dodheim Jun 24 '18 edited Jun 24 '18

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.

4

u/doom_Oo7 Jun 24 '18

joke's on you I'm unemployed

11

u/johannes1971 Jun 24 '18

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++."

3

u/[deleted] Jun 24 '18

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.

4

u/johannes1971 Jun 25 '18

Dude, it was sarcasm. Check out the parent post.

1

u/[deleted] Jun 25 '18

Ah, haha, OK, s/condescension/sarcasm/. I didn't notice :D

3

u/doom_Oo7 Jun 24 '18

VT100 is dead, and so is the notion of printing source code;

sorry what ? source code is printed all the time.

4

u/johannes1971 Jun 25 '18

On an 80-column matrix printer, no doubt, using chain-fed paper with those cute alternating blue lines ;-)

3

u/[deleted] Jun 23 '18

Annoying for me are those ones that have gone one step further and turned style into logics.

15

u/aearphen {fmt} Jun 23 '18

If we are rewriting all the code to move const around then we should probably consider two other alternatives:

  • Both const (universal const) - requires changes to the standard but totally worth it to reconcile the conflicting styles:

    const int const i;
  • North const:

    const
     int i;

21

u/Ameisen vemips, avr, rendering, systems Jun 24 '18

I prefer infix const. con int st.

20

u/jcelerier ossia score Jun 23 '18

why not define types lisp-like

(* (const (int)) x;

... oh wait, we can (and notice how the const is west-side as a proof of the superiority of the system)

std::add_pointer_t<std::add_const_t<int>> x;

9

u/johannes1971 Jun 24 '18

North const

LOL :-)

I think to resolve this issue that now divides our community, we need a new standard. I propose uniform const:

auto a = {const 3};  // a has type 'const int const'
auto b = {const &a}; // b has type 'const int const * const'

5

u/aearphen {fmt} Jun 24 '18

Looks somewhat verbose. Wasn't there some proposal about natural (terse) const syntax?

6

u/thukydides0 Jun 23 '18

South-East const:

int
    const*
        const p;

4

u/cleroth Game Developer Jun 26 '18

You guys seem to have missed the part where reddit eats your newlines. :p

2

u/degski Jun 25 '18

Are you a flat-earther? Zenith const and nadir const should at least be made optional. ;-)

15

u/sumo952 Jun 23 '18

I hate (blog) posts without a date. Or am I blind?

In any case, wasn't this posted already a couple weeks or months ago?

12

u/[deleted] Jun 23 '18

Oh, the evangelist strike force strikes again.

- http://nosubstance.me/post/constant-bikeshedding/

1

u/meneldal2 Jun 25 '18

That title is interesting, can't guess if it's about bikeshedding that always happen or bikeshedding about const.

5

u/xENO_ Jun 24 '18

Obviously north const is the way to go. That is to say, follow every const with a line-feed. /s

16

u/doom_Oo7 Jun 23 '18

West const all the way

24

u/thukydides0 Jun 23 '18

You mean const West.

13

u/IcyWindows Jun 23 '18

I think part of the appeal is that the adjective goes first like in English. "const west" would be the east way to say it. ;)

3

u/[deleted] Jun 23 '18

Nailed it.

4

u/Daniela-E Living on C++ trunk, WG21|🇩🇪 NB Jun 23 '18

You've got it!

2

u/matthieum Jun 24 '18

As a French, were adjectives usually go after the name they qualify, I've always thought of English as backward ;)

4

u/[deleted] Jun 23 '18

Reppin' East Const till I die, yo. Throw up your span signs.

2

u/Kronikarz Jun 24 '18

My personal favorite is type const or template <typename T> using cnst = T const;

And then you get stuff like ptr<cnst<char>> str = "hello";

1

u/imMute Jul 07 '18

So basically std::add_pointer_t<std::add_const_t<int>> but with less typing and less standardization?

1

u/Kronikarz Jul 07 '18

Yes. I don't use it, really, as I am a fan of the verbosity, I just like the clean look of that syntax.