News for hackers. Stuff that matters.
Re:Deprecating Raw Pointers in C++20 by mbel on Sunday April 01, 2018 @06:14AM (#16727585)
The fact that this headline cannot be distinguished from April Fools joke by other commenters seems to say a lot about the direction in which C++ standard committee is heading.
Re:Deprecating Raw Pointers in C++20 by codeflo on Sunday April 01, 2018 @07:07AM (#16727707)
It’s not like the idea is completely crazy; pointer misuse is a big source of all kinds of problems, Rust shows how much can be done without constantly using raw pointers, and what are the C++ Core Guidelines if not an effort in exactly this direction?

I finally “got” that this is a joke when they discussed the future alternatives:

> For copyable and assignable references you can use std::reference_wrapper. (http://en.cppreference.com/w/cpp/utility/functional/referenc...)

and thought, ha ha, an “assignable reference” instead of a “pointer”, that’s obviously completely different. :) What a subtle joke!

Only now I see that reference_wrapper is apparently completely real and exists since C++11. Why does this even exist? My head hurts from banging it against the desk.

Re:Deprecating Raw Pointers in C++20 by evincarofautumn on Sunday April 01, 2018 @07:39AM (#16727782)
In all seriousness, reference_wrapper lets you:

1. Have a container of non-null references. As the example in your cppreference link shows, that’s convenient for efficiently providing multiple “views” of the same values.

2. Pass a value with reference semantics to a function that takes an argument by value. Mainly useful to avoid copying or reuse a function object.

3. Explicitly say “this is a reference to something I don’t own”, complementing unique_ptr’s “reference to something I own exclusively”, shared_ptr’s “reference to something I share ownership of”, and raw pointers’ “reference to something I may or may not own”.

Re:Deprecating Raw Pointers in C++20 by netheril96 on Sunday April 01, 2018 @07:41AM (#16727786)
> Why does this even exist?

When you use `std::bind` or `std::thread`, the arguments you pass are captured and stored by value. What if you want it to be captured as reference? You use a `std::reference_warpper` instead. Note you cannot use a pointer here because the type won't match, while `reference_wrapper` implicitly converts.

Re:Deprecating Raw Pointers in C++20 by _o_ on Sunday April 01, 2018 @07:31AM (#16727760)
1. April joke :)

The point of c/c++ in comparision to other languages is that you can do anything and having a huge toolbox for that. Pointers are excelent sledgehammer. You can be perfectly fine with not using them but c++ need to have them. The pointers are not source of the problem, the developer is. That's why languages like java are prospering, it prevent incompetent people making stupid mistakes and that is fine. But some people need and want freedom that c++ offers.

Re:Deprecating Raw Pointers in C++20 by laumars on Sunday April 01, 2018 @08:39AM (#16727959)
Your point may be technically accurate but the elitism of the tone completely undermines it's point because even the best of us can and do write code with errors in it. I mean just look at all the mature code out there written by experienced developers which fails fuzz testing.

I've been writing software for close on 30 years and I know damn well how easy it is to make mistakes. Even on days when I think I'm in the zone, there will be occasions when I'll go back to it and think "WTF was I thinking?" when it bombs out of the first round of automated testing.

Re:Deprecating Raw Pointers in C++20 by FrankHB on Sunday April 01, 2018 @10:13PM (#16731802)
The problem is that pointers almost totally violate the single responsibility principle.

Technically, the only dependencies on pointers are types of the allocation/deallocation functions which are mandated in ISO C++ even for freestanding implementations (not the case in ISO C), and their derivations (new-expressions, etc). All other sane uses of pointers should be replaced by some better alternatives when appropriate (shared_ptr, unique_ptr, observer_ptr, reference, reference_wrapper without type completeness requirement, uintptr_t, iterator, etc).

In that sense every pointer is a badly designed variant type; basically each occurrence of a pointer would likely be mostly incorrect (or not correct enough) in program semantics. I always treat that vagueness as a can of worms, so even merely replacing pointer by observer_ptr somewhere makes a big win to me. There do exist real costs like verbosity and bloating of binary size, but they have to be paid for sin of the father. The ship has sailed too far in a regretful direction; but this is not the excuse to fix it - which is one source of the problem from many developers.

Re:Deprecating Raw Pointers in C++20 by pjmlp on Sunday April 01, 2018 @09:43AM (#16728208)
You can have languages that prevent people making stupid mistakes and still offer full control over the hardware, that is what languages like Modula-2 and Ada offer.
Re:Deprecating Raw Pointers in C++20 by evincarofautumn on Sunday April 01, 2018 @09:58AM (#16728267)
Yeah, also Rust and ATS. A good systems language just needs to allow low-level and unsafe operations; nowadays the industry is warming up to the idea that such operations shouldn’t be available by default. Having to opt in with a machine-checked “unsafe” annotation means you have an explicit indication in the code of everywhere things could go wrong with type/memory safety, which means when something does go wrong, you know it must be caused by one of those unsafe regions.
Re:Deprecating Raw Pointers in C++20 by lucidguppy on Sunday April 01, 2018 @07:37AM (#16727774)
Raw pointers are like "transporter scalpel" used by star trek doctors. When used with care it does the job and does it well.

You need plenty of tests and valgrind.

Its dangerous for most programmers to be cavalier with owning raw pointers. If we aren't we'll get another Java.

Re:Deprecating Raw Pointers in C++20 by andrepd on Sunday April 01, 2018 @07:44AM (#16727790)
cppreference explains it pretty well:

>std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object. It is frequently used as a mechanism to store references inside standard containers (like std::vector) which cannot normally hold references.

>Specifically, std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference [...] of type T. Instances of std::reference_wrapper are objects (they can be copied or stored in containers) but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference.

Sounds pretty reasonable and useful to me. No need for over-the-top head banging :)

Re:Deprecating Raw Pointers in C++20 by mannykannot on Sunday April 01, 2018 @09:15AM (#16728110)
It is also an example of a sort of 'combinatorial pump' that inflates the language's complexity, as each new feature needs to work with every existing one. It is my guess that it is C++'s multi-paradigm flexibility that makes this both possible and necessary.
Re:Deprecating Raw Pointers in C++20 by jopsen on Sunday April 01, 2018 @07:20AM (#16727740)
It probably exists facilitate type parametrization of pointer implementations. Just a guess.

That still crazy though :)

Re:Deprecating Raw Pointers in C++20 by agumonkey on Sunday April 01, 2018 @06:18AM (#16727596)
maybe HN should have a colored header line to remind people about this day and prevent reactions
Re:Deprecating Raw Pointers in C++20 by misnome on Sunday April 01, 2018 @08:22AM (#16727895)
I don’t think they are disallowed, but think most of them end up getting downvoted out of distaste (the annoying and useless April 1sts was one of the reasons I left slashdot years ago).

Obviously this one is either believed, or believed to be amusingly subtle. Either way, I agree it should be at least [Joke] flagged.

Re:Deprecating Raw Pointers in C++20 by rndgermandude on Sunday April 01, 2018 @06:44AM (#16727655)
The entire point of April Fools is to fool people...
Re:Deprecating Raw Pointers in C++20 by oh_sigh on Sunday April 01, 2018 @07:38AM (#16727780)
It isn't a world-wide holiday
Re:Deprecating Raw Pointers in C++20 by krylon on Sunday April 01, 2018 @10:55AM (#16728580)
I remember reading about China making April Fools illegal after some major mishap where many people took a joke seriously. I was never sure if that was for real or satire.
Re:Deprecating Raw Pointers in C++20 by FrankHB on Sunday April 01, 2018 @09:36PM (#16731635)
Now they should be surely aware of that.

FYI, here was one of Chinese translation of the article, but the contents was just deleted 10 minutes ago:

https://www.oschina.net/news/94805/deprecating-pointers

Re:Deprecating Raw Pointers in C++20 by DoofusOfDeath on Sunday April 01, 2018 @09:19AM (#16728127)
Maybe it should be :)
Re:Deprecating Raw Pointers in C++20 by chi3 on Sunday April 01, 2018 @09:17AM (#16728119)
Honestly, anyone with C++ experience should understand that it's a joke just from the title. I'm honestly surprised so many people thought this could be true; even Rust has raw pointers (in unsafe mode).
Re:Deprecating Raw Pointers in C++20 by dreta on Sunday April 01, 2018 @06:23AM (#16727614)
If i didn't read this comment section, i would've been convinced it's real.
Re:Deprecating Raw Pointers in C++20 by Koshkin on Sunday April 01, 2018 @12:00PM (#16728928)
Consider it real. (Please.)