lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Parentheses vs braces round 2 (was: master 58b0c04 3/9: Sort c


From: Vadim Zeitlin
Subject: Re: [lmi] Parentheses vs braces round 2 (was: master 58b0c04 3/9: Sort columns alphabetically in TSV output)
Date: Fri, 28 Sep 2018 16:04:57 +0200

On Fri, 28 Sep 2018 00:23:36 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2018-09-27 20:37, Vadim Zeitlin wrote:
GC> > On Thu, 27 Sep 2018 12:53:50 -0400 (EDT) Greg Chicares <address@hidden> 
wrote:
GC> [...]
GC> > GC> +        std::map<std::string,std::vector<std::string>> 
ordered_stringvectors
GC> > GC> +            (stringvectors.begin()
GC> > GC> +            ,stringvectors.end()
GC> > GC> +            );
GC> > 
GC> >  That's another nitpick, but shouldn't be the parentheses above be braces,
GC> > i.e.
GC> > 
GC> >   std::map<std::string,std::vector<std::string>> ordered_stringvectors
GC> >       {stringvectors.begin()
GC> >       ,stringvectors.end()
GC> >       };
GC> > 
GC> > ? I don't think we can get into trouble with the initializer list ctor
GC> > overload here, as an iterator shouldn't be convertible to a pair (I 
hope?),
GC> > but please let me know if I'm missing anything.
GC> 
GC> Our discussions on this topic are still evolving, and there's room for
GC> them to evolve further; but IIRC the closest we've come to a rule is
GC> to use () when we're "calling" a special member function, as in
GC>   std::vector<int> v(10, 7); // Calls vector::vector(int len, T value).
GC> and to use {} when we're "moving" or "copying" a value, e.g.:
GC>   std::vector<int> v2 {v1};  // Calls vector::vector(vector const&).

 I misunderstood the current consensus then. I thought the rule was to use
"{}" if it was "trivial" initialization and "()" if it was something more
involved. For me, the initialization here is still "trivial", even though
it does involve iterating over the provided range. As an example of a
clearly non-trivial initialization, I'd suggest something like

        http_client client("https://xkcd.com/";);

where the ctor would open a network connection to the host extracted from
the URL: I think we can both agree that the use of braces would be
inappropriate in this case.

 Of course, there are many other cases in between these two extremes and it
might be not always obvious what is "trivial" and what isn't. But assuming
we could decide it, I think that use of parentheses vs braces based on this
consideration would be more valuable than the rule above, as the presence
of the former would indicate that something more complicated is happening.


GC> IIUC, you're suggesting a different rule: use {} unless it would be
GC> semantically incorrect--i.e., almost always. I'm not sure what
GC> "almost always" means; I only know that std::vector(count, value)
GC> is one exception, but I don't know what other exceptions may be
GC> necessary.

 No, I don't really suggest this, sorry for giving the wrong impression.
It's true that most ctors (and so maybe even "almost all" of them) should,
IMO, be "trivial", so the effect of my rule would be close to what you say,
but there is still place for non-trivial ctors too and those -- and only
those -- would still use parentheses.

 Regards,
VZ


reply via email to

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