4 ms·
I was trying to figure out if this was satire. C++ gives you strictly more tools, particularly for guaranteeing reliability, and they're all optional. What pa
by jdashg 6y ago
I was trying to figure out if this was satire.
C++ gives you strictly more tools, particularly for guaranteeing reliability, and they're all optional.
What particularly laughable here is the split ctor/init pattern is allegedly driving them towards C, whereas C doesn't even give you dtors! If you're forgetting your init calls, are you really telling me you're not going to forget your destructor call? There are plenty of approaches besides split-init anyway, but it feels like the author feels pulled towards C for other reasons, and is looking for reasoning after the fact. C is not a magic bullet for simpler code!
C is useful for solving social problems with deciding what features and patterns of C++ to use, if you've given up on code review and style guidelines. If you decide that's you, good luck! You'll need it.
- pradn 6y agoOne good alternative to ctor+init() is a static factory method with a private ctor. It's just as simple as in C.
- fluffything 6y agoNot sure what a "factory method" is, but struct Foo { private: int a = 0, b = 0; Foo() = default; Foo(int a, int b): a(a), b(b) {} public: static Foo init_zeroed() { return Foo{}; } static Foo init_ones() { return Foo{1, 1}; } }; will do. You can add as many static methods acting as "named constructors" as you want.
- stickfigure 6y ago...and now you know what a "factory method" is.
- Koshkin 6y agoAlmost. One of the biggest advantages of a class factory is that it can return a pointer to an interface rather than a concrete class.
- inetknght 6y agoYes but that doesn't meaningfully change what a "factory" is: a factory returns an already-constructed object or smart-pointer-to-that-object you can work with. Whether or not that object is concrete or an interface to a hidden implementation is less important IMO.
- beeforpork 6y ago> C++ gives you strictly more tools, particularly for guaranteeing reliability, and they're all optional. You are right. But it doesn't help. When I used C++, I constantly shot myself in the foot by using its features. It did not feel like overusing, but I just wanted type-safety and to replace macros. It was impossible to restrict to useful features, because they are all useful in their way, only they come at the price of spreading everywhere until you don't understanding what is going on. Typing rules are insanely complex. Overloaded template error messages and hilarious amounts of boiler plate member functions just to satisfy the constructor rules and to catch the best overload for every integer type were the result. I went back to C. It's a relief.
- CreRecombinase 6y agoYou wanted type-safety and to replace macros, but then you went back to C?
- kova12 6y agothis is ridiculous. Every remotely powerful programming language gives you an opportunity to shoot yourself in the foot. c++ is so simple, and with every new standard it becomes even better and easier to use. How can anybody possibly complain is beyond me.
- fulafel 6y agoIts simplicity and ease of yse pales only in comparison with its safety and beauty.
- TheOtherHobbes 6y agoA language with four different pointer metatypes for memory management and (unrelatedly) four different pointer type meta-casts is not "simple". The subdialect of features that you have settled on may be simple, but the language itself is a nightmare of random feature archaeology and creeping throw-it-against-the-wall-and-see-if-sticks extensions, which somehow still fails to provide clean simple tools for polymorphism.
- StavrosK 6y ago