aboutsummaryrefslogtreecommitdiff
path: root/docs/cpp-coding/09-Considering_Correctness.md
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-11 13:05:39 +0200
committerStefan Boberg <[email protected]>2021-05-11 13:05:39 +0200
commitf8d9ac5d13dd37b8b57af0478e77ba1e75c813aa (patch)
tree1daf7621e110d48acd5e12e3073ce48ef0dd11b2 /docs/cpp-coding/09-Considering_Correctness.md
downloadzen-f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa.tar.xz
zen-f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa.zip
Adding zenservice code
Diffstat (limited to 'docs/cpp-coding/09-Considering_Correctness.md')
-rw-r--r--docs/cpp-coding/09-Considering_Correctness.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/cpp-coding/09-Considering_Correctness.md b/docs/cpp-coding/09-Considering_Correctness.md
new file mode 100644
index 000000000..5bc8b61ec
--- /dev/null
+++ b/docs/cpp-coding/09-Considering_Correctness.md
@@ -0,0 +1,30 @@
+# Considering Correctness
+
+## Avoid Typeless Interfaces
+
+
+Bad Idea:
+
+```cpp
+std::string find_file(const std::string &base, const std::string &pattern);
+```
+
+Better Idea:
+
+```cpp
+std::filesystem::path find_file(const std::filesystem::path &base, const std::regex &pattern);
+```
+
+The above is better but still suffers from having implicit conversions from `std::string` to `std::filesystem::path` and back.
+
+Consider using a typesafe library like
+
+ * https://foonathan.net/type_safe/
+ * https://github.com/rollbear/strong_type
+ * https://github.com/joboccara/NamedType
+
+Note that stronger typing can also allow for more compiler optimizations.
+
+* [Sorting in C vs C++](Sorting in C vs C++.pdf)
+
+