News for hackers. Stuff that matters.
Re:What =delete means by SavantIdiot on Monday October 18, 2021 @09:46AM (#28905385)
I'm so done with C++. When a fundamental keyword becomes a semantic pitfall, you've created an esoteric niche for enthusiasts, not a useful tool.
Re:What =delete means by simias on Monday October 18, 2021 @10:24AM (#28905711)
I must say that I'm always a bit in awe when I read modern C++ and I realize that I barely understand what's going on even though ~10 years ago I considered that it was the language I knew best. And even back then it was already a sprawling monster of a language. Nowadays the idea of having to maintain a large C++ codebase scares me. Too many footguns and arcane knowledge required.
Re:What =delete means by kllrnohj on Monday October 18, 2021 @10:34AM (#28905821)
Eh? '=delete' is a bad example of "footgun" or "arcane knowledge". There are those in C++, sure, but this isn't one of them.

You can happily never know the existence of '=delete' and nothing about your code changes. And if you ever hit a libraries usage of it, like the standard library, you get a pretty clear error message at compile time instead of an actual footgun in C++98 like memory corruption or runtime crashes.

'=delete' is basically the entire reason why std::unique_ptr is safe and std::auto_ptr is a footgun. It reduces the ammo aimed at yourself & the amount of knowledge you need to know (like the knowledge to never put auto_ptr in a vector)

Re:What =delete means by simias on Monday October 18, 2021 @02:31PM (#28909396)
I was talking generally, not for this particular feature. But it would still be sort of arcane knowledge for me since when I last actively used C++ `=delete` either didn't exist or was not in common use, so if I encountered it in some codebase I'd probably guess what it does but still have no idea about the implications.

Like, are there other =<something> construct? Is it overridable or overloadable by the user? Can I use it to "erase" any member of a class, for instance to hide a parent member from an inherited class?

I suspect that the answer to all of these questions is "no", but I can't know for sure without deep diving into some C++ ref.

In the C++ I knew there was nothing resembling this syntax, and `delete` was only the keyword you used to free memory.

Re:What =delete means by cesarb on Monday October 18, 2021 @02:44PM (#28909639)
> Like, are there other =<something> construct?

Yes, there's "= 0" to mark a virtual method as not implemented in this class (that is, it must be implemented by a subclass), which is older than "= delete". Conceptually, it sets the corresponding slot in the virtual method table to null instead of a pointer to the (non-existent) method, except that it actually doesn't do that, it sets that slot to a pointer to a "pure virtual method called" function from the standard library, which AFAIK prints an error message and exits the program (IIRC, this is because there are some situations in which you can actually manage to call such a pure virtual method, like calling it from a function called within the constructor or destructor of the base class.)

Re:What =delete means by jdsully on Monday October 18, 2021 @02:56PM (#28909886)
A concrete object must implement all virtual methods including those marked as pure virtual. All =0 means is that someone else lower down the inheretence chain will implement this and the caller using the class type can rely on it existing.

If you try to instantiate an object without all methods implemented you'll get a compiler error about the class being "abstract". You should never have a case where there's a null in the vtable.

If there is some specific edge case around ctors then forgive me - this is C++ after all! But in practice you don't have to worry about this which is true for most of the C++ minutia.

Re:What =delete means by cesarb on Monday October 18, 2021 @06:17PM (#28912522)
> If there is some specific edge case around ctors then forgive me - this is C++ after all!

Yes, the specific edge case is around ctors and dtors. During the ctor or the dtor, the vtable is the vtable of the base class, not the derived class, so if you call a virtual function within the ctor or dtor of the base class (don't do that), the function which will be called is the one from the (possibly abstract) base class. See for instance this FAQ entry: https://isocpp.org/wiki/faq/strange-inheritance#calling-virt...

Re:What =delete means by kllrnohj on Monday October 18, 2021 @02:55PM (#28909859)
I would argue that's just "knowledge" not "arcane knowledge". To me arcane knowledge is stuff like the xvalues, prvalues, etc... Where it's both complex and obscure. Where you can go down a headache-inducing rabbit hole. This isn't really that, it's pretty simple, and really only does that single thing. It doesn't have complex interactions with anything else: https://en.cppreference.com/w/cpp/language/function#Deleted_...

As a sibling mentioned, it's not even a new syntax as '= 0' has always been there.

Re:What =delete means by gpderetta on Monday October 18, 2021 @03:58PM (#28910781)
In addition to =0 mentioned elsethread, there is also =default which will force the generation of a default function that would be otherwise suporesed.

You can use =delete to delete any overload of a function, be it class member or namespace scope.

Languages evolve; =delete and default were added to get rid if a bunch of common hacks and the language is better for that (at least for delete, default has a bunch of pitfalls of its own unfortunately).

Re:What =delete means by carpenecopinum on Monday October 18, 2021 @10:05AM (#28905543)
If a language feature being weird is enough to declare that you're "done with it", you won't have too many languages to work with in the end. Maybe some LISP, I guess?

You don't become a good craftsman by rejecting every tool that isn't perfect. You become one by knowing your tools and their flaws and strengths well.

Re:What =delete means by SavantIdiot on Monday October 18, 2021 @10:13AM (#28905608)
> You become one by knowing your tools and their flaws and strengths well.

Yes, that's why I said "I" am done with it, not "you should be done with it." There's no need for me to use it ever. Except when forced to with mbed, TFLiteMicro, and the occasional port of an Arduino driver to C.

I've been at this since before C++ existed. I've watched it come in to the world, and I've watched it mutate, Akira-like, into an academic omphaloskepsis.

EDIT: Fun story: I learned C++ in ... 1990? ... by watching a series of videos on VHS tape taught by none other than Bjarne Stroustrup himself. I think it was a bonus that came with the purchase of the first version of the Borland C++ compiler for OS/2.

Re:What =delete means by mikepurvis on Monday October 18, 2021 @09:50AM (#28905421)
I think for most of us mere mortals, the only normal use for =delete is making a class non-copyable. And for that, my muscle memory is already wired to inheriting from boost::noncopyable anyway.
Re:What =delete means by jpm48 on Monday October 18, 2021 @10:32AM (#28905792)
I put

private : myclass(const &myclass )=delete;

Just to be safe :-)

Re:What =delete means by ziml77 on Monday October 18, 2021 @12:41PM (#28907529)
Funny thing there is that one could read that as saying that the copy constructor's deletion is private and therefore still accessible in the public interface. I wouldn't put it past C++ to do something as crazy as that.
Re:What =delete means by bialpio on Monday October 18, 2021 @05:32PM (#28912054)
IIRC this will make the compiler error less helpful than it could be? I think you'd get an "attempt to use private member" instead of "attempt to use deleted member". End result is probably the same, but it feels like you're not saying what you mean with the code.

Edit: NVM, looks like all major compilers will say that the copy ctor is deleted. https://godbolt.org/z/jTd3714Tb

Re:What =delete means by Psychlist on Monday October 18, 2021 @06:54PM (#28912843)
clang-tidy will ask that you put in the full set.

  Foo() = delete;
  Foo(const Foo& orig) = delete;
  Foo(Foo&& orig) = delete;
  Foo operator=(const Foo &other) = delete;
  Foo operator=(Foo &&other) = delete;
(add const to taste)
Re:What =delete means by pansa2 on Monday October 18, 2021 @10:01AM (#28905513)
> I'm so done with C++.

But what to use instead? Especially in an industry like game engine development, where C++ is basically all there is (and almost all there’s ever been)?

Are we forever going to be stuck with every company trying to reduce complexity by defining their own custom subset of C++?

Re:What =delete means by dahart on Monday October 18, 2021 @10:29AM (#28905760)
> Are we forever going to be stuck with every company trying to reduce complexity by defining their own custom subset of C++?

Yes, probably? In 30 years of professional coding and a decade of game engine development, I’ve never seen that not be the case, all the companies I’ve been at and all the companies I know about limit their C++ to a subset to try to control complexity.

I’m curious if you’re suggesting it would be better to increase complexity by allowing all of C++? There are definitely features I don’t trust everyone with.

Complexity combined with engineer hubris is one of the big problems with C++. While working in games, I witnessed many people overengineering and being too clever by half, and costing the team time and money. One of the most memorable bugs I ever tracked down while working in games was a release-build only crash where a programmer had tried to get fancy with a copy constructor and bungled it unknowingly. We had a team of 10 people working over a weekend trying to catch it and I had to write a custom debugger to trap the call stack. The cost of his trickery was easily in the several tens of thousands of dollars at least. It only takes that happening a few times before you realize C++ is a foot-gun in many (most? all?) hands.

Re:What =delete means by pansa2 on Monday October 18, 2021 @10:45AM (#28905946)
> I’m curious if you’re suggesting it would be better to increase complexity by allowing all of C++?

No, definitely not. I’m wondering if there might be a language on the horizon that’s suitable for game engine development but which is substantially less complex than C++.

Or, if not, is there an effort to rally round a particular subset of C++ instead of everyone defining their own? In your experience, have the C++ subsets used in different companies been very similar, or quite different?

Re:What =delete means by TuringTest on Monday October 18, 2021 @12:20PM (#28907211)
> No, definitely not. I’m wondering if there might be a language on the horizon that’s suitable for game engine development but which is substantially less complex than C++. Or, if not, is there an effort to rally round a particular subset of C++ instead of everyone defining their own?

If it doesn't exist, it should be created and called --C.

(C-- is already taken) https://en.wikipedia.org/wiki/C--

Re:What =delete means by jerf on Monday October 18, 2021 @10:20AM (#28905678)
The places where you must use C++ are a dwindling niche. Large niches in their own right, certainly, but niches. Once you leave those niches there is an explosion of possibilities.

I'm coming up on year 25 of my career and I haven't touched C++ since school, if one can indeed call what is covered in school C++. Especially nowadays. And C and Java I've barely touched. I certainly couldn't put them on my resume with a straight face.

I say this because you kind of sound like you're making some sort of plaintive plea, as if C++ is somehow the only viable option in the world and who could even dream of stepping outside of it? And I'm telling you that while that may be true in an ever-decreasing set of niches, it is not true in general anymore and hasn't been for a long time.

Re:What =delete means by fullstop on Monday October 18, 2021 @10:09AM (#28905574)
Someone is going to say Rust, and I might agree with them at some point in the future.

I periodically check https://www.areweguiyet.com/ to see the state of things, but C++ is still king here.

I cut my teeth on C++ but was then employed to write code in C. After almost two decades of doing this, C++ looks vastly different to what I remember from 2001 and kind of ugly to me. I'm sure, however, if I had stuck with C++ for the last twenty years it would feel like home.

Re:What =delete means by professoretc on Monday October 18, 2021 @05:12PM (#28911828)
> Are we forever going to be stuck with every company trying to reduce complexity by defining their own custom subset of C++?

The problem with doing this is the same as with the idea that one "90% of people only use 10% of Excel's features" so we should be able to make a simpler Excel and capture 90% of the market: all those people use a different 10% subset. It's the same with C++; everyone wants a "simpler" language, but no one agrees on what should be kept and what should be thrown out. C++ is the language that results from putting together everything that everyone needs (and then dealing with the resulting conflicts and contradictions).

Re:What =delete means by SavantIdiot on Monday October 18, 2021 @10:08AM (#28905571)
I didn't say "You can't use it," I said "I" am done with it.

Have fun! Write some cool games!

Re:What =delete means by pansa2 on Monday October 18, 2021 @06:50PM (#28912811)
Thanks for the encouragement, it’s appreciated.
Re:What =delete means by swalls on Monday October 18, 2021 @10:28AM (#28905754)
in the future, I think Jai looks pretty good, as a language designed for game dev, considering they're basically battle testing it by shipping a large 3d game in it... if the compiler ever gets released. I think 7 years of streamed development from Jonathan Blow?
Re:What =delete means by nynx on Monday October 18, 2021 @10:05AM (#28905536)
The main alternative is likely rust.
Re:What =delete means by criddell on Monday October 18, 2021 @10:10AM (#28905584)
Are you saying that for game engine development, Rust is the second most popular option?
Re:What =delete means by jcelerier on Monday October 18, 2021 @10:19AM (#28905666)
> I'm so done with C++. When a fundamental keyword becomes a semantic pitfall, you've created an esoteric niche for enthusiasts, not a useful tool.

you think quux wouldn't be able to find semantic pitfalls in literally every language you would use instead ?

Re:What =delete means by tux3 on Monday October 18, 2021 @10:22AM (#28905689)
Some language designs have more semantic pitfalls than others. All else equals, those would be preferable.

C++ is an old beast with many many footguns.

There's a more modern subset hiding inside, these days, but let's not pretend every language has the same pitfalls that C++ has.

Re:What =delete means by jcelerier on Monday October 18, 2021 @10:25AM (#28905725)
sure, but there's also a deep culture in the C++ blogosphere to go and seek the deepest and darkest corners and exhibit them as it's a very fun puzzle game. the same people applied to Python, Java or LISP would yield endless articles on pitfalls of those
Re:What =delete means by tragomaskhalos on Monday October 18, 2021 @04:16PM (#28911073)
In the early 90's there were two print magazines: "The C++ Report" and "The Smalltalk Report". The former, even with the far simpler language it was then, was chock full of programming arcana and 'what does this code do?' type puzzles. The latter, by contrast, had effectively zero such content. I loved both languages but this difference was always very stark.
Re:What =delete means by SanFranManDan on Monday October 18, 2021 @10:34AM (#28905829)
If they are endless where are they?
Re:What =delete means by pjmlp on Monday October 18, 2021 @11:50AM (#28906779)
Search for Java Puzzles books
Re:What =delete means by edflsafoiewq on Monday October 18, 2021 @10:02AM (#28905518)
What is the semantic pitfall here?
Re:What =delete means by tialaramex on Monday October 18, 2021 @10:19AM (#28905658)
C++ has a keyword, "delete" which originally refers to an operator that destroys objects, thus calling their destructor and giving back resources (most obviously memory) allocated for their lifetime.

But, adding keywords to C++ is expensive. You can't use these as symbols, you can't name a class, a variable, a function or anything "delete" because that's a keyword and so it's reserved. A new keyword would clobber existing symbols, and that's painful, so, C++ tries not to do it, instead repurposing existing keywords.

So as well as the operator named "delete" now "delete" refers to this feature where you can tell the compiler that this particular overload mustn't be used, if it was looking for an overload, it won't use this because you explicitly said not to (even if it could have otherwise conjured a default) and if somebody else called it by mistake now they get a compile error saying not to.

I don't think they would naturally have written =delete if not for being conscious that doing so is "free" (the word is already reserved for something else) whereas some other word would have caused compatibility problems.

Re:What =delete means by edflsafoiewq on Monday October 18, 2021 @10:25AM (#28905723)
What, you think the syntax is funny? I guess, but that's not a semantic pitfall.
Re:What =delete means by tialaramex on Monday October 18, 2021 @10:33AM (#28905811)
Previously delete referred to an operator

Today delete is both the operator and this entirely unrelated feature, so that alters the meaning, a matter of semantics.

Natural languages have plenty of such ambiguity, but C++ has a Committee (yes I know about French, no the Académie Française doesn't actually get to decide how French works, that's not how natural languages work) which could have chosen to use a different word and did not.

Re:What =delete means by edflsafoiewq on Monday October 18, 2021 @10:51AM (#28906017)
A semantic pitfall would be something where you think the code means one thing (a patch of grass) but it really means another (you fall into the spikes). =delete is neither; it is not possible to confuse it for operator delete, and I don't see even a hole to get your foot stuck in, let alone any spikes.
Re:What =delete means by tialaramex on Monday October 18, 2021 @11:46AM (#28906716)
Fair. I wouldn't have chosen the phrase "semantic pitfall", however after some thought I think it would classify as a "hole to get your foot stuck in" because it's unexpected in an artificial language to have this. If you're a learner and you covered "delete" the operator last week, then missed a day, and now there's = delete on the slides, do you raise your hand to ask what's this completely new syntax? No, right, it must somehow be the delete operator you learned about, as otherwise it would have a different name... wouldn't it?

But sure, C++ does have actual hidden spike traps, where unwary programmers are going to hurt themselves badly by mistake and this is not one of those.

Re:What =delete means by squeaky-clean on Monday October 18, 2021 @01:26PM (#28908052)
> it is not possible to confuse it for operator delete,

I haven't written C++ in many years and my interpretation of the code examples before reading the rest of the article was that it was somehow binding it to the delete operator as a function.

Re:What =delete means by jcranmer on Monday October 18, 2021 @11:42AM (#28906646)
Do you also complain that the operator named '*' is overloaded? As a binary operator, it means to perform a multiplication operator. As an unary operator, it means to load the value located at that memory address, which has nothing to do with anything close to multiplication. That is a more gross alteration of semantics than the use of a keyword in completely different slots (as an expression versus as a declarator).
Re:What =delete means by tialaramex on Monday October 18, 2021 @12:02PM (#28906967)
I'm not a fan of your example with the asterisk or of the reference operator sharing a symbol with the binary AND operator.

I don't like the use of + for concatenation much either, even though it's overloaded to do that in some languages I really like, and it's even special cased despite the lack of overloading in one language I think is fairly good (Java) and some others I've used but think are garbage.

But I'm willing to cut some more slack for symbols because they're short.

I think erase for example would have been a better choice here (I haven't spent long thinking about this, the committee had months), but C++ had to worry about the backwards compatibility penalty and that's... sad.

Re:What =delete means by agent327 on Monday October 18, 2021 @02:18PM (#28909124)
Actually it would have been a contextual keyword, meaning it could be any word the committee wanted it to be, and it is only recognized as such in this particular context (i.e. at the end of a function declaration). They could have chosen anything they wanted, but decided that '=delete' was fine.

Other examples of contextual keywords are 'final' and 'override', which may also occur on function declarations.

Re:What =delete means by jmull on Monday October 18, 2021 @10:48AM (#28905978)
A pointless semantic argument about the word semantic... Thank you C++!
Re:What =delete means by hnfong on Monday October 18, 2021 @10:36AM (#28905845)
I guess they mean the "syntax-semantic mismatch pitfall"? :)
Re:What =delete means by cesarb on Monday October 18, 2021 @06:25PM (#28912583)
> A new keyword would clobber existing symbols, and that's painful, so, C++ tries not to do it, instead repurposing existing keywords.

It's even more painful than that. A new keyword could conflict with a macro. So even contextual keywords (something which is a keyword only in a place where arbitrary symbols are not allowed, so there's no conflict) could be problematic.

Re:What =delete means by beached_whale on Monday October 18, 2021 @10:14AM (#28905623)
For almost everyone, none. delete doesn’t remove the method from the overload set, it leaves it there in order to give the caller an error saying don’t do that.
Re:What =delete means by klyrs on Monday October 18, 2021 @11:34AM (#28906524)
It also prevents the compiler from emitting a default implementation for the deleted method.
Re:What =delete means by agent327 on Monday October 18, 2021 @02:07PM (#28908850)
It's just a piece of programming knowledge being explained. It's very far from a 'semantic pitfall' or an 'esoteric niche'. Don't be such a drama queen.
Re:What =delete means by pjmlp on Monday October 18, 2021 @11:47AM (#28906737)
Until one delves into all the cool niche features being added into Java, C#, F#, Python,...., even C.

Unless we are talking about v1.0 there always such cases when a language is around long enough.

Re:What =delete means by kccqzy on Monday October 18, 2021 @01:01PM (#28907767)
How is it a pitfall? The article clearly elucidates several uses of the "=delete" construct. I don't see any pitfalls, just some new uses of the feature. And I expect most people to be the same: most people only ever use "=delete" on the copy constructor and the copy assignment operator, now this article tells them you can actually use it on other things too. There's no pit to fall into, just new ways to use a feature.
Re:What =delete means by gpderetta on Monday October 18, 2021 @10:35AM (#28905833)
There is no semantic pitfall in = delete. = default on the other hand...
Re:What =delete means by enriquto on Monday October 18, 2021 @10:24AM (#28905716)
> I'm so done with C++. When a fundamental keyword becomes a semantic pitfall, you've created an esoteric niche for enthusiasts

but it always was!

Re:What =delete means by codebolt on Monday October 18, 2021 @03:39PM (#28910523)
I'm with you. The only thing = delete means to me is that I'm happy C++ isn't part of my dayjob.