4 ms·
What, you think the syntax is funny? I guess, but that's not a semantic pitfall.
by edflsafoiewq 5y ago
What, you think the syntax is funny? I guess, but that's not a semantic pitfall.
- tialaramex 5y agoPreviously 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.
- deleted 5y ago[deleted]
- edflsafoiewq 5y agoA 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.
- tialaramex 5y agoFair. 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.
- squeaky-clean 5y ago> 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.
- jcranmer 5y agoDo 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).
- tialaramex 5y agoI'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.
- agent327 5y agoActually 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.
- hnfong 5y agoI guess they mean the "syntax-semantic mismatch pitfall"? :)
- jmull 5y agoA pointless semantic argument about the word semantic... Thank you C++!