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


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

Re: What a reference actually is

From Juha Nieminen <nospam@thanks.invalid>
Newsgroups comp.lang.c++
Subject Re: What a reference actually is
Date 2022-11-18 09:40 +0000
Organization Aioe.org NNTP Server
Message-ID <tl7ju8$1bu7$1@gioia.aioe.org> (permalink)
References <tl4t8h$1uqr$1@gioia.aioe.org> <e8f587a1-ac73-4b31-ad5f-5009c73ec4cfn@googlegroups.com>

Show all headers | View raw


Michael S <already5chosen@yahoo.com> wrote:
> For language that is so similar (nearly identical) to C at the level of
> "virtual machine", as is C++, the concept of reference is just unnecessary.

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. A 'for()' statement is unnecessary because you can write the same
thing using a 'while()' statement. And obviously the 'do' keyword is
completely unnecessary. As well as the 'switch' keyword. And why do we
even need a 'const' keyword at all? That could be easily dropped off.

We could easily drop half of C syntax as "unnecessary" and still be able
to write the same programs as before. Not to talk about C++!

> Don't use references in your code except when forced by interfaces that
> are out of your control! Then people that are going to read and comprehend
> your code will be thankful.

Actually references add useful abstraction to interfaces. For example,
when you write 'foobar(abc)', is that 'foobar' function taking the
parameter by value or by reference? It can decide! Whatever is best in
that particular function, it can choose. The calling code doesn't need to
tie its hands and force one or the other.

Moreover, if later it turns out that the function would need to change
how it takes the parameter (for example it originally took it by value,
but the type got a lot larger after a refactor, so now it would be more
efficient to take it by reference), it can do so without breaking any
code that's calling the function. (And no, "just fix all the places
where the function is called, by following the compiler errors" is not
a good solution because this may be a library used somewhere, and you
will be breaking the API, causing it to become incompatible with the
previous version, forcing every project that uses the library to fix
all the calls.)

Also, how do you suggest implementing copy constructors and operator
overloading without references?

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