4 ms·
Not really. I'm sure this happens some of the time, but I suspect that's more common with developers who haven't written either. In my experience, a lot of the
by yoklov 11y ago
Not really. I'm sure this happens some of the time, but I suspect that's more common with developers who haven't written either.
In my experience, a lot of the developers who prefer C to C++ are developers who wrote a lot of C++, found that it only improved productivity in solving problems that it created, and went back to C and realized how much easier it is to write software in C.
C++ gets you caught up thinking about problems that don't even matter.
- deleted 11y ago[deleted]
- throwawayaway 11y agoone of my favourite quotes from stroustrup says that 'don't use malloc and free, unless you want to debug 1980s' problems. which i find curious, given the truism about debugging and understanding code taking longer than writing code. personally i would prefer 1980s problems people in general know the answer to, rather than up to the minute esoterica. all that said, the scott meyers modern c++ book is out, so i should really start and finish that before forming an worthy opinion in 2015.
- pmelendez 11y agoI would recommend you to first read "Tour of C++" or another book that explains better the new features on C++11. Meyers explain very well some of edge cases of move semantics but if you don't understand the concept first then you might not have a good experience reading the book. >"says that 'don't use malloc and free, unless you want to debug 1980s' problems." The problem with malloc and free is that they left to the developer to keep track of the references and memory corruptions bug are not pleasant to debug. RAII idiom actually helps a lot in that context, and that is what Strouptrup was referring to.
- throwawayaway 11y agothanks for the recommendation. i think malloc and free are a lesser evil than this stuff: http://thbecker.net/articles/rvalue_references/section_08.html http://thbecker.net/articles/rvalue_references/section_08.ht... feel free to disagree!
- pmelendez 11y agoThe link that you provided does not have to do with malloc and/or free but with perfect forwarding: http://thbecker.net/articles/rvalue_references/section_07.html http://thbecker.net/articles/rvalue_references/section_07.ht... Also that example uses a Factory pattern which is actually verbosing the example, but it's like comparing apple and oranges since that's OOP which you actually wouldn't be doing in C. What you would be comparing is something like: mystruct * stcVar = malloc(sizeof(mystruct)); free (stcVar); Vs. std:shared_ptr<mystruct> stcVar; Of course that is a stupid example; However things gets more interesting when you have pieces of code sharing the same structure (threads maybe?) and you don't know exactly which code should be the one in charge of releasing the pointer.
- throwawayaway 11y agoi think you misunderstand. clearly, it is C++, not C. instead of a simple malloc and free, you will invariably end down the rabbit hole learning about rvalues. perfect forwarding, move semantics, lvalues - the list goes on - these topics arise from the simple concept of RAII. which i find worse than malloc and free.
- pmelendez 11y ago>i think you misunderstand. >clearly, it is C++, not C. I got that, what I said is that you wouldn't have that problem in C because it arises when you are doing OOP, and most C devs would not use OOP. Also, keep in mind that it is perfectly fine not using OOP in C++. > instead of a simple malloc and free, you will invariably end down the rabbit hole learning about rvalues That's not true. Actually you can be a very decent C++ developer without knowing the notion of what an rvalue is. Move semantics is just an optimization to avoid extra copy of objects, so it is completely optional. At the moment of writting this, there is an entry on the front page with an example of a modern C++ piece of code. You would notice that there is not a single explicit heap allocation nor any other crazy stuff. https://news.ycombinator.com/item?id=9560667 https://news.ycombinator.com/item?id=9560667
- 11y ago