On 03/15/2017 04:38 PM, Alex Rousskov wrote: > On 03/15/2017 06:57 AM, Adam Majer wrote: >> If you really want to fix this, avoid `auto` in code people actually >> want to maintain. The only place it is actually useful is in heavily >> templated code and that is the main reason it was introduced. It was not >> introduced so you can avoid typing the name of POS (plain old >> structures) or types or classes. > > I disagree on all counts. Auto is much more nuanced. The web has a lot > more pro- and cons- arguments about auto, including advice from C++ > gurus. For example: > https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/
I would disagree with you on these accounts and with Mayers (if that is actually his position) auto has its place and that place is generally when dealing with templates, and especially in templates where types are not fixed in the definition. So auto simplifies boilerplate. It's a very good feature. Sure, you are more than welcome to replace every instance of type with auto, but don't be very surprised when few weeks from now you are looking at a piece of code and want to know what structure something comes from and then tracing things through the code just because you wanted to use auto instead of `Foo`. But arguing this kind of reminds of trying to argue with someone that for loops are not dead because you can now do everything with std::algorithm and lambdas. It's not very productive. C++ is a statically typed language and auto does not make that go away. > In my personal experience, going against Sutter and Mayers advice > usually ends up in long-term regrets. They are sometimes wrong, but it > is usually much easier to fix their wrongs than mine. (Just like with > Squid or any other development, it is often about making good mistakes > versus the bad ones.) Let's just say just because someone is famous and knows a few things does not imply others don't know things. I've learned on my own skin that hiding types can cause serious problems, but maybe it's just me. Cheers, Adam _______________________________________________ squid-dev mailing list [email protected] http://lists.squid-cache.org/listinfo/squid-dev
