r/cpp_questions • u/Substantial-Rain8916 • 21d ago
OPEN Cpp books
Hi I'm a first year from a tier 3 university. I want to learn about cpp i have basic knowledge about C++
Inheritance, getters and setters etc I'm also learning data structures and algorithms. I want to improve my cpp knowledge, what books you guys recommend . I personally thought about going for The C++ Programming Language by Bharne Stroustrup. What are some of the better books than this I'm also targeting quant as of now but as a backup I'm keeping software engineering.
26
Upvotes
View all comments
1
u/mredding 20d ago
The way programming is taught is completely disconnected from how it's used. A tutorial will sacrifice good taste just to illustrate the point of the lesson. This means you get absolute garbage like getters and setters; the point isn't that they're a good idea, the point is to show you access control, membership, and consequences.
Accessors and mutators are a C idiom around abstract or opaque data. In a header, you'll only see this:
You don't know what a
foois. You don't know how it's created, you don't know how it's initialized, you don't know it's layout, you don't know it's side effects, you don't know anything. These operations could be DB queries. This is an opaque pointer - the only thing you know about the pointer is the type name; it's only a resource handle to you that you can pass back to provide context as to WHICHfooyou want to get, set, or destroy. It's also abstract because even in C you can model inheritance or variants with overlapping types, so the real object may not be afooat all.But you're not writing code like this, and accessors and mutators typically make for bad object design. A
carcanstop,go, andturn. NocarI've ever heard of couldgetMake. A car has a make, but that's a property associated with the car; the glass and metal and rubber don't care. This is why you need higher orders of abstraction to associate objects and properties, through loose coupling. If I'm busy driving a car, I don't even NEED agetMakeinterface, so why is it there?Classes model behaviors that enforce an invariant through the implementation of it's interface. You don't get or set the speed, you press the throttle; there's a whole orchestration under the hood that has to happen. Or not. As a client of
car, what do you care?