changeset 34:3bf129646979

Add TRS paragraph
author David Demelier <markand@malikania.fr>
date Mon, 30 Jul 2018 14:33:58 +0200
parents 793a60620477
children 6114710feda7
files STYLE.md
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/STYLE.md	Wed Jul 18 13:58:51 2018 +0200
+++ b/STYLE.md	Mon Jul 30 14:33:58 2018 +0200
@@ -73,11 +73,22 @@
 References and pointers are always next to the type name and not the variable.
 
 ```cpp
-T& get(const std::string& name);
+auto get(const std::string& name) -> T&;
 
 int* p = &x;
 ```
 
+### Trailing return syntax
+
+We use trailing return syntax everywhere, it has the following benefits:
+
+- Inner types don't need to be prefixed by class name,
+- Functions are kept aligned correctly, focusing on the function name.
+
+```cpp
+auto func() -> std::string;
+```
+
 ### Naming
 
 - English names,
@@ -98,10 +109,7 @@
     std::string name_;
 
 public:
-    inline const std::string& name() const noexcept
-    {
-        return name_;
-    }
+    auto name() const noexcept -> const std::string&;
 };
 
 template <typename Archive>
@@ -233,7 +241,7 @@
 is better to take it by value and modify it directly.
 
 ```cpp
-std::string clean(std::string input)
+auto clean(std::string input) -> std::string
 {
     if (!input.empty() && input.back() == '\r')
         input.pop_back();
@@ -253,7 +261,7 @@
 between the bounds of an array:
 
 ```cpp
-T& operator[](unsigned index)
+auto operator[](unsigned index) -> T&
 {
     assert(index < length_);
 
@@ -296,7 +304,7 @@
 ```cpp
 namespace util {
 
-std::string clean(std::string input);
+auto clean(std::string input) -> std::string
 
 } // !util
 ```
@@ -420,7 +428,7 @@
 But do not use `auto` to write code like in python, this is not acceptable:
 
 ```cpp
-    auto o = my_object("foo");
+auto o = my_object("foo");
 ```
 
 ### String views