[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ preferences (was: RFC: lalr1.cc: support move semantics)
From: |
Akim Demaille |
Subject: |
Re: C++ preferences (was: RFC: lalr1.cc: support move semantics) |
Date: |
Sat, 15 Sep 2018 06:41:52 +0200 |
Hi!
> Le 13 sept. 2018 à 13:13, Frank Heckenbach <address@hidden> a écrit :
>
> 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.
Local variables can be captured by lambdas and passed to coroutines.
In fact, I enjoyed so much ‘const’ on my variables, that I started
using a lot ‘IIFE’ (immediately invoked function expressions) to
be able to have this property more often. E.g.
const auto context = [&]
{
auto res = elle::serialization::Context{};
res.set<Doughnut*>(&this->doughnut());
res.set<elle::Version>(
elle_serialization_version(this->doughnut().version()));
return res;
}();
>> 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.
I agree.
> 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. :)
:) Indeed :)
I agree short lived entities should have short names. That’s
actually one benefit (the only one?) to have *.h and *.c files:
*.h files can expose intelligent meaningful names, while *.c can
use short names.
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
>
> But they don't have type declarations. ;)
Sure! But that’s the kind of conciseness I would love.
- Re: RFC: lalr1.cc: support move semantics, (continued)
- Re: RFC: lalr1.cc: support move semantics, Akim Demaille, 2018/09/13
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Frank Heckenbach, 2018/09/12
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Akim Demaille, 2018/09/13
- Re: C++ preferences, Hans Åberg, 2018/09/13
- Re: C++ preferences, Akim Demaille, 2018/09/13
- Re: C++ preferences, Hans Åberg, 2018/09/13
- Re: C++ preferences, Akim Demaille, 2018/09/13
- Re: C++ preferences, Hans Åberg, 2018/09/13
- Re: C++ preferences, Hans Åberg, 2018/09/13
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Frank Heckenbach, 2018/09/13
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics),
Akim Demaille <=
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Frank Heckenbach, 2018/09/15
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Akim Demaille, 2018/09/15
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Frank Heckenbach, 2018/09/15
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Akim Demaille, 2018/09/16
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Hans Åberg, 2018/09/13
- Re: C++ preferences (was: RFC: lalr1.cc: support move semantics), Akim Demaille, 2018/09/13
- Re: C++ preferences, Hans Åberg, 2018/09/13