6 ms·
And so I will continue to avoid C++ because I'm not a master and will not avoid the many pitfals, and I want to get things done, not become a master of C++.
by rando3826 11y ago
And so I will continue to avoid C++ because I'm not a master and will not avoid the many pitfals, and I want to get things done, not become a master of C++.
- a3n 11y agoWhat a strange language, that so much sage wisdom involves what parts of it you shouldn't use. (Former C++ programmer, a long time ago, before the "don't use these parts" advice became a thing.)
- derefr 11y agoThere was a post here recently, explaining type systems are effectively about restricting you from encoding nonsensical constructions. C is ASM with the ability to encode some nonsensical ASM instruction-sequences removed, etc. The weird thing about C++—and the reason it didn't just absorb/replace C—is that it gives you the ability to encode strictly more nonsensical things than C does. In that sense, C looks more like the descendant of C++ than the other way around!
- pjmlp 11y ago> The weird thing about C++—and the reason it didn't just absorb/replace C—is that it gives you the ability to encode strictly more nonsensical things than C does. In that sense, C looks more like the descendant of C++ than the other way around! Yet the most famous current C compilers are all written in C++. If it wasn't the rise of open source and its community attachment to C, mainly in GNU and BSD circles, C would have been long replaced except for the embedded space.
- gridspy 11y agoYes, it shares that 'feature' in common with JavaScript.
- bajsejohannes 11y agoNo, actually, it doesn't. C++ is a huge language, javascript is a relativly small one. I know it's funny to compare the size of "Javascript the good parts" with "Javascript the definitive guide", but that's can be attributed to writing style more than percentage of language covered.
- MaulingMonkey 11y ago> No, actually, it doesn't. Perhaps less in what features to avoid, but there's plenty of hidden gotchas to avoid in JavaScript still. https://www.youtube.com/watch?v=et8xNAc2ic8 https://www.youtube.com/watch?v=et8xNAc2ic8 https://dorey.github.io/JavaScript-Equality-Table/ https://dorey.github.io/JavaScript-Equality-Table/ > C++ is a huge language, javascript is a relativly small one. C++'s ISO/IEC 14882:2003 weighs in at 786 pages, compared to ECMA-262 (5.1 Edition)'s 258 pages (measuring by PDF reader). A ~3x difference, but not quite the order of magnitude I'd expect from huge vs small.
- furyofantares 11y agoAnd we share 50% of our DNA with a tree... That's not meant to be snarky, but what's is the minimum size of a language spec? I don't know the answer, but I'd think the delta over that would be the better comparison. For example if you can't really spec a language in less than 200 pages then C++'s spec is more like 10 times as big as JavaScript.
- bremac 11y agoScheme has the smallest (useful) language specs that I know of. For example, R5RS is 48 pages (44 if you exclude the back matter.)
- waps 11y agoHere is one of the smallest useful (ie. turing complete) language's full specification : > Subtract and branch if not equal to zero[edit] > The SBNZ a,b,c,d instruction ("Subtract and Branch if Not equal to Zero") subtracts the contents at address a from the contents at address b, stores the result at address c, and then, if the result is not 0, transfers control to address d (if the result is equal zero, execution proceeds to the next instruction in sequence). This is all of it.
- vitaut 11y agoWith great power comes great responsibility.
- dragontamer 11y agoGood luck finding a language out there that doesn't have pitfalls.
- moonchrome 11y agoTo be fair I think most languages don't have pitfalls as defaults in the C++ sense :D
- Daishiman 11y agoThe amount of things in C++ to avoid practically constitute a language by itself.
- moonchrome 11y agoAnother amusing part is that it's a moving target - some parts of the language actually got better with implementations and spec improvements - so there's a large number of people avoiding useful features on outdated practices (they learned "don't use X" without the reasoning behind it :) )
- dragontamer 11y agoBut most languages that have seen prominent use have obscure corners that no one should ever visit. PHP has absolutely awful parts for example. (Magic Quotes anyone?) Even relatively "clean" languages like Java or C# can be completely mucked around if you abuse reflection or do dumb things (ie: have property getters / setters in C# do something insane... like get {return blah++;} ) I mean, any language that has mutexes (ie: all of them) can more or less lead to absolutely dangerous situations. C++ RAII may not be the best (compared to D or Rust or whatever), but C++ is the most widespread language that has complete RAII support. If you even learn the most basic of C++ patterns: shared_ptr<>, RAII destructors... (which are useful concepts in C++'s "replacements" anyway), C++ becomes not only a manageable language... but one of the most widespread useful languages current right now.
- vitaut 11y agoActually avoiding C++ pitfalls is not that difficult as most of them come from C: manual memory management, macros, varargs, unsafe casts. In fact C++ provides safe alternatives to many of the unsafe C constructs, so if you stick to them you are fine.
- nulltype 11y agoThe pitfalls of C++ that I've seen are mostly the things people build with the safe alternatives.
- vitaut 11y agoCould you give an example?
- nulltype 11y agoI've seen some pretty impossible to comprehend or debug uses of templates. Perhaps my favorite, which represents most of the pitfalls you can create with C++ is the Boost library. And of that, the shining star is this page: http://www.boost.org/doc/libs/1_57_0/libs/geometry/doc/html/geometry/design.html http://www.boost.org/doc/libs/1_57_0/libs/geometry/doc/html/...
- vitaut 11y agoI wouldn't call it a pitfall. Boost is written by C++ experts who like to push the boundaries of what can be done with the language. This doesn't mean that you have to debug their code or overuse templates yourself and there is nothing in the language that encourage this. For common cases such as in the standard library, templates are pretty easy to use and trivial to debug with modern compilers.
- GFK_of_xmaspast 11y agoGiven the design constraints: """ A generic library should be able to calculate the distance: for any point class or struct, not on just this mypoint type in more than two dimensions for other coordinate systems, e.g. over the earth or on a sphere between a point and a line or between other geometry combinations in higher precision than double avoiding the square root: often we don't want to do that because it is a relatively expensive function, and for comparing distances it is not necessary """ I suspect a little bit of complexity is necessary. (And can you even build something like this in a more fashionable language?)
- Shorel 11y agoC with classes is undervalued, and templates are overvalued, IMO. Just switching compilers makes the C code more robust.
- eropple 11y agoTemplates can be abused, but there's real value to simple ones such as container classes and even shared_ptr and unique_ptr. The subset of C++ I personally use is pretty small, but I hope I never go back to manual memory babysitting.
- waps 11y agoTemplates are the main thing in C++ that you can easily use everywhere with zero costs in compatibility. And they certainly beat C's "equivalent", macros.