c++

a mental map of production c++. what i learn, what matters.

practice

intent first.
the pr, in jargon
→
the intent, in plain words
→
then touch the code
can't say it simply? don't understand it yet.

reading c++

a function, left to right.
Shelfgives back
MakeShelfname
(optional<int> limit)takes in
{ … return s; }does
every function is the same four slots. find them first, read the body last.
maybe a value.
optional<int>
→
12
nullopt · empty
a box that might be empty. *x opens it.
build a thing by naming its parts.
Book{make a Book
.title = "dune",set this field
.pages = 412,and this one
}rest = empty / zero
fields go in the order the struct declares them.
put it in a lookup table.
booksthe table
.emplace(insert
"b1",key
Book{…})value
like a python dict. built in place, no extra copy.
symbols.
a.bfield b of object a a->bsame, but a is a pointer A::bb lives inside A (a namespace, class, or enum) std::standard library *xopen the box: what x points to / holds &xthe original, not a copy constread only autocompiler figures out the type <T>fill-in-the-type: list<int> = list of ints
a test, in three moves.
build fake input
→
run the code
→
EXPECT: got == wanted
most test code is setup. skip to the EXPECTs to see what it actually checks.

build: bazel

workspace.
workspace = one build unit
root file marks the start
a name others point at
→ external deps sibling dirs · third-party, pinned by hash
→ toolchains compilers · target platforms
pinned by hash = every build comes out the same.
dependency direction.
app layer
old code
test: old vs new
↓ depends on   ✕ never ↑
shared foundation
new code
where code lives decides what it can see. migrating? check the direction first. the test goes where it sees both.
← back