From 61ddee69aa4892ee465203d4c3b81bdbcb836735 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 18 Jun 2021 10:49:15 -0700 Subject: [PATCH] Remove cpp style guide --- governance/cpp-style.md | 64 ----------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 governance/cpp-style.md diff --git a/governance/cpp-style.md b/governance/cpp-style.md deleted file mode 100644 index 4adaa1882..000000000 --- a/governance/cpp-style.md +++ /dev/null @@ -1,64 +0,0 @@ -# C++ Coding Style - -Tensorflow follows [Google C++ style](https://google.github.io/styleguide/cppguide.html), -with a few additions. - -## Status - -Functions which can produce an error should return a `tensorflow::Status`. To propagate an -error status, use the `TF_RETURN_IF_ERROR` macro. - -``` -TF_RETURN_IF_ERROR(f()); -``` - -## StatusOr - -`StatusOr` is the union of a `Status` object and a `T` object. It offers a way to use -return values instead of output parameters for functions which may fail. - -For example, consider the code: - -``` -Output out; -Status s = foo(&out); -if (!s.ok()) { - return s; -} -out.DoSomething(); -``` - -With `StatusOr`, we can write this as - -``` -StatusOr result = foo(); -if (!result.ok()) { - return result.status(); -} -result->DoSomething(); -``` - -**Pros:** - -Return values are -[easier to reason about](https://google.github.io/styleguide/cppguide.html#Output_Parameters) -than output parameters. - -The types returned through `StatusOr` don't need to support empty states. To return a type -as an output parameter, we must either use a `unique_ptr` or support an empty state for the -type so that we can initialize the type before passing it as an output parameter. `StatusOr` -reduces the number of objects we have in an "uninitialized" state. - -**Cons:** - -`StatusOr` adds complexity. It raises questions about what happens when `T` is null and -how `StatusOr` behaves during moves and copies. `StatusOr` also generally comes with -macros such as `ASSIGN_OR_RETURN`, which add additional complexity. - -The current Tensorflow codebase exclusively uses `Status` instead of `StatusOr`, so -switching over would require a significant amount of work. - -**Decision:** - -Tensorflow foregoes the use of `StatusOr<>` because it doesn't add enough value to justify -additional complexity.