You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/learning-cpp.md
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ For a real-time visualisation of the build process, see [this post](https://dani
12
12
13
13
Best practices:
14
14
15
-
- Use a package manager (e.g. `conan`)
15
+
- Use a package manager (e.g. [conan](https://conan.io/) or [vcpkg](https://vcpkg.io/en/))
16
16
- Use [CMake](https://cmake.org/) with Ninja (for CMake best practices, see [Professional CMake](https://crascit.com/professional-cmake/) or [Pragmatic CMake](https://www.youtube.com/watch?v=NDfTwOvWIao))
17
17
- Strict compiler settings: at least `-Wall -Wextra -Werror`, preferably also `-Wpedantic -Wcast-align -Wno-unused -Wshadow -Woverloaded-virtual`, and ideally with `-Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion`
18
18
- Static analysis: linters, formatters (e.g. `clang-tidy` and `clang-format`)
@@ -32,7 +32,7 @@ Below are some highlights.
32
32
### Tutorials
33
33
34
34
-[Modern C++ Programming Course](https://github.com/federico-busato/Modern-CPP-Programming), [HackerNews thread](https://news.ycombinator.com/item?id=38444834)
35
-
-[Learn C++](https://www.learncpp.com/cpp-tutorial/), very comprehensive tutorial for the C++ language itself, but without discussing the wider ecosystem like existing testing frameworks or toolchains
35
+
-[Learn C++](https://www.learncpp.com/cpp-tutorial/), very comprehensive tutorial for the C++ language itself, but without discussing the wider ecosystem like existing testing frameworks or toolchains ([my solutions](https://github.com/mloning/learning-cpp))
36
36
-[C++ Study Plan](https://www.studyplan.dev/cpp)
37
37
-[Learn C++ in Y Minutes](https://learnxinyminutes.com/c++/), very concise introduction
-[C++ Coding with Neovim](https://www.youtube.com/watch?v=nzRnWUjGJl8)
47
47
48
-
### Other resources
48
+
### Miscellaneous
49
49
50
50
-[cplusplus.com](https://cplusplus.com/), community tutorials, forum and blog posts
51
51
-[Cheat sheet](https://hackingcpp.com/cpp/cheat_sheets.html) with [HackerNews thread](https://news.ycombinator.com/item?id=30579884)
52
52
- Well-written C++ repos: [nlohmann/json](https://github.com/nlohmann/json)
53
53
- Example best-practices repository [bemanproject/exemplar](https://github.com/bemanproject/exemplar)
54
-
55
-
## Other resources
56
-
54
+
-[C++ best practices](https://github.com/cpp-best-practices/cppbestpractices) (Jason Turner)
57
55
-[It's Complicated](https://www.youtube.com/watch?v=tTexD26jIN4) (Kate Gregory, Meeting C++ 2017 Keynote)
58
56
-[10 Core Guidelines You Need to Start Using Now](https://www.youtube.com/watch?v=XkDEzfpdcSg) (Kate Gregory, CppCon 2017)
59
57
-[Undefined Behavior in C++: What Every Programmer Should Know and Fear](https://www.youtube.com/watch?v=k9N8OrhrSZw) (Fedor Pikus, CppCon 2023)
60
58
-[Crafting the Code You Don’t Write: Sculpting Software in an AI World](https://www.youtube.com/watch?v=v6OyVjQpjjc) (Daisy Hollman, CppCon 2025)
61
-
-[Learning To Stop Writing C++ Code (and Why You Won’t Miss It)](https://www.youtube.com/watch?v=mpGx-_uLPDM) (Daisly Holman, ACCU 2025)
59
+
-[Learning To Stop Writing C++ Code \(and Why You Won’t Miss It\)](https://www.youtube.com/watch?v=mpGx-_uLPDM) (Daisly Holman, ACCU 2025)
62
60
-[You've just inherited a legacy C++ codebase, now what?](https://gaultier.github.io/blog/you_inherited_a_legacy_cpp_codebase_now_what.html), great blog post on working with a legacy C++ code base, but most tips apply to any language; also see the related [HackerNews thread](https://news.ycombinator.com/item?id=39549486) and the [blog post](https://medium.com/@ramunarasinga/git-blame-ignore-revs-to-ignore-bulk-formatting-changes-f20ac23e6155) on how to ignore large formatting changes using [.git-blame-ignore-revs](https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revltrevgt)
63
61
-[cppreference.com](https://en.cppreference.com/), language reference
64
62
-[C++ Insights](https://cppinsights.io/) and [Compiler Explorer](https://compiler-explorer.com/) to better understand the compiled code and how the compiler works
@@ -80,4 +78,13 @@ Below are some highlights.
80
78
-[Rust Devs Think We’re Hopeless; Let’s Prove Them Wrong (with C++ Memory Leaks)!](https://www.babaei.net/blog/rust-devs-think-we-are-hopeless-lets-prove-them-wrong-with-cpp-memory-leaks/)
81
79
-[Lessons Learnt from a Rust Rewrite](https://gaultier.github.io/blog/lessons_learned_from_a_successful_rust_rewrite.html)
82
80
- Comparing with Rust: "In my experience, C++ is a much more complicated language. The 8 ways to initialize something, the 5 types of values (xvalues etc.), inconsistent formatting conventions, inconsistent naming conventions, the rule of 5, exceptions, always remembering to check `this != other` when doing a move assignment operator, perfect forwarding, SFINAE, workarounds for not having a great equivalent to traits, etc. Part of knowing the language is also knowing the conventions on top that are necessary in order to write it more safely and faster (if your move constructor is not noexcept it'll cause copies to occur when growing a vector of that object), and learning the many non-ideal competing ways that people do things, like error handling." ([HackerNews comment](https://news.ycombinator.com/item?id=45606560))
83
-
- "In C/C++, making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword." (John Carmack [tweet](https://x.com/ID_AA_Carmack/status/1983593511703474196))
81
+
82
+
## My notes
83
+
84
+
Some loose notes from reading and working through some tutorials:
85
+
86
+
- Disable [function overloading and implicit conversions](https://www.learncpp.com/cpp-tutorial/introduction-to-function-overloading/), for example using the `explicit` keyword and strict clang settings (`cppcoreguidelines-explicit-virtual-functions`, `google-explicit-constructor`, `cppcoreguidelines-narrowing-conversions`)
87
+
- Use `const` almost everywhere, for input arguments to functions and when initializing variables (see John Carmack's [tweet](https://x.com/ID_AA_Carmack/status/1983593511703474196) and Jason Turner's [guide](https://github.com/cpp-best-practices/cppbestpractices/blob/master/04-Considering_Safety.md#const-as-much-as-possible))
88
+
- Use `constexpr` (or `consteval`) for everything that can be computed at compile time
89
+
- Use `[nodiscard]` for not forgetting about a return value
0 commit comments