6 ms·
Deprecating Raw Pointers in C++20
- deleted 9y ago[deleted]
- jng 9y agoHacker News also doing April Fools now...
- jhanschoo 9y agoThis sounds to me like an April Fools joke, but the linked article on new new written on 26 March makes it sound like it's not...
- vasilipupkin 9y agoThank god, it's such a terrible idea, I started freaking out.
- shakna 9y agoThey link back from there to a April 1st post, however. > Additionally, I refer to the post C++ Will no Longer Have Pointers by Fluent C++ Following the trail of references just loops around a half dozen April 1st posts. With that, and nothing on the drafts [0], that I can see, I'm leaning towards joke. [0] https://github.com/cplusplus/draft https://github.com/cplusplus/draft
- mbel 9y agoThe 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.
- agumonkey 9y agomaybe HN should have a colored header line to remind people about this day and prevent reactions
- rndgermandude 9y agoThe entire point of April Fools is to fool people...
- deleted 9y ago[deleted]
- oh_sigh 9y agoIt isn't a world-wide holiday
- DoofusOfDeath 9y agoMaybe it should be :)
- krylon 9y agoI 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.
- FrankHB 9y agoNow 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 https://www.oschina.net/news/94805/deprecating-pointers
- misnome 9y agoI 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.
- dreta 9y agoIf i didn't read this comment section, i would've been convinced it's real.
- Koshkin 9y agoConsider it real. (Please.)
- codeflo 9y agoIt’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/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.
- jopsen 9y agoIt probably exists facilitate type parametrization of pointer implementations. Just a guess. That still crazy though :)
- _o_ 9y ago1. 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.
- lucidguppy 9y agoRaw 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.
- laumars 9y agoYour 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.
- deleted 9y ago[deleted]
- chi3 9y agoHonestly, 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).
- deleted 9y ago[deleted]
- enitihas 9y agoCan someone with more knowledge about c++ standard comment whether this is for real or it is an April Fools joke. Wouldn't this be an enormous change and probably break the language?
- ChrisSD 9y agoIt would break the C interface unless the spec had some kind of wrapper for such cases.
- mbel 9y agoIt seems to be a joke, they would have serious problem with backward compatibility with "this" pointer. Also it would limit the use cases for the language, unless they would introduce something like std::raw_ptr, which to be honest would be quite funny.
- evincarofautumn 9y agoHonestly this wouldn’t be a bad idea for consistency, teaching, and template programming purposes: namespace std { template<typename T> using raw_ptr = T*; } // mutable pointer to const value int const *a_old; std::raw_ptr<int const> a_new; std::raw_ptr<const int> a_new_var; // const pointer to mutable value int *const b_old; std::raw_ptr<int> const b_new; const std::raw_ptr<int> b_new_var; // const pointer to const value int const *const c_old; std::raw_ptr<int const> const c_new; const std::raw_ptr<const int> c_new_var; I’ve actually used this before to parameterise a struct/class with an ownership policy, for example: template<template<typename T, typename...> class P> struct Wrapper { P<int> value; }; Now Wrapper<std::raw_ptr> is a non-owning Wrapper, while Wrapper<std::unique_ptr> is an owning one.
- mehrdadn 9y agoIf it were for real how would you implement smart pointers?
- mbel 9y ago
- berkut 9y agoI hope this is a joke: the std::weak_ptr / std::shared_ptr combo (only non-reference alternative I can think of other than std::optional) can have pretty bad performance implications due to ref-counting atomics in multi-threaded scenarios... For the use-case of optional pointers that don't have any ownership (and can possibly be updated mid-lifetime) and have a guaranteed external lifetime, what's the alternative? Are there any other ways of doing this that are guaranteed to have no performance (time or memory) overhead in modern C++ (relying on by-value move semantics isn't ideal) ? Also, what about std:atomic (CAS) raw pointers - for high-performance / lockless stuff, they can be critical...
- mehwoot 9y agoFor the use-case of optional pointers that don't have any ownership (and can possibly be updated mid-lifetime) and have a guaranteed external lifetime Those three things seem like a pretty rare co-occurrence, if something has no ownership how can it have guaranteed external lifetime without being reference counted? I guess it's possible but in any scenario I come up with reference counting seems an easier way to do it.
- rosshemsley 9y agoThis could be a joke. Or not. It is very much in keeping with the current direction of C++, which appears to be: "Oh no, C++ cannot keep pace with modern systems languages, let's repair it by whatever means possible" Their heart is in the right place, but perhaps this accelerated process of mutating the language will ultimately be what kills it. Personally, after having deep expertise in C++(11/14) I jumped ship to Go and will _never_ look back...
- gmueckl 9y agoThere is nothing in C++ 11 and later that is forced on you. Everything that was added is optional. For personal projects I depend on some alternate implementations for things that are now in the STL because these not complete enough for my needs.
- pmorici 9y agoThat only works if you are working alone. In a real world team environment you can’t always enforce your preferences on your teammates
- gmueckl 9y agoI did not wrote these things for fun. I had a real need for each one. The STL is fine for the average case, but it is also limited. I hit these limitations.
- the_why_of_y 9y agoC++17 removed exception specifications from the language, and parts of the standard library, including std::auto_ptr and a lot of the <functional> header. https://isocpp.org/files/papers/p0636r0.html https://isocpp.org/files/papers/p0636r0.html
- deleted 9y ago[deleted]
- andrepd 9y ago>this accelerated process of mutating the language Oh we can't be talking about the same language x) C++ moves fast? They took until 2017 to remove trigraphs for crying out loud! Absolutely nothing in C++>=11 breaks anything in the language.
- ChrisSD 9y agoI guess a serious point is that modern C++ does "deprecate" raw pointers in the sense that their use is discouraged outside of interfacing with external libraries or old C++ code. But that's more the realm of linters than compiler warnings.
- xwvvvvwx 9y agoI'm not sure that's quite true. Raw pointers are fine if you need a nullable non-owning reference type.
- bumblebritches5 9y agoso tldr, the C haters have won in the process of rubyizing C++ for webdevs who literally could not care less about a language that they have absolutely no use for... I'm glad I decided against moving to C++
- chris_wot 9y agoLook at the date on the article...
- 2aa07e2 9y agoObvious joke is obvious. I looked at the date immediately after reading the title. Now, if that was to be discussed for C++23, that could indeed be plausible... yet still unlikely.
- neals 9y agoI've never done any real development with a language that uses pointers. So noob question: why would one use a pointer over passing a variable? (those are the two flavors right?)
- andrepd 9y agoThat's far too big a question to answer here, but consider for example writing a function thst modifies its arguments.
- em3rgent0rdr 9y agoWhen passing a pointer, if you want the resulting state of the variable, the function doesn't need to return a value. Also if the variable is a large object, then passing just a pointer to it saves time spent copying the object.
- Koshkin 9y agoI am sure parent meant "passing by reference". (In Oberon, for example, this is indicated by the VAR keyword.)
- mirekrusin 9y agoThere's absolutely no reason to use pointers, unmentioned detail is that c++20 will bundle v8's garbage collector in the runtime to support this removal.
- tomsmeding 9y agoThat's horrifying. And what's even more interesting is that C++11 even had a proposal for garbage collection, even if no-one implemented it.
- alephr 9y ago"The C++ Standard moves at a fast pace." Too obvious.
- MichaelMoser123 9y agoIn other news: Bjarne Stroustrup hast been fired by the C++ language committee, as one data member declared "we are sick and tired of this backard compatibility with C mantra, we all want to party like Rust!". Today everything is possible...
- sus_007 9y agoAnother blogger wrote about this : https://www.fluentcpp.com/2018/04/01/cpp-will-no-longer-have-pointers/ https://www.fluentcpp.com/2018/04/01/cpp-will-no-longer-have... Is this actually a joke ?
- erAck 9y agoNo, never.
- tomsmeding 9y agoYou can follow the links to more details, which goes to a different blog post. Each has another blog post as a source, and eventually comes back in a circle to the original one. This is most definitely an April Fool's joke.
- erAck 9y agoEventually C++ will be a well thought out standard.
- tomsmeding 9y agoIf you click on the "more details" link, you end up on a different blog post, saying some of the same things. Looks like it has a reference. But then that post also has a link to a source, which is another blog post, which links to another, which via a few more links back to this one. We have citogenesis[1] in actual action. [1] https://xkcd.com/978/ https://xkcd.com/978/
- titzer 9y agoIt's an April fool's day joke in the best tradition: a parody almost indistinguishable from truth. C++ has jumped the shark. Prima facie C was created as a portable assembly language that very nearly reflected the underlying hardware. Then C++ added new abstraction mechanisms on top of C, that were at first totally orthogonal: just classes and templates. One could still use all of C to get at the raw machine (raw pointers and peeking/poking). Then as abstraction envy grew to overcome C++, as it does every active language in time, C++ drifted farther and farther from its system-y roots. Fine. But in my day job, the only real reason to use C++ is because it's the only realistic choice as a systems language. I need to peek and poke memory, jump to raw machine code I've generated at runtime. This doesn't make me better or worse, it's just my use case (a virtual machine). As C++ becomes less and less capable of doing these low-level unsafe things (because too many people caused too much damage attempting this), and adds more ceremony to the old ways of peeking and poking memory, it becomes less useful to me. Who is it useful for? I'd argue that C++ has drifted off into some fantasy world where it believes it's a beautiful language full of nice, solid abstractions. But IMO it isn't--probably can't be--as all the abstractions break down, leaving us in the lurch, with neither good systems programming support nor good application-level abstraction.
- electrograv 9y ago> I'd argue that C++ has drifted off into some fantasy world where it believes it's a beautiful language full of nice, solid abstractions. But IMO it isn't--probably can't be--as all the abstractions break down, leaving us in the lurch, with neither good systems programming support nor good application-level abstraction. I’m not sure I’d say all the abstractions break down. If you and your team can agree on a subset of C++ features and patterns that work really well, you really can have some nice, clean code that yields both effective abstractions and good system-level results. The problem with C++ is that it’s effectively a giant pile of tools, that keeps getting new tools dumped on the pile every few years —- some of which meant to “replace” older tools, yet rarely remove any tools (for fear of breaking backwards compatibility). So the pile keeps getting bigger and bigger, until it some day collapses under its own weight of complexity (maybe). Skilled craftspeople can still use these tools to great effect, but there is at least an organizational overhead and danger from how cluttered and huge the set of tools is: every person or team may use a different subset of tools due to differing preference, not knowing about all the tools, not using some tools “properly”, using the “bad” tools, etc. etc.
- cesarb 9y agoHaving started using the Internet in the 90's, and thus still remembering Geocities-era websites, I loved that they did this as a webring (https://en.wikipedia.org/wiki/Webring https://en.wikipedia.org/wiki/Webring): each blog post has a link to the next one, making a singly-linked circular list. Starting with this one, we have: - http://www.bfilipek.com/2018/04/deprecating-pointers.html http://www.bfilipek.com/2018/04/deprecating-pointers.html - http://www.modernescpp.com/index.php/no-new-new http://www.modernescpp.com/index.php/no-new-new - https://www.fluentcpp.com/2018/04/01/cpp-will-no-longer-have-pointers/ https://www.fluentcpp.com/2018/04/01/cpp-will-no-longer-have... - https://blog.tartanllama.xyz/no-pointers/ https://blog.tartanllama.xyz/no-pointers/ - https://arne-mertz.de/2018/04/raw-pointers-are-gone/ https://arne-mertz.de/2018/04/raw-pointers-are-gone/ And it circles back to this one.
- Koshkin 9y agoOn a more serious note, raw pointers can be seen as practically deprecated in C++ since its inception (at least inside code that is not considered library or low-level).