8 ms·
I love C and Objective-C. I can't stand C++. Is that common among programmers?
by stupang 10y ago
I love C and Objective-C. I can't stand C++.
Is that common among programmers?
- johnydepp 10y agoComing from C++ and iOS world I would say recent C++ has evolved a lot. And I think its better than Objective-C.
- hacker42 10y agoWhat has always bugged me about C++, but maybe I am overlooking some reason why this generally cannot work, is that it does not resolve circular dependencies such as this one: // file: A.h class A { B* _b; }; // file: B.h class B { A* _a; }; I mean a pointer has a fixed size, so couldn't the compiler just leave some sort of type placeholder in class A until class B is eventually defined.
- jontro 10y agoThis can be done, check the end of this answer: http://stackoverflow.com/a/628079/429972 http://stackoverflow.com/a/628079/429972 // file: A.h class B; class A { B* _b; // or any of the other variants. };
- gruez 10y agoYou can also do this class A { class B* _b; };
- MaulingMonkey 10y agoStructure layout isn't the hard part, it's having the rest of the language cope with the ambiguity of everything. // Things.h namespace Foo { class A { C* c; }; } namespace Bar { class B { C* c; }; } Are A::c and B::c the same type? // TU1.cpp class C {}; Were you right? // TU2.cpp namespace Foo { class C {}; } namespace Bar { class C {}; } What about now? // TU3.cpp class C {}; namespace Foo { class C {}; } namespace Bar { class C {}; } This may get you shot, but is legal. What about now? Ahh - all three are in the same program. Just pretend they #included <c.h>, <foo/c.h>, and <bar/c.h>. Having A::c's type be different in different contexts is a violation of the "One Definition Rule", for which the punishment is undefined behavior. Although you can still recreate the above scenarios by just #including <Things.h> after <c.h> and company, but you're a bit more likely to have Things.h #include what it needs to clarify the situation. Hopefully. So maybe we can get away with it! void foo() { D * d; } Is that a pointer definition or invoking operator* against two globals? void bar() { E < 42 > e; } Now you're just fucking with me. Is that some comparison operators or a template? void baz() { F < (42) > f; } That didn't clarify anything. Stop it. void he_comes() { G < (42) > g(); } What do you mean I just declared a function? Stop it! v̹̊̈́̇ͦ̌ͭ͂ͅo̅̉̀ͪ̚ī̵̠̘̋d̸͚̪̝̹͙͆͛̿ ͉̜̳ͪͬ́ͣ̌ẑ̸̹̹̩̩a̡̰ͣͭ̄͒ͫ̇̚l̛̹̫͓̣͖͈̐ͬg̢͕̘͙o̪͆̏ͥ͟(̖̭̟̱̰ͩ)̘̬͉̺̉̓ ̦͆́̚{ ̶̪͙̹͈ͮͧ̋ͪͤͅĜ͔̙̉͢ ̝̯ͭ̈́͘<̨͊̂͋̎ ̤͇̼̝͔͇ͯ̑̋ͫ̾͐̚(ͨͪͦ̈̈́ͥ4͍͗̆2̲̞̦̳̖͡)͖͇̟̥ͮ͘ ̺̖͙̘̳͛̐̊͊>̼͍̘̦͖̎ ̧̘̻̭͉̺g̟͓̑ͦ̌̃(̪ͬͪͤ̎̉͘ȉ̮̥͖́n̸̝̪̗̯͇̓̈́̀̔̄̍́t͓̟͍ͨͪ(̰͈̻͎̣͉̀̿̈͑)̝͚̆̃̇)̠̃;̺͎̙̰̈́̏̚͘ ̶̜͍̠̼ͬ}̡̤̰̮̳͈̌͛ͤ̈́ A function accepting a function pointer? Stooooop!
- Tyr42 10y agoYou can just do class B; class A { B* _b; }; and it'll be happy.
- green7ea 10y agoIt can easily be done by declaring a prototype of B: // file: A.h class B; class A { B* _b; }; // file: B.h class B { A* _a; };
- _pmf_ 10y agoC programmer here; I don't like C++ much because every library tends to reinvent the whole stack (or maybe that's just my impression from using MFC and Qt, which are notorious in that regard). RAII and scope based construction/destruction is actually quite nice.
- humanrebar 10y ago> every library tends to reinvent the whole stack This is a problem with vocabulary types. C tends to do a good job of providing them. C++ tends not to, though there has been some progress in the standard lately in defining classes like unique_ptr and string_view. C tends to fall down by providing raw memory (an int and a char) to represent fairly subtle relationships (the int represents the size of the string pointed to by the char... what happens when the int is negative?). So C libraries don't 'reinvent the whole stack', but this sort of bookkeeping logic tends to cause bugs (at least security bugs).
- mayhew 10y agoAt least C++ has a stack to re-invent. With C you're missing Vector and Map before you even start.
- zenshin 10y agoCheck out the Juce library. It's a fantastic lib, primarily intended for audio programming but I've found the GUI tools to be very nice.
- Tomis02 10y agoThe more I learn C++, the more I can't stand it. Its ever-increasing complexity keeps being a distraction from the actual problem you're trying to solve.
- MaulingMonkey 10y agoI've reached peak loathing of C++ at this point. I can see why people would want to lock up the recursive template metaprogramming double barrled automatic shotgun. ...but I get confused by the people who do that, and then turn around to embrace C, the circus where people juggling the chainsaws of "faking templates with macros", "terrible build times", "yet more security vulnerabilities resulting from undefined behavior", "no C-standard defined threading / async support until C1X", and more. It's common, but I don't get it.
- Joeri 10y agoWell, people like C because it contains less language features and therefore is simpler. The error is thinking that simple and easy are the same thing. C is fiendishly difficult to write correctly.
- hellofunk 10y agoYes, but the distractions of C are just as inconvenient, though wholly different. The amount of extra low-level work you must do in a C program considerably adds to the time you need to make it work, time that could be spent thinking about more interesting things. I'd rather reach for a C++ vector and just let it manage the memory for me (or unique_ptr or many other easy tools) while I'm crafting my program logic then spend a nontrivial fraction of my time making sure my memory handling is correct.
- Koshkin 10y agoBut the same can be said about mathematics, for example. While true, such statement is only saying something about the process of learning; it does not mean that C++ (or mathematics) is badly designed, useless, or is not worth learning. When you are just learning, of course you tend to be more focused on the subtleties of the subject itself rather than on its applications. Which is not to say that it is a good idea: it is through application that you begin to understand and fully appreciate the subject.
- pjmlp 10y agoI love C++ except the copy-paste parts from C and the toolchain compromises used to sell it to C developers. Dislike Objective-C verbosity and C roots, although I kind of like its Smalltalk influence. Really strongly dislike C and the culture of insecure software it has brought into our industry.
- 11281281 10y agoI'm sorry, but C++ does not exactly have a culture of secure, maintainable and understandable software.
- pjmlp 10y agoYes, it does. The majority of C++ programmers make use of: - RAII - String classes instead of char* überall - Vector classes instead of char* überall - new and delete instead of malloc()/free() and casts - References for out parameters instead of pointers - Real enums, specially since C++11, instead of #define - Smart pointers for memory management - Type based programming to reduce errors - Minimize the use of the pre-processor to #include and macros, only when they cannot be expressed via templates, const, constexpr and inline. Most of the unsafe C++ code is written by the "C with C++" sub-community that are mostly C refugees forced to use a C++ compiler. Also while the C++ community is pushing for safety with activities like the C++ Core Guidelines and reducing the amount of UB in the standard, the C standard community doesn't care at all. The only thing that the C community has done regarding security was the Annex K in C99, which was proven so good that it became an optional feature in C11.
- pcwalton 10y ago> Yes, it does. Where is this modern C++ culture that has resulted in large-scale codebases free of memory safety vulnerabilities? I've never seen even one, much less a "widespread culture". > The majority of C++ programmers make use of: None of this, empirically, results in safe code. > Most of the unsafe C++ code is written by the "C with C++" sub-community that are mostly C refugees forced to use a C++ compiler. I haven't seen any evidence for this. A lot of vulnerabilities are found in modern C++11. > Also while the C++ community is pushing for safety with activities like the C++ Core Guidelines and reducing the amount of UB in the standard, the C standard community doesn't care at all. I don't see any way that the C++ Core Guidelines are going to be able to succeed in creating a usable language that is memory-safe. Robert O'Callahan and I have elaborated why in other posts.
- hellofunk 10y agoIt's easy to dislike or hate C++ due to its immense complexity, and programmers like to be able to keep simple abstractions in their head so they can concentrate their energies on their problem domain without worrying about language confusion. With C and many other languages, this is possible as they are smaller languages. C++ on the other hand: is there any language with widespread use that is so deep and complex? However, there are undeniable conveniences to C++ (safety, a good library, much more -- especially functional-style programming with lambdas now) that can speed up your work process, and if you can accept that you will never know the entire language and can just use those bits that make things easier, it is possible to have a healthy relationship with the language. And it offers tremendous room to grow as you get more and more comfortable with it. Few languages allow you to just keep diving in deeper and deeper as you desire, while still letting you get to work right away without being a master. Even template metaprogramming alone is gigantic area of ongoing research -- the stuff you can do with it is mind-bending and unavailable in nearly all other languages. Templates are, after all, one of very very few wholly functional, immutable languages out there. And template instantiation is the underlying force behind many of the modern features like lambdas that allow you to access that power without actually knowing templates well. It's a powerful language for which you must accept its character flaws in return for its abilities. It's doesn't hurt either that the libraries available in C++ are really cool.
- kazinator 10y ago> if you can accept that you will never know the entire language As a developer responsible for understanding what everyone else is doing on the same project, no I cannot accept that.
- lisper 10y ago> safety Um, no. C++ can be safer than C (which is an incredibly low bar) but only if you carefully constrain yourself to certain subsets of the language, which is why the web is chock-a-block with byzantine "C++ coding standards" documents describing all the rules you have to follow in order to avoid shooting yourself in the foot.
- 10y ago
- mratzloff 10y agoHave you tried modern C++ (that is, C++11 and C++14)? It has a very different feel these days. I used to prefer C as well, but C++ has come a long way in ease of usability.
- blt 10y agoAmong many reasons, I would choose C++ over those languages because it has operator overloading. Expressing 3D spatial math and linear algebra in a language without operator overloading is incredibly tedious.
- gurkendoktor 10y agoIt all depends on what you are building. Objective C is absolutely fantastic for rapidly developing GUIs because of its dynamic runtime and flexible typing. On the other hand, C++ makes it a lot easier to write efficient, (relatively) safe data structures. I find it extremely frustrating when I have to use either language in an area that it wasn't designed for.