[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ preferences (was: RFC: support move semantics)

From: Frank Heckenbach
Subject: Re: C++ preferences (was: RFC: support move semantics)
Date: Thu, 13 Sep 2018 13:13:34 +0200

Akim Demaille wrote:

> > I do admit I usually don't declare my local variables const though
> > they often should be
> I recently had to work on some piece of software with coroutines,
> and known what variables are immutable was really reassuring.

I haven't done coroutines, but threads, and of course, everything
that's exposed there, I make as const as possible. But that doesn't
usually include local variables.

> In my code I usually try to having the smallest possible scopes
> for variables, more for readability than quick destruction, and

Me too.

> I now spread `const` for similar reason: help the reader.

I think it's double-edged. OT1H, when the reader is trying to
understand the code in detail, it certainly helps; OT2H on casual
quick reading, too much verbosity can distract, especially for code
that is not that complex. So as I said, with a more concise syntax,
it would be a no-brainer to me, but as things are, I often prefer
shorter code. (For a similar reason, I also prefer "i" to
"FoobarLoopCounter"; short names are quicker to parse mentally, and
with small scopes there's no big danger of forgetting what the
variables are, and of course, as a mathematician I'm used to short
index variable names anyway. :)

> > but
> > if "const" with implied "auto" can simply work, that would be great.
> > But we're not designing C++ here, I know ...
> I recently changed works, and have to deal with JavaScript.
> They have const!  But they also have let, and it means something
> different...

But they don't have type declarations. ;) I'm not trying to argue
about names ("let", ":=", simple "const" or whatever), I'd just like
to have a single thing that declares constness and auto-type (which
really is the most common combination I need for local variables).

Hans Åberg wrote:

> There is Unicode U+2254 COLON EQUALS if one dares leaving the
> ASCII range, which in fact I am using in my own language, for
> definitions and Hoare logic code.

Whether C++ should go Unicode (apart from char/string literals) is
another can of worms. Anyway, the token ":=" is also unused in C++
so far (":" "=" doesn't occur in any valid syntax AFAIK).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]