News for hackers. Stuff that matters.
Re:Less is Exponentially More (2012) by 0xcde4c3db on Friday March 09, 2018 @01:14AM (#16550079)
A C++ reference is basically a pointer that pretends to not be a pointer. If they have any efficiency advantage over const-correct pointers, I've never heard of it (though I'm at best an intermediate C++ programmer).

Points often cited as disadvantages of references include:

- There's nothing that clearly distinguishes them from regular variables at the point of use. They can therefore obscure the fact that you're not passing by value or mutating a local/member variable (particularly if you don't have good IDE support, and good IDE support for C++ is damn hard for some environments/toolchains/targets)

- There is no concept of a null reference, which can create friction with interfaces that use NULL for optional parameters

These points are also often cited as crucial advantages of references. So it goes.

Re:Less is Exponentially More (2012) by yuushi on Friday March 09, 2018 @02:34AM (#16550306)
The second is absolutely an advantage of references, and other than having to use (if I'm being honest, legacy and/or bad) interfaces, there is absolutely not a downside in this regard.

The first can be a legitimate complaint, although I find it's rarely an issue in practice.

Re:Less is Exponentially More (2012) by stevedonovan on Friday March 09, 2018 @05:43AM (#16550959)
Contrast with Rust references, which are very much their own type (they more resemble pointers in their behaviour, with explicit dereferencing and address-of needed). As a C++ dev, this took some getting used to! But I never was a fan of how passing-by-reference was invisible at the call site.
Re:Less is Exponentially More (2012) by TheCoelacanth on Friday March 09, 2018 @11:00AM (#16552615)
References being non-nullable is a huge advantage of references.

If you need the equivalent of a nullable reference, you can just use std::optional<std::reference_wrapper<T>> instead and make the nullability explicit.

Re:Less is Exponentially More (2012) by Retra on Friday March 09, 2018 @08:01PM (#16556469)
If we used std and wanted every type to be 50+ chars long to type, sure. Or we could just use a pointer, which just so happens is a nullable reference.