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


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

Re: What a reference actually is

Newsgroups comp.lang.c++
Date 2022-11-19 15:43 -0800
References (5 earlier) <1fa49f55-80ce-45de-80da-708da2ebc783n@googlegroups.com> <cc18485f-f734-4aaa-be94-998123825020n@googlegroups.com> <tlbo8k$3amai$2@dont-email.me> <6c66d3d3-e9aa-430c-95b8-661d4a0237cfn@googlegroups.com> <39896c16-022b-4fb3-baa4-948a5a80f032n@googlegroups.com>
Message-ID <ea85ea60-bece-45be-be2f-99551dbae902n@googlegroups.com> (permalink)
Subject Re: What a reference actually is
From Öö Tiib <ootiib@hot.ee>

Show all headers | View raw


On Sunday, 20 November 2022 at 01:36:50 UTC+2, Michael S wrote:
> On Sunday, November 20, 2022 at 1:33:16 AM UTC+2, Öö Tiib wrote: 
> > On Sunday, 20 November 2022 at 01:18:59 UTC+2, Chris M. Thomasson wrote: 
> > > On 11/19/2022 3:13 PM, Öö Tiib wrote: 
> > > > On Saturday, 19 November 2022 at 18:21:05 UTC+2, Michael S wrote: 
> > > >> On Saturday, November 19, 2022 at 9:34:32 AM UTC+2, james...@alumni.caltech.edu wrote: 
> > > >>> On 11/18/22 06:23, Michael S wrote: 
> > > >>>> On Friday, November 18, 2022 at 11:40:43 AM UTC+2, Juha Nieminen wrote: 
> > > >>> ... 
> > > >>>>> If we start dismissing everything that one could deem "unnecessary" 
> > > >>>>> then we could start dropping off quite many features even from C itself. 
> > > >>>>> After all, for example the syntax 'a[b]' is just syntactic sugar for 
> > > >>>>> '*(a+b)', and thus the former is "unnecessary" and could just be 
> > > >>>>> dropped off. 
> > > >>>> 
> > > >>>> The [] variant is shorter by 2 characters. In DRM view, shortness of 
> > > >>>> most frequently used language features was of high priority. 
> > > >>>> Also, in slightly more complex expressions, in case of *(a+b) variant 
> > > >>>> reader has to look for more information in order to figure out which 
> > > >>>> of two homonyms 
> > > >>>> of * is actually used. I would speculate that DRM was not really 
> > > >>>> pleased with 
> > > >>>> using asterisk for dereference, but had no better choice in available 
> > > >>>> character set. 
> > > >>>> 
> > > >>>> A 'for()' statement is unnecessary because you can write the same 
> > > >>>>> thing using a 'while()' statement. 
> > > >>>> 
> > > >>>> Except that 'continue' behave differently. 
> > > >>>> The better argument is that 'while' loops are unnecessary and that is 
> > > >>>> absolutely correct. A mistake on part of DRM. 
> > > >>>> 
> > > >>>>> And obviously the 'do' keyword is completely unnecessary. 
> > > >>>> 
> > > >>>> I don't see it. Please elaborate. 
> > > >>>> 
> > > >>>>> As well as the 'switch' keyword. 
> > > >>>> 
> > > >>>> What alternative do have in mind? if-else-if chains? 
> > > >>>> Both more typing and intentions of using the same selection variable 
> > > >>>> for all choices is not pronounced clearly. 
> > > >>> I get the impression that you've missed his point. He's not arguing that 
> > > >>> C would be made better by dropping all of those things. He's pointing 
> > > >>> out that just because something is not necessary, is not a reason for 
> > > >>> dropping it from the language. It is precisely his point that the 
> > > >>> language would be less easy to use if these features were removed for no 
> > > >>> better reason than the fact that they are unnecessary. 
> > > >> I don't know about your or Juha, but I personally draw a line at DRY. 
> > > >> Features that help to DRY can be controversial, can be even harmful, 
> > > >> (as many preprocessor macros) but they are not nutrient-free syntactic 
> > > >> sugar. 
> > > >> Of all features of 'C' listed by Juha, only 'while' and 'const' do not help 
> > > >> DRY at all and only [] help it minimally, but [] obviously help other aspects 
> > > >> of readability. 
> > > >> C++ references do not help DRY at all, except if you consider & here 
> > > >> or * there as repeating yourself. And, IMHO, presence of references 
> > > >> in the language makes understanding somebody else's code 
> > > >> significantly harder. 
> > > > 
> > > > Pointer can be null, so everywhere it is passed has to check that it is 
> > > > not null and that gets quite repetitive to do after a while. 
> > > 
> > > Or, a lib writer can say passing a null pointer into function void* 
> > > foo(void*) will result in undefined behavior. 
> > So caller has to check, that is even worse violation of DRY as a function is 
> > usually called from multiple places. Meanwhile lib writer can accept a 
> > reference and then the check is needed on neither side.
> No, caller does not have to check, because caller knows that he passes non-null.

About reference it is known that it is not null but about pointer it is known only
after checking  ... like if the caller is he or she takes checking.
 

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


Thread

What a reference actually is Juha Nieminen <nospam@thanks.invalid> - 2022-11-17 09:01 +0000
  Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-17 06:09 -0800
    Re: What a reference actually is Paavo Helde <eesnimi@osa.pri.ee> - 2022-11-18 00:36 +0200
      Re: What a reference actually is JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-11-18 07:49 +0200
      Re: What a reference actually is Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-11-20 05:48 -0800
    Re: What a reference actually is Juha Nieminen <nospam@thanks.invalid> - 2022-11-18 09:40 +0000
      Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-18 03:23 -0800
        Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-18 05:11 -0800
        Re: What a reference actually is James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-11-19 02:34 -0500
          Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-19 08:20 -0800
            Re: What a reference actually is Paavo Helde <eesnimi@osa.pri.ee> - 2022-11-20 00:37 +0200
              Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-19 15:35 -0800
            Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-19 15:13 -0800
              Re: What a reference actually is "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-19 15:18 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-19 15:33 -0800
                Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-19 15:36 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-19 15:43 -0800
                Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-19 15:51 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-19 17:57 -0800
                Re: What a reference actually is "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-19 19:56 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-20 03:47 -0800
                Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-20 04:24 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-20 06:32 -0800
                Re: What a reference actually is "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-21 16:32 -0800
                Re: What a reference actually is Öö Tiib <ootiib@hot.ee> - 2022-11-22 08:30 -0800
              Re: What a reference actually is Michael S <already5chosen@yahoo.com> - 2022-11-19 15:27 -0800
                Re: What a reference actually is Paavo Helde <eesnimi@osa.pri.ee> - 2022-11-20 01:28 +0200
      Re: What a reference actually is Paavo Helde <eesnimi@osa.pri.ee> - 2022-11-18 14:51 +0200
        Re: What a reference actually is JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-11-18 18:32 +0200
        Re: What a reference actually is Juha Nieminen <nospam@thanks.invalid> - 2022-11-21 11:56 +0000
  Re: What a reference actually is Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-17 19:27 +0100
  Re: What a reference actually is Jorgen Grahn <grahn+nntp@snipabacken.se> - 2022-11-19 17:10 +0000
    Re: What a reference actually is Juha Nieminen <nospam@thanks.invalid> - 2022-11-21 11:59 +0000

csiph-web