3 ms·
More than that, the guide limits C++ usage to a safer subset of features.
by Laremere 7y ago
More than that, the guide limits C++ usage to a safer subset of features.
- bradfitz 7y agoIn addition to style/subset, I also meant using Google's internal standard library.
- erik_seaberg 7y agoC++ relies heavily on RAII. Exceptions are safer than broken instances from failed constructors.
- SamReidHughes 7y agoIn their defense, the style guide says they inherited that from legacy code.
- kragen 7y agoGoogle C++ doesn't allow using exceptions and therefore requires broken instances from failed constructors.
- saalweachter 7y agoGoogle C++ tends towards the convention of constructors that do only cursory initialization to a sane but non-functional state, things that almost-always succeed (and assert on failure), with the "real" initialization pushed to an Init() or Start() function.
- bruckie 7y agoNot these days, although that was true 8-9 years ago. The preferred pattern now is to use factory functions that can return either a fully-initialized object or an error.
- d1zzy 7y agoNot having exceptions doesn't imply that. An alternative is ErrorOr<ReturnType> returning factory functions. It requires that ReturnType is movable tho (can be further wrapped in std::unique_ptr if not). Not every error is exceptional so not every error should use exceptions. This is especially important in lower level code where someone's exception is someone else's expected code path.