11 ms·
C++ Frequently Questioned Answers
- timr 17y ago"Unfortunately, you can't tell the class of a C++ object given a pointer to it at run time....which is why you can't automatically collect the garbage of C++ programs." What nonsense. Here's what I learned from this link: trolling isn't as effective when it requires the trollee to read 10 pages of text. This is garbage. Please flag it for collection.
- mrtron 17y agoThis is C++. Implement your own deconstructor, and manage your own damn memory. I would probably use Boost's smart pointers to handle the reference counting though.
- swolchok 17y agoNo, GP's point is that there are garbage collectors for C++. I believe Stroustrup even mentions one in The C++ Programming Kanguage. Furthermore, you CAN tell the type of an object given a pointer to it, assuming it has at least one virtual function, using the typeid operator. As the GP said, the original quote is nonsense.
- calambrac 17y agoassuming it has at least one virtual function Which you can't do. Seriously, when did it become okay to call out a problem with the general case as nonsense because there's a specific case that avoids the issue?
- DarkShikari 17y agoJust because you disagree with something does not automatically make it a troll.
- deleted 17y ago[deleted]
- dave_au 17y agoAFAIK it's reasonably well known as an unintentional troll - there was a stackoverflow question about the FQA (still looking for the link) that basically mooted almost every point. I was reading it as a neutral party, however some very knowledgeable C++ appeared to convince all comers that the FQA is either based on ignorance or is disingenuous.
- nickpp 17y agoMaybe this is it: http://stackoverflow.com/questions/385297/whats-wrong-with-c-compared-to-other-languages http://stackoverflow.com/questions/385297/whats-wrong-with-c... Summarizing: "C++ is hard but makes some things possible that aren't in other languages." The FQA dude is a troll: he criticizes without offering better alternatives, ignoring tradeoffs and considerations and overlooking any advantages offered by C++.
- finnw 17y agoI also once tried referencing the C++ FQA on stackoverflow and was quickly downvoted. Maybe SO is just the wrong place to mention it, probably because of a C++ bias from the high percentage of SO users who develop on MS platforms.
- timr 17y agoMy disagreement has nothing to do with it -- the quoted remark was completely without basis in fact.
- kmavm 17y ago"Unfortunately, you can't tell the class of a C++ object given a pointer to it at run time....which is why you can't automatically collect the garbage of C++ programs." That's a somewhat self-serving use of ellipses. Here's the actual text: "Unfortunately, you can't tell the class of a C++ object given a pointer to it at run time. So if you debug a crashed C++ program and find a pointer somewhere in its guts, and you don't know its type, you'll have to guess that "0000000600000005" is a Point. Which is completely obvious, because that's the way a pair of adjacent integers looks like in hexadecimal memory listings of a little endian 32 bit machine. And two adjacent integers might be a Point. Or some other two-integer structure. Or a part of a three-integer-and-a-float structure. Or they might be two unrelated numbers which just happen to be adjacent. Which is why you can't automatically collect the garbage of C++ programs." Which part are you claiming is wrong? (Be careful.) The entire first paragraph even Bjarne Stroustrup would agree with once he was done hemming and hawing. Post-mortem inference of types of dynamic objects in C++ programs is undecidable. In higher-level OO languages, memory is organized as framed objects, not as a bag of bytes. The main thrust of this questioned answer had nothing to do with GC. And he's right about this being what makes GC and C++ bad fits for one another, too, though he skipped a few steps. Getting out the sock puppets, without the ability to tell the type of an in-memory object, you can't compact the heap. If you want to move an object, you can't just assume anything in memory with the bit pattern of that object's address is a pointer, because it might be two shorts or a double or whatever that happens to have that bit pattern. While conservative, non-compacting garbage collectors can be built in theory, they're too slow in practice. Check out the source to Hans Boehm's C/C++ collector; it stops all the threads in the process, and analyzes liveness starting from each thread's CPU registers, each thread's entire stack, and the entire static data segment. By the implementors' own admission, this will not scale to large numbers of threads, or large address spaces. Even if this approach is refined significantly, if your garbage-collected program lives long enough, you need compacting garbage collection, or fragmentation will kill you just as surely as exhaustion would have. And if you are so convinced that performant, general purpose GC can be dropped into large C++ codebases, you have a straightforward way of both shutting me up, and having a very interesting ycombinator startup. A drop-in operator new overload that does compacting, generational, safe GC would have a readymade market, with very deep pockets, from companies stuck maintaining enormous piles of C++ code with intractable memory management bugs.
- DarkShikari 17y agoOn a quite related note, I like this page as well: http://harmful.cat-v.org/software/c++/I_did_it_for_you_all http://harmful.cat-v.org/software/c++/I_did_it_for_you_all ;)
- spectre 17y agoWish there were more sites like this. We mostly just believe the answers we recieve.
- deleted 17y ago[deleted]
- joey 17y agoIt's probably more important to have a good set of coding guidelines when writing C++ code than with other languages, but there's no reason not to write new projects in C++ if it's the best language for the task and team. Voxli is built on C++ and boost. We make liberal use of scoped_ptr and shared_ptr where appropriate and we have yet to experience resource leaks in our client.
- dryicerx 17y agoThis. Actually to add to your comment, it's not just good, but a MUST to have a set of good coding guidelines. The language is complex for a reason, you tell the Compiler EXACTLY what you want it to do, and this takes away overhead from the compiler trying to guess. It's a trade off between the convenience to the programmer to the performance of the application. C++ isn't perfect, it's not meant for everything. But for fast, large, and complex systems, C++ is one of the best ways to go about it.
- kowsik 17y agoC++ is so not perfect and is definitely not for large scale development. Read this: http://labs.mudynamics.com/2007/07/23/writing-c-within-ruby/ http://labs.mudynamics.com/2007/07/23/writing-c-within-ruby/
- nickpp 17y agoReality, however, contradicts you. C++ is one of the only languages out there PROVEN in the field by being used in thousands of large-scale developments. Operating Systems, Office applications, Browsers, Search Engines, etc. - aren't these large scale?!
- eru 17y agoTry Cobol. Or C. Or Assembler. Or Fortran. Those languages are also used in large projects since ages. But what does that tell us?
- kmavm 17y agoThe author, Yossi Kreinin, is also one of the most underrated bloggers about software implementation on the planet. Before dismissing him as a one-trick pony language bigot, please sample http://www.yosefk.com/blog/ http://www.yosefk.com/blog/ a bit. http://www.yosefk.com/blog/extreme-programming-explained.htm.. http://www.yosefk.com/blog/extreme-programming-explained.htm.... is just waiting to be dusted off and resubmitted by some enterprising young news.yc karma junky.
- deleted 17y ago[deleted]
- mojuba 17y agoOh, his Cardinal Programming Jokes have been here already, but thanks for reminding, this rare and awesome blog is somewhere between the worlds of technology and bed-time fiction.
- gcv 17y agoFascinating that Yossi Kreinin hates Boost libraries so much. I have had my share of problems with them (slooooooow compilation and horrible template compiler error messages, mainly), but the Boost.Spirit parser library turned out to have been a lifesaver. I needed to parse JSON in a C++ system, had Boost available, but could not realistically install any other external library dependencies. Well --- the TinyJSON (http://blog.beef.de/projects/tinyjson/ http://blog.beef.de/projects/tinyjson/) looks a little funky thanks to all the templates and operator overloading magic, but it works well and I dropped it into the system as a header file. Problem solved. I'd make heavier use of Boost.Filesystem, too, but I'm stuck deploying with an older version of Boost which lacks a few essentials. I never understood the messiness of concatenating path strings by hand until I was forced to stop using os.path (Python) and java.io.File (Java, Clojure).
- kmavm 17y agoTemplates taking too long to compile and producing ridiculous error messages is actually one of, if not the, major complaints Yossi has about C++, though. One of the rarely spoken of differences between C and C++ is that the latter has a ludicrously slower compile leg of the compile/edit/debug cycle, and once you start digging into it, the slowness of compilation is built into the language (basically, matching template specializations is computationally hard), and is not an artifact of so-called "poor implementations."
- DanielBMarkham 17y agoFor those of you who are skimming: this is an attack job on C++ Instead of wading in to somebody else's religious war (and it's obviously personal for somebody to spend so much time finding fault with every item in the original FAQ), I'll just say: works great in some situations. I was building a shell extension for Microsoft Windows several years ago. Booted up C++ and MVC, got up to speed on COM and shell extensions, and made some magic happen. Once I got up to speed (which took some time) I found I was just as productive in C++ as any other language. Same goes for a couple of other projects I've done in C++. C++ is my favorite language, and it's a god-awful power tool of a beast. I don't use it regularly and don't plan to, but when you need it, it kicks ass. Most of the time, however, you need other stuff, like fast development times, ease-of-learning, common runtime, managed GC, and ease-of-understanding. Criticizing C++ for not having those things is completely missing the point of the language.
- Hexstream 17y agoIf x - (fast_dev_time + ease_of_learning + common_runtime + managed_GC + easy_of_understanding) = kicks_ass, then what's x? In other words, what redeems C++? What's the point of the language?
- kingkongrevenge 17y ago> What's the point of the language? It's a drop-in replacement for C that is much more powerful and succinct.
- halostatue 17y agoThat's the theory. The reality is that it's not more succinct and it's not significantly more powerful in most cases. Yes, there are some neat things you can do with templates (and I do), and some of the syntactic sugar things you get with objects and overloading and namespaces are nice, but there's nothing that you can do in C++ that you can't do equally well in C. That said, C++ is in no way a "drop-in replacement" for C. What makes C++ "interesting" is that most of the time, you can drop C code into a C++ program and it will just work. Of course, you can do the same thing with Objective C, and the object model behind Objective C is much more sane.
- Confusion 17y agoIf you're criticising something as vast as the C++ FAQ lite and find issue with every single claim, then you are bigoted and your review probably isn't worth it.
- rmaccloy 17y agoThis is both a bad argument and kind of lacking a sense of humor, since programmers do this (point by point rebuttals) all the time (see: every popular thread on the LKML, ever)
- scott_s 17y agoI think it's a bad practice in general, as it encourages nit-picking the small details and missing the main point of what someone says.
- billswift 17y agoA programmer who isn't a nitpicker is a lousy programmer. Computers don't get the "main point" of what someone says. I'm not much of a nitpicker, which is my biggest problem when coding.
- scott_s 17y agoDiscussions with humans is an entirely different domain than programming computers. I get the same urges to argue with someone point-by-point as anyone else does, and I try to quell it so that a useful discussion can take place.
- Confusion 17y agoEven if programmers do something all the time, that doesn't mean it's right. The reason is simple: every opinion has arguments in favor of it. If someone offers five arguments in favor of an opinion, usually at least two are reasonable. If someone attempts to rebuke all five points, they're usually being unreasonable. It's also counterproductive, because bad counter-arguments call for counter-counter-arguments, which detracts from the actual points under discussoin. If you think an argument isn't persuasive and doesn't have much weight, then that is what you should say, instead of searching for some nitpicky way to counter the argument, usually ending up in discussions about semantics because you actually agree on the point. As for this article: if this was intended to be humorous, then it contains far too much that seems to have been intended seriously, for my taste. After a few points he could have stopped beating the dead horse. Wrapping criticism in humor is an annoying strategy similar to the 'poisoning the well' fallacy: as soon as someone tries to start a discussion, you can go "where's your sense of humor?" and your humorously wrapped argument remains unchallenged. That gets under my skin and may have impaired my humor detecting capabilities here.
- rmaccloy 17y agoAlso worth reading (edit: if you've got an hour to kill and care about the subject): http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/870d15c57e831fc5/5868fd6e57f6ae2c http://groups.google.com/group/comp.lang.c++.moderated/brows... The author defends his position pretty coherently and civilly; you can disagree with his conclusions but calling him a troll or an idiot is certainly not warranted.
- sreque 17y agoI feel like people miss one of the main points of this FQA. The author repeatedly asserts that most people who think they need C++ do so because they think they need the performance it can offer. Most of these people, however, don't actually need the extra performance and would be much better off with a higher level language. Those that actually do need the performance and know what they are doing would be better off just using C with assembler. In many ways, I think he is right. C++ tries to be high-level, low-level and everything in between all at once, and the end result can bring a lot of potentially unnecessary frustration to programmers. There are several projects, such as LLVM, for example, that get by using a "tasteful subset" of C++, and I would be interested in learning what that subset is.