Skip to content

Commit e925988

Browse files
committed
update cpp post
1 parent 3c755c7 commit e925988

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

content/posts/learning-cpp.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For a real-time visualisation of the build process, see [this post](https://dani
1212

1313
Best practices:
1414

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/))
1616
- 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))
1717
- 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`
1818
- Static analysis: linters, formatters (e.g. `clang-tidy` and `clang-format`)
@@ -32,7 +32,7 @@ Below are some highlights.
3232
### Tutorials
3333

3434
- [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))
3636
- [C++ Study Plan](https://www.studyplan.dev/cpp)
3737
- [Learn C++ in Y Minutes](https://learnxinyminutes.com/c++/), very concise introduction
3838

@@ -45,20 +45,18 @@ Below are some highlights.
4545
- [Debugging](https://www.youtube.com/watch?v=qgszy9GquRs)
4646
- [C++ Coding with Neovim](https://www.youtube.com/watch?v=nzRnWUjGJl8)
4747

48-
### Other resources
48+
### Miscellaneous
4949

5050
- [cplusplus.com](https://cplusplus.com/), community tutorials, forum and blog posts
5151
- [Cheat sheet](https://hackingcpp.com/cpp/cheat_sheets.html) with [HackerNews thread](https://news.ycombinator.com/item?id=30579884)
5252
- Well-written C++ repos: [nlohmann/json](https://github.com/nlohmann/json)
5353
- 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)
5755
- [It's Complicated](https://www.youtube.com/watch?v=tTexD26jIN4) (Kate Gregory, Meeting C++ 2017 Keynote)
5856
- [10 Core Guidelines You Need to Start Using Now](https://www.youtube.com/watch?v=XkDEzfpdcSg) (Kate Gregory, CppCon 2017)
5957
- [Undefined Behavior in C++: What Every Programmer Should Know and Fear](https://www.youtube.com/watch?v=k9N8OrhrSZw) (Fedor Pikus, CppCon 2023)
6058
- [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)
6260
- [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)
6361
- [cppreference.com](https://en.cppreference.com/), language reference
6462
- [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.
8078
- [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/)
8179
- [Lessons Learnt from a Rust Rewrite](https://gaultier.github.io/blog/lessons_learned_from_a_successful_rust_rewrite.html)
8280
- 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
90+
- Use `noexcept` for performance optimization

0 commit comments

Comments
 (0)