From a03da909f19e1f4f3516879625088b6ed0bccbe5 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 1 May 2024 21:25:37 -0400 Subject: [PATCH] Add notes about PPP3 for people to read and follow. --- PPP3/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 PPP3/README.md diff --git a/PPP3/README.md b/PPP3/README.md new file mode 100644 index 0000000..d538f73 --- /dev/null +++ b/PPP3/README.md @@ -0,0 +1,40 @@ +# Stroustrup's PPP3 Study + +The last time I did C++ seriously was 1996. That was 28 years ago. Damn I'm getting old. If I'm going to use C++ to make some games and teach people how to code C++ then I better relearn the latest stuff. + +To relearn C++ I bought [Stoustrup's Principles and Practice Using C++ 3rd Edition](https://www.stroustrup.com/PPP3.html), +or PPP3 for short. This part of the repository are my study files so people can read them, and my +critique of the book as I go through it. + +## Getting the Code to Work + +It uses [meson](https://mesonbuild.com/) so if you got the `sfmldemo` to work then you should be ready to go. You need to do this: + +1. `mkdir builddir` +2. `meson setup builddir` +3. `meson compile -C builddir` + +The "exercises" are then compiled into `builddir` so to run `ex06.cpp` you do `./builddir/ex06`. + +## Editing the Code + +I'm using Vim with [clangd](https://clangd.llvm.org) and [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) for checking the code while I work. I also use Tim Pope's [vim-dispatch](https://github.com/tpope/vim-dispatch) to run the builds but there's a slight problem with how Meson is setup. + +Meson requires you to do the builds in `builddir`, and it does this by doing a `cd builddir` then running `ninja`. This keeps the source tree clean of build junk, but now all of the error messages from the C compiler are in the wrong location. They'll list an error in `ex06.cpp` as `../ex06.cpp`. Vim can pick this up, then then it goes one directory up to find the file. It's incredibly irritating that Vim doesn't have an ability to adapt to this given how many C++ build tools use this pattern, but the way I solve this is simple: + +1. `:cd builddir` +2. Run the build in Vim and now the error paths will be correct. +3. Just remember to edit files with `:e ../ex06.cpp`. + +This is dumb as hell but it's working for now. If you have a fancy way to tell Vim "Hey, all paths in the error buffer are one level up" then let me know. + +## Criticisms of PPP3 + +1. **Bad support code and future proofing.** This book is attempting to teach C++23 (the 2023 version of the standard) in a world that doesn't correctly support 2023. To make this work he has these header files `PPP3.h` and `PPP3_support.h` and other random files you're supposed to include with no explanation on how to _actually_ use them. When I try use them (they're included in this repo) they don't compile. I could spend the time to make them work, but it's actually easier to just take his code and make it work without these headers. +2. **Nothing actually works as written.** Not a single example given in the book actually compiles. Header files are skipped even when they'r essential to the code's function. He just assumes you'll use `PPP.h` but that doesn't even include everything correctly, and as I said, his files don't even work without a mythical advanced compiler from the future. Also, relying on `PPP.h` means people don't learn the real includes needed to make the code work. +3. **No full sample code available.** Normally in this situation I'd go find the sample code download or see if there's a github repository of the code, but all of his links to sample code on the [his website for the book](https://www.stroustrup.com/PPP3.html) are dead and sometimes labeled "TBD". +4. **Disjointed incomplete examples.** There's all kinds of examples that feature code from one part of the system that relies on another part that either doesn't exist or isn't explained well. A good example is the calculator, where you're making a parser. In Chapter 5.6 he has code for parsing the calculator language that all use a `Token_stream` class, but only implements the `Token_stream` _after_ all the parsing code. This means that none of the parsing code he's talking about actually works until you get to the `Token_stream` later, which is backwards. Many examples are also progressively improved versions of functions but that require later code to even work. +5. **No explanation on actually building the code or setting up an environment.** In the very beginning he claims the book is for people who have no programming experience but want to work hard. He then dives right into the classic "hello world" but no explanation on how to get that to compile. No instructions for installing software, no explanation of build tools, or compilers that work, nothing. You might think this is to be "high class" and not focus on such "trivial nonsense" but there's only like 4 compilers he has to worry about, 2 if you want only C++23 features. He could totally figure out instructions for 2 compilers. Without instructions on how to properly setup and compile that first version the book is completely useless for the total beginner he claims to target. Even as a seasoned professional I couldn't figure out how to get his `PPP.h` to work, so how is someone who knows nothing about C++ supposed to figure it out? Since the code samples are incomplete, how is a beginner supposed to know they need `#include ` to make `std::cout` to work? +5. **Disorganized presentation of the core concepts.** The book is all over the place. First you cover objects, types, and values, but this doesn't cover objects it covers base types like `int`, then it goes into computation but nothing about classes and struct, then he gets into error reporting with a reporting method that doesn't work without the `PPP.h` file you can't use, but then gets into writing a calculator that uses `class` but no explanation of that until Chapters 7 and 8 which finally explains all the things you needed to work on the calculator. It's understandable to not cover things until you can explain them later, since programming is so complicated you do have to gloss over concepts until later. But, Chapters 7 and 8 should have probably replaced the majority of the content in chapters 1-4 before he gets into making code with the concepts. + +That's my critique for far. Basically, the book is your classic code book where the author has absolutely no idea who he's writing the book for, and just assumes that everyone who reads it has his brain and his computer. He most likely has a whole directory full of the code in the book but you and I will never see it. It's also _definitely_, _DEFINITELY_ not a beginner book. I couldn't imagine someone who's never written code trying to setup MinGW with Meson on a Windows machine or even getting Visual C++ to work, let alone figure out his mishmash of `PPP_*.h` files.