3 ms·
If you don't know even the most basic concepts of a language like using strings for strings that's a problem in every language. You can use an array of chars in
by inglor 12y ago
If you don't know even the most basic concepts of a language like using strings for strings that's a problem in every language. You can use an array of chars in PHP and access it by a reference and then compare pointers if you _really_ want to but you don't see people ranting on that.
- loup-vaillant 12y agoIn C++, the following: "Hello, World!" …is a null terminated array of chars. When literal strings are not, in fact, strings, this is a problem with the language. It's confusing, you see? Underlying semantics nonwithstanding, how on Earth the followig works: (std::string)"foo" == "foo" and the following may not?! "foo" == "foo" These are not basic concepts. These are trivia. I know there are reasons for these confusing rules, but they're still confusing. You should not mock the programmer for forgetting them now and then.
- inglor 12y agoEvery language has quirks and issues - if you use raw char arrays like that in general purpose C++ without an extremely good reason that's not just forgetting and trivia that's a cultural issue. Just like you wouldn't see Python code relying on mutable default values or JavaScript value relying on `with` semantics or Java code relying on `URL` comparison through DNS very often - you shouldn't find code that relies on `"foo" == "foo"`. I'm sorry if my comments are harsh but I really do believe C++'s issues are mostly cultural.
- loup-vaillant 12y agoSo, accept the traps of the language as a fact of life, and just avoid them? No, that doesn't fly with me. Programming languages aren't Forces of Nature, they are human artefacts. They can be corrected. Of course you should never rely on `"foo" == "foo"` and other such things. Still, one would expect literal strings in the language to be of the preferred string type. C++ is the only language I know of that breaks this expectation. It does not follow the principle of least astonishment. That, is not a cultural issue. That said, I'm willing to accept that C++ do have cultural issues. Could you tell me what they are?