Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #72291

Re: overuse of auto is dangerous

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: overuse of auto is dangerous
Date 2020-03-14 16:12 +0100
Organization A noiseless patient Spider
Message-ID <r4is8t$3b5$1@dont-email.me> (permalink)
References <r4eghj$j17$1@dont-email.me> <r4fm0n$rdv$1@dont-email.me> <EpJaG.606811$%G5.213848@fx03.am4> <r4g1ls$a1a$1@dont-email.me> <r4i44g$ls9$1@dont-email.me>

Show all headers | View raw


On 14/03/2020 09:20, jacobnavia wrote:
> Le 13/03/2020 à 14:26, David Brown a écrit :
>> If you don't like a language, don't use it.  If you don't know a
>> language, either learn about it or keep quite about it - it is pointless
>> to come to a language forum and complain about it.
> 
> Well, as a user of comp.lang.c I have been reading about the problems 
> with C by C++ heads since YEARS. They come to comp.lang.c to tell us how 
> bad C is and how good C++ is with various arguments. We listen politely 
> and answer them how do you do that in C, for instance when they say "C 
> is lacking xxx"

So you think two wrongs makes a right?  There are a few people who post 
regularly in c.l.c. about how bad or pointless C is, and why C++ or 
their own made-up language is vastly better.  These kinds of posts are 
as annoying as posts in c.l.c++ about how bad C++ is.  (It's one thing 
to discuss particular features, or to question the wisdom of current 
language directions - that's different from wide-ranging rants about how 
impossibly complicated the language is and other such posts.)

No, you don't have to listen politely to people complaining about C in 
c.l.c.  You can ignore them, point out their mistakes, or ask them to 
stop pointless posts.  (Again, there is nothing wrong with discussing a 
language or its features pros and cons.)

> 
> I haven't seen answers like "If you do not like C do not use it and go 
> away".

Such answers are not uncommon - I don't know how you missed them.

For most people, in most circumstances, there are choices about the 
tools and languages they use.  Occasionally as professional programmers, 
we have to work with languages we don't like, but if it is a long term 
issue, it would be better to try to change jobs (or change things at 
your current job) than to complain to innocent bystanders in a newsgroup.

> 
> In this particular thread I am asking about your awareness about "auto" 
> misfeatures and we seemed to agree that are problems with it.

I think everyone can see that it is a feature with advantages and 
disadvantages.  Use it appropriately, and don't use it inappropriately. 
The same could be said of pretty much every feature of every language.

> 
> I am not saying that C++ is a pile of shit or even that this construct 
> should be taken away... I am pointing to the problems with it in the 
> following context:
> 
> Many of the new features added to C++ aren't well THOUGHT OUT and 
> provoke more problems than the ones they try to solve!

I think you are wrong.  Some features have, in hindsight, had unexpected 
and unforeseen issues.  But that is not common, and not from lack of 
thought or effort.  More directly, however, I think you are not in a 
position to make a reasonable judgement - much less make the kind of 
absolute condemnations you write.  Instead of emotive posts full of 
capitals, exclamation marks, and accusations of incompetence in the C++ 
committee, perhaps you could ask other people where the find it useful, 
and where they see it as counter productive.

In fact, /asking/ people and listening to them, rather than making 
declarations from a position of ignorance or prejudice, is generally a 
good idea.

> 
> This is precisely why I think that continuing to add features each 3 
> years to an already highly complex language is a recipe for DISASTER!
> 
> I singled out two of them: structured binding and auto but there are 
> many more. Is it still possible to change the way the committee is working?
> 
> Instead of cheap polemic could you (maybe) reflect about that and 
> express your opinion about that?

I haven't made use of structured bindings as yet.  I see it as a 
somewhat convenient way to get multiple return values from functions. 
However, it is not ideal for me - I would prefer a method that named the 
parts, as it is too easy to get the order wrong.  (For the same reason, 
I am disappointed that C++ still has not got named parameters in 
function calls.)

auto foo(int x, int y) {
     struct { int sum; int prod; } r;

     r.sum = x + y;
     r.prod = x * y;

     return r;
}

