[Top][All Lists]

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

Re: Enhancement request: enabling Variant in C parsers

From: Rici Lake
Subject: Re: Enhancement request: enabling Variant in C parsers
Date: Thu, 25 Oct 2018 11:23:44 -0500

El jue., 25 oct. 2018 a las 3:21, Victor Khomenko (<
address@hidden>) escribió:

> Well, when in Rome do as Romans do... This chapter is for C/C++
> programmers, not Go. Some of them are not even familiar with the new
> syntax. If you check cppreference website, they don't use trailing return
> types unless absolutely necessary.
The use of trailing return types is definitely a style question, and I, for
one, side with Akim on this. I'm slowly training myself to use them
consistently in my new programs, spurred on by reflections such as this ACCU
post by Phil Nash
<https://blogs.accu.org/category/trailing-return-types/> (which
in turn references this thought-provoking post by Jon Kalb
<http://slashslash.info/2018/02/a-foolish-consistency/>, which addresses
the "historical practice" argument) and this Quora answer by David
And many others which would be tiresome to list. Clearly, these opinions
are not universally shared, but it seems to me that there is a movement
towards use of trailing return types (and deduced return types) and we
might as well get on board now. Or, at least, it is a legitimate option.

Returning functions is not the only case where trailing return types are
more readable (and even more concise). As you say, function return types
are relatively rare, although they are a lot more frequent than they used
to be. Much more common are the cases where there is a dependency on the
scope of the trailing return type, including the interesting case pointed
out by Vandervoorde (and by many others), where the fact that the trailing
return type is inside the class scope simplifies use of locally-visible

   1. template<class T>
   2. struct S {
   3.   using X = int;
   4.   auto f()->X;
   5. };
   6. template<class T>
   7. auto S<T>::f()->X {  // X is in scope here.
   8.   return 42;
   9. }

   Without the trailing return type, you would need:

   1. typename S<T>::X S<T>::f() { ... }

> On the philosophical note, I understand the reasoning in the blog you
> referenced, but I think it misses several important points. In its time, C
> blew other imperative languages out of the water, and one of the reasons
> was its conciseness. Trailing return types require two extra tokens, "auto"
> and "->", so most people will prefer the old syntax unless the trailing
> return type is the only way to declare a function.

(From reddit, tcbrindle in a comment on r/cpp

How to describe code:
>    - If it is longwinded but I like it, it's "explicit". If it's
>    longwinded and I don't like it, it's "verbose".
>    - If it's is short but I like it, it's "concise". If it's short and I
>    don't like it, it's "terse"
> :-)

(Smiley in original, too)

reply via email to

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