Zed A. Shaw
d8f98afa55
|
7 months ago | |
---|---|---|
.. | ||
Makefile | 7 months ago | |
PPP.h | 7 months ago | |
PPP_support.h | 7 months ago | |
README.md | 7 months ago | |
date.h | 7 months ago | |
ex01.cpp | 7 months ago | |
ex02.cpp | 7 months ago | |
ex03.cpp | 7 months ago | |
ex04.cpp | 7 months ago | |
ex05.cpp | 7 months ago | |
ex06.cpp | 7 months ago | |
ex07.cpp | 7 months ago | |
ex08.cpp | 7 months ago | |
goc.cpp | 7 months ago | |
meson.build | 7 months ago | |
stats.py | 7 months ago |
README.md
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, 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 so if you got the sfmldemo
to work then you should be ready to go. You need to do this:
mkdir builddir
meson setup builddir
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 and clang-tidy for checking the code while I work. I also use Tim Pope's 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:
:cd builddir
- Run the build in Vim and now the error paths will be correct.
- 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
- 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
PPP.h
andPPP_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. - Nothing actually works as written. Not a single example given in the book actually compiles. Header files are skipped even when they'rr 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 onPPP.h
means people don't learn the real includes needed to make the code work. - 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 are dead and sometimes labeled "TBD".
- 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 theToken_stream
after all the parsing code. This means that none of the parsing code he's talking about actually works until you get to theToken_stream
later, which is backwards. Many examples are also progressively improved versions of functions but that require later code to even work. - 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 <iostream>
to makestd::cout
to work? - 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 thePPP.h
file you can't use, but then gets into writing a calculator that usesclass
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.
6. Constantly using things that don't exist. The book is riddled with things that are claimed to be supported or standard, but that isn't available in many compilers. A great example is std::format
, which would be great since I planned on having people use the excellent fmt
library, but none of the compilers I have had this. He does this all the time where he just assumes something exists but it doesn't, and what's even more irritating about this is it's not hard at all to test. There's only like 4 compilers to verify. A single test suite could do it, but nope, I'm forced to research it myself.