int bar(int x, int y) {
     auto r = foo(x, y);
     return r.prod / r.sum;
}

int bar2(int x, int y) {
     auto [prod, sum] = foo(x, y);
     return prod / sum;
}

The "auto" in "foo" and "bar" makes the code a lot simpler and shorter, 
and saves providing a name for the multi-value return type.  This is a 
good thing, and a good use of "auto" (IMHO, of course).  "bar2" uses 
structured bindings, and shows the kind of subtle mistake that is easily 
made here.  (Unlike some of the mistakes you discussed about structured 
bindings, this mistake compiles fine so you get no help from the tools.)

However, AFAIK C++ currently gives no way to use such anonymous struct 
return types in functions with separate definitions and declarations.




Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-13 00:27 +0100
  Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-13 00:27 +0000
  Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-13 13:57 +1300
    Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-12 18:16 -0700
      Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-13 16:17 +1300
        Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-12 20:48 -0700
          Re: overuse of auto is dangerous "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-03-13 21:27 +0100
            Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-13 13:35 -0700
  Re: overuse of auto is dangerous Cholo Lennon <chololennon@hotmail.com> - 2020-03-12 22:06 -0300
  Re: overuse of auto is dangerous Bo Persson <bo@bo-persson.se> - 2020-03-13 03:17 +0100
    Re: overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-13 08:51 +0100
    Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-13 01:14 -0700
      Re: overuse of auto is dangerous Vir Campestris <vir.campestris@invalid.invalid> - 2020-03-16 21:35 +0000
        Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-17 11:49 +1300
    Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-13 21:27 +0100
  Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-13 11:07 +0100
    Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-13 10:39 +0000
      Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-13 14:26 +0100
        Re: overuse of auto is dangerous jacobnavia <jacob@jacob.remcomp.fr> - 2020-03-14 09:20 +0100
          Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-14 10:12 -0400
          Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-14 16:12 +0100
            Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-14 17:23 +0000
              Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-15 12:27 +0100
                Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-15 15:41 -0700
                Re: overuse of auto is dangerous Ian Collins <ian-news@hotmail.com> - 2020-03-16 13:37 +1300
                Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-16 07:26 +0000
                Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-16 07:05 -0400
                Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 12:32 +0100
                Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-16 08:21 -0400
                Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-16 11:27 +0000
                Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 09:11 +0100
                Re: overuse of auto is dangerous Bart <bc@freeuk.com> - 2020-03-16 11:44 +0000
                Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-03-16 13:29 +0100
                Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-16 05:35 -0700
                Re: overuse of auto is dangerous James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-16 09:16 -0400
                Re: overuse of auto is dangerous Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-02 07:13 -0700
                Re: overuse of auto is dangerous James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-02 07:45 -0700
                Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 10:25 -0700
                Re: overuse of auto is dangerous Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 12:49 -0700
                Re: overuse of auto is dangerous David Brown <david.brown@hesbynett.no> - 2020-04-05 14:15 +0200
                Re: overuse of auto is dangerous Paavo Helde <myfirstname@osa.pri.ee> - 2020-04-02 19:20 +0300
                Re: overuse of auto is dangerous Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 10:19 -0700
        Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-15 16:26 +0100
    Re: overuse of auto is dangerous Daniel <danielaparker@gmail.com> - 2020-03-13 07:27 -0700
      Re: overuse of auto is dangerous Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-13 21:22 +0000
      Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 04:53 +0000
        Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-14 03:23 -0700
          Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 13:20 +0000
            Re: overuse of auto is dangerous Öö Tiib <ootiib@hot.ee> - 2020-03-14 09:20 -0700
  Re: overuse of auto is dangerous Paavo Helde <myfirstname@osa.pri.ee> - 2020-03-13 13:53 +0200
  Re: overuse of auto is dangerous Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2020-03-13 15:46 +0000
  Re: overuse of auto is dangerous Sam <sam@email-scan.com> - 2020-03-13 23:09 -0400
  Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-14 08:06 +0100
    Re: overuse of auto is dangerous Melzzzzz <Melzzzzz@zzzzz.com> - 2020-03-14 13:16 +0000
      Re: overuse of auto is dangerous Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-16 15:31 +0100

csiph-web