3 ms·
In my opinion, the site you linked to has a major problem - many of the example functions have a "void" return type. This indicates that they must have side-eff
by zabzonk 6y ago
In my opinion, the site you linked to has a major problem - many of the example functions have a "void" return type. This indicates that they must have side-effects (or why else call them?) and we would normally not want to write functions that have side effects.
A rule of thumb: if your function doesn't have a return type, consider that your design maybe wrong in some way.
- detaro 6y agoWhat the functions return is utterly irrelevant for the examples, so adding return types and statements just makes the example more complex for no good reason (and distracts from examples where the example is about the returns)
- zabzonk 6y agoThe site is about writing "good" C++. Having loads of functions that implement "bad" C++ cannot help.
- josefx 6y agoGood C++ code shouldn't throw around heap allocations, shared or otherwise. Smart pointers are like duct tape, they help keeps things together but most of the time there are better solutions. Your complaint about void will be noted once you fix your programs ownership semantics. Note: Any negative reactions to smart pointers on my side may be fueled by a disturbing amount of cargo culting that I had to witness since their inclusion in the standard.
- zabzonk 6y ago> Your complaint about void will be noted By whom? > once you fix your programs ownership semantics. How do you heck know how my programs need fixing? > Any negative reactions to smart pointers on my side may be fueled by a disturbing amount of cargo culting that I had to witness since their inclusion in the standard. Any positive reactions to smart pointers on my side may be fuelled by over 30 years experience in using them.
- josefx 6y ago> How do you heck know how my programs need fixing? You where the one complaining that sample one liners with void return types where bad code. In my experience shared_ptr is overkill in nearly all trivial code examples, so any one liner containing one is bad code. > Any positive reactions to smart pointers on my side may be fuelled by over 30 years experience in using them. Hope you never had to deal with code reviews that suggested putting scoped std::vector uses in shared_ptr s to avoid stack overflows. Or really any code that put objects into smart pointers because it could not because it should.
- zabzonk 6y agoI have never, ever used, or suggested the use of shared_ptr, which I believe is not a construct that should be in C++ or any other language.
- rualca 6y ago> (...) shared_ptr, which I believe is not a construct that should be in C++ or any other language. What's your rationale for that assertion?
- mhh__ 6y agoThis is true, but two points: Firstly, don't teach too much at the same time, and secondly sometimes you have to just launch the missiles.