|
| 1 | +# A learning path through the lab |
| 2 | + |
| 3 | +The menu is organized by topic; this page suggests an order. Run an example with |
| 4 | + |
| 5 | +```bash |
| 6 | +./build/bin/cpp_lab_project --run <id> |
| 7 | +``` |
| 8 | + |
| 9 | +and read its source next to the output - the header comment of each file says what it teaches. |
| 10 | + |
| 11 | +--- |
| 12 | +## Stage 1 - the language you write every day |
| 13 | + |
| 14 | +| # | Example | Take away | |
| 15 | +|---|---------|-----------| |
| 16 | +| 1 | `core/basics/Initialization` | prefer `{}`; know what stays uninitialized | |
| 17 | +| 2 | `core/basics/Operations` | integer division, unsigned wrap-around, short-circuit | |
| 18 | +| 3 | `core/basics/ControlFlow` | if with initializer, range-for, why `goto` is rare | |
| 19 | +| 4 | `core/datatype/Fundamental` | sizes are minimums; use `<cstdint>` when width matters | |
| 20 | +| 5 | `core/datatype/Struct` | aggregates, designated initializers, padding | |
| 21 | +| 6 | `core/datatype/Enum` | `enum class` over plain `enum` | |
| 22 | +| 7 | `core/basics/TypeQualifier` | const vs constexpr vs consteval | |
| 23 | + |
| 24 | +## Stage 2 - memory and indirection |
| 25 | + |
| 26 | +| # | Example | Take away | |
| 27 | +|---|---------|-----------| |
| 28 | +| 8 | `core/datatype/Pointer` | `&`, `*`, the three const positions, pointer arithmetic | |
| 29 | +| 9 | `core/datatype/Reference` | references cannot be null or re-seated; `std::move` is a cast | |
| 30 | +| 10 | `core/datatype/Array` | arrays decay to pointers and lose their size | |
| 31 | +| 11 | `core/smart_pointer/Unique` | ownership belongs in the type system | |
| 32 | +| 12 | `core/smart_pointer/Shared` | shared ownership costs a control block | |
| 33 | +| 13 | `core/smart_pointer/Weak` | break reference cycles | |
| 34 | + |
| 35 | +## Stage 3 - your own types |
| 36 | + |
| 37 | +| # | Example | Take away | |
| 38 | +|---|---------|-----------| |
| 39 | +| 14 | `core/class/Encapsulation` | invariants live behind a small interface | |
| 40 | +| 15 | `core/class/Constructor` | initializer lists, delegating, explicit | |
| 41 | +| 16 | `core/class/Destructor` | destruction order and RAII | |
| 42 | +| 17 | `core/class/ShallowDeepCopying` | copying a pointer is not copying the data | |
| 43 | +| 18 | `core/class/RuleOfThreeFiveZero` | write five, or better none | |
| 44 | +| 19 | `core/class/Binding` | hiding vs overriding, virtual dispatch | |
| 45 | +| 20 | `core/class/Relationship` | composition, aggregation, association | |
| 46 | +| 21 | `core/function/operator_overloading/ArithmeticOperator` | operators behave like the built-in ones | |
| 47 | +| 22 | `core/function/operator_overloading/ComparisonOperator` | `<=>` writes the comparisons for you | |
| 48 | + |
| 49 | +## Stage 4 - the standard library |
| 50 | + |
| 51 | +| # | Example | Take away | |
| 52 | +|---|---------|-----------| |
| 53 | +| 23 | `core/string/StdString` | `std::string` and `std::string_view` | |
| 54 | +| 24 | `core/string/StringFormatting` | `std::format` beats streams and `printf` | |
| 55 | +| 25 | `core/container/sequence/Vector` | capacity, reallocation, invalidation | |
| 56 | +| 26 | `core/container/unordered/UnorderedMap` | `operator[]` inserts; `find`/`contains` do not | |
| 57 | +| 27 | `core/container/associative/Set` | sorted, unique, `lower_bound` | |
| 58 | +| 28 | `core/utils/Algorithm` | name the loop: algorithms and ranges | |
| 59 | +| 29 | `core/function/Lambda` | captures decide lifetime | |
| 60 | +| 30 | `core/function/Functional` | `std::function` for stored callbacks | |
| 61 | +| 31 | `core/utils/Optional` | say "no value" in the type | |
| 62 | + |
| 63 | +## Stage 5 - failure, files and time |
| 64 | + |
| 65 | +| # | Example | Take away | |
| 66 | +|---|---------|-----------| |
| 67 | +| 32 | `core/exception/BasicHandle` | throw by value, catch by const reference | |
| 68 | +| 33 | `core/exception/ThrowNoexcept` | `noexcept` moves make containers fast | |
| 69 | +| 34 | `core/filehandle/IOStream` | stream states and input validation | |
| 70 | +| 35 | `core/filehandle/FileIO` | text files with RAII | |
| 71 | +| 36 | `core/filehandle/Directory` | `std::filesystem` | |
| 72 | +| 37 | `core/datetime/Time` | `<chrono>` and the C time API | |
| 73 | + |
| 74 | +## Stage 6 - concurrency |
| 75 | + |
| 76 | +| # | Example | Take away | |
| 77 | +|---|---------|-----------| |
| 78 | +| 38 | `core/concurrency/ThreadManagement` | join or `std::jthread`, never a dangling thread | |
| 79 | +| 39 | `core/concurrency/SharingData` | arguments are copied unless you say otherwise | |
| 80 | +| 40 | `core/concurrency/RaceCondition` | see updates get lost, then fix it | |
| 81 | +| 41 | `core/concurrency/ConditionVariable` | wait with a predicate | |
| 82 | +| 42 | `core/concurrency/FuturePromise` | results and exceptions across threads | |
| 83 | + |
| 84 | +## Stage 7 - design patterns |
| 85 | + |
| 86 | +Start with the ones you will recognize immediately: |
| 87 | +`dp/creational/FactoryMethod`, `dp/structural/Adapter`, `dp/structural/Decorator`, |
| 88 | +`dp/behavioral/Strategy`, `dp/behavioral/Observer`, `dp/behavioral/Command`. |
| 89 | + |
| 90 | +Then the rest of `dp/creational`, `dp/structural` and `dp/behavioral`. Each example first shows |
| 91 | +the problem the pattern solves; several end with the modern C++ alternative (`std::function`, |
| 92 | +`std::variant`, ranges). |
| 93 | + |
| 94 | +## Stage 8 - systems and applications |
| 95 | + |
| 96 | +| Example / program | Take away | |
| 97 | +|---|---| |
| 98 | +| `core/linkage/Linkage`, `core/linkage/sharing/Sharing` | what the linker sees | |
| 99 | +| `socket/simple_tcp/LoopbackEcho` | sockets end to end in one process | |
| 100 | +| `socket/simple_tcp/SimpleTCPServer` + `SimpleTCPClient` | the same across two processes | |
| 101 | +| `socket/multiple_client/MultiTCPServer` | a thread per connection | |
| 102 | +| `controller/pid/PIDSim` | a control loop | |
| 103 | +| `./build/bin/mvc_ap`, `./build/bin/mvvm_ap` | the same GUI with two architectures | |
| 104 | +| `./build/bin/demo_dlopen` | loading a plugin at run time | |
| 105 | +| `src/embedded` | a firmware image booting in QEMU | |
| 106 | + |
| 107 | +--- |
| 108 | +When something surprises you, change the example and rebuild - that is what the lab is for. |
| 109 | +Then write your own: see [adding-examples.md](adding-examples.md). |
0 commit comments