lua-users home
lua-l archive

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


Coda:

On Thu, Jul 25, 2019 at 9:54 PM Coda Highland <chighland@gmail.com> wrote:
> On Thu, Jul 25, 2019 at 2:47 PM Jasper Klein <jasper@klein.re> wrote:
>> Another example is C++17 that allows you to do something like:
>> if( auto foo = get_foo() ; foo.bar() == 42 )
>> {
>>    foo.baz( 1337 );
>> }
...
> The C++17 example also looks like something I would NEVER want to write. There's no compelling reason to put that on one line. Just kick the initializer out to the previous line, and add braces around it if you REALLY need the strict scoping.

Well, I would never WANT to write that, but I wouldn't want to write
the alternative block for scoping either. They are the same, each
approach has its merits, and in some cases I would prefer it. I.e., if
instead of that synthetic example you have something like this (
shamelessly cut&pasted from cppreference ):

std::map<int, std::string> m;
...
if (auto it = m.find(10); it != m.end()) { return it->second.size(); }

I would prefer it to the extra block approach ( although I would drop
the if braces, as I tend to not use them in this case ). I would do ti
because I always unravel and indent, and the alternative:
{
    auto it = m.find(10);
    if(it != m.end()) return it->second.size();
} // No braces in if to make lien comparison fair in my style.

Does not gain readabality, just looses screen real state, which I
prefer to use for blank lones where I deem it useful.

Also, I can read the if as easy as "for(auto i=m.begin(),e=m.end();
i!=e;++i)', its idiomatic, but YMMV.

Francisco Olarte.