C++ Logo

SG20

Advanced search

Subject: Re: Constant initialization in C++20
From: Arthur O'Dwyer (arthur.j.odwyer_at_[hidden])
Date: 2019-06-20 18:12:32


On Thu, Jun 20, 2019 at 5:19 PM Mark A. Gibbs via SG20 <
sg20_at_[hidden]> wrote:

> On 2019-06-19 6:56 a.m., Christopher Di Bella wrote:
>
> I would encourage newer books and classes to introduce keywords as they
> become necessary. There's no need to spam students with a bunch of words
> that have no place in a relevant class. For example, I'd like to see
> reinterpret_cast, const_cast, and union no longer show up in introductory
> material. Not mentioning consteval and co there is also a good idea.
>
> I agree with the sentiment, but it doesn't seem practical in reality.
>
> When I teach beginners about what they can use as a legal identifier, I
> simplify it to "use only letters, numbers, and underscores, don't start
> with a number or underscore, oh, and don't use any of these", and then show
> the list of keywords and other reserved words. (Granted, this does lead
> some inquisitive people to ask "what does this do? what does that do?". I'm
> forced to brush them off so I can move on by saying something to the tune
> of "if you don't know what it does, you probably don't need it" or "when
> you need it, then you'll know what it does"... but that's something I have
> to do a lot when teaching C++ anyway.)
>
> Are there any other options for telling beginners what they can use for
> their variable/function/class/whatever names? Without showing them the list
> of keywords, how would they know they can't name something "union" or "
> register" or "default"?
>
Just try it out, and if it doesn't work, then don't do it.

C++ programmers have to learn not to name things all kinds of wacky names,
in practice.
Can't use `min` on Windows.
Can't use `R10` on MinGW.
https://github.com/zenorogue/hyperrogue/issues/30#issuecomment-366485573
Can't use `unix` on Linux.
https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html#System-specific-Predefined-Macros
Can't use `rad1` or `hyper` on MinGW-w64.
https://github.com/zenorogue/hyperrogue/pull/44/commits/034514778d06c37427696f70e0a6d04f25368eeb

None of those examples are "because it's a keyword."

And vice versa, you *can* name variables `final` or `override` or `module`,
but, *should* you?
On that note, are any students really out there wondering, "Is `consteval`
an acceptable name for this local variable?"?

(However, I am kibitzing only at the message I'm replying to. Re the
original post: yeah, `constinit` definitely should be an attribute. Eric
Fiselier even proposed it that way. It was committee'd by the committee.
And `consteval` has, as yet, no reason to exist. I certainly wouldn't teach
it, even if it survives into the release version of C++2a.)

–Arthur



SG20 list run by herb.sutter at gmail.com

Older Archives on Google Groups