News for hackers. Stuff that matters.
Re:Less is Exponentially More (2012) by segmondy on Thursday March 08, 2018 @10:44PM (#16549652)
I don't think I will say that's the advantage of C++, but rather the perceive advantage of C++. Anytime I've met a great C++ programmer, they start off by ratting of a list of C++ features they don't use.
Re:Less is Exponentially More (2012) by Retra on Thursday March 08, 2018 @10:54PM (#16549691)
At my work, we don't use the standard library and we don't use references. And it's the only C++ code base I've ever liked working on.
Re:Less is Exponentially More (2012) by gowld on Friday March 09, 2018 @12:15AM (#16549951)
How can you write efficient programs without references? And why are references so painful for you anyway?
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.
Re:Less is Exponentially More (2012) by Retra on Friday March 09, 2018 @08:08PM (#16556494)
We have to use pointers for various reasons. Legacy interfaces use them all over the place, so we continue to do so, and they don't really work like pointers at all, so they're horribly inconsistent. Boilerplate things like conditional & partial initialization require jumping through hoops to get working for references. We also have lots of shared & cached objects, so everything needs to be validated anyway, you don't really gain much by knowing a pointer isn't null.
Re:Less is Exponentially More (2012) by yuushi on Friday March 09, 2018 @02:31AM (#16550294)
Out of curiosity, what do you use? I hope it isn't back to raw pointers and size_t offsets for lengths. What do you do if you want to pass a container of ... anything around? What's the replacement for:

   U do_something(const std::vector<T>& vec);
Re:Less is Exponentially More (2012) by JamesLeonis on Friday March 09, 2018 @11:15AM (#16552746)
Raw pointers can still be used for pass-by-reference without size.

    U do_something(std::vector<T> const *vec) {
        T item = (*vec)[1];
        ...;
    }
We can get away with this because the type `std::vector<T>` is known at compile time. It goes back to C and passing pointers of structs all over the place.

The const on the right side makes sure the compiler keeps the memory at the pointed location safe like the const used in your initial question.

Re:Less is Exponentially More (2012) by yuushi on Friday March 09, 2018 @03:00PM (#16554497)
Sure, you can pass by pointer instead of reference, but the post also mentioned that they didn't use the STL (hence no std::vector) and I'm curious if that means they used a replacement library or something else.
Re:Less is Exponentially More (2012) by nwatson on Friday March 09, 2018 @04:14AM (#16550598)
My guess: they effectively turned C++ into Python with everything allocated from heap and wrapped with shared pointers ... and custom iterators and collections like old-style RogueWave Tools.h++.
Re:Less is Exponentially More (2012) by kbwt on Friday March 09, 2018 @08:24AM (#16551517)
Not OP but...

    output_type do_something(buffer_view input);