Live data from Hacker News

3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

stroustrup.com

41–50 of 231 posts

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#41
post #33

Earlier quoted context omitted.

I started off writing C++ this way, basically writing it like it was C89. This is fine if you do not plan to share your work with others, but it's not well-written C++. It will bite you later on. It's best to learn the C++ way of doing things. It will save you so much time and headache. Don't use character arrays, use strings. Don't use C arrays, use std::vector or std::array. Don't write your own lists or sets, use…

In particular, you don't need volatile unless you're writing hardware device drivers. If you're doing that, then you also need to understand the semantics of the memory mappings of the I/O pages you're writing. You also need to know about bus ordering and request coalescing guarantees for PCIe (or AXI, or whatever your embedded system uses). If that paragraph doesn't make any sense, and you think you need volatile th…

> (or __sync_* for C)

Actually even C has _Atomic these days!

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#42
post #2

Sharing the C++ Annotations here, which is a continiously updated book on modern C++. http://www.icce.rug.nl/documents/cplusplus/

If I just use C with classes, plus smart pointers and auto, for my emulator project(s), would that be a reasonably good approach? I once heard that the C++ language contains 4 components: the first catalog is "C", the second is for OOP, the third is for productivity and flexibility such as stl and templates, and the last one is for special cases such as volatile, asm, etc. He then recommends to use catalog 1 with car…

These days, OO programing is mostly frowned upon. OO added the idea of implementation inheritance to interfaces, and that's mostly a bad idea.

Newer languages and modern C++ favor composition instead. You define interfaces that provide some well-defined capability, and then you write things that wrap the interfaces to provide additional functionality. In C++ you can use templates to do this without any runtime overhead. In C, you can either use preprocessor macros (ouch) or you can build your own vtables. The vtable approach adds virtual method invocations all over the place, so it's not zero cost.

The C++ approach actually isn't zero-cost either: You can end up having many copies of the same template logic, which blows up your instruction cache. One of the big innovations of swift was to avoid that. As far as I know, Rust macros and "go generate" produce binaries that are closer to the C++ approach.

Anyway, especially for emulators, you should look into getting good with C++ template meta programming, or just learn rust and then use its implementation of generics. Both approaches will let the compiler inline the heck out of stuff that ends up in the inner loop. In particular, clang + gcc are both good at constant propagation.

One problem with jumping straight from C to rust is that you basically have to already be able to write stable C++ code in order to get it to compile at all. The borrow checker moves subtle but common C++ errors from runtime to compile time. If you have a lot of experience with C already, the jump might be OK.

(edit: I should add that C++ isn't standing still, and there are lots of cool efforts to backport the good ideas from Rust to it. Systems language competition is a good thing, and they're my two favorite languages!)

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#44

Earlier quoted context omitted.

I just wish to _not_ work with Python.

Why is that? I'm genuinely curious. Also, what languages / environments do you prefer?

Not gp but I prefer rust to python and I'm itching to try that "just write your build scripts and stuff in rust too"

Sure the builds are slow and Python _kinda_ has static typing, but rust just has a lot of stuff I like and it's practical to install and use natively without learning all the jargon like venvs and eggs and wheels and which package manager and package manager manager (rye?) to use this year

I tried Python years ago and never got the motivation to push through that learning curve. I've used c++ a lot but it always required me to "keep my hands inside the ride at all times". Rust feels like it actually wants to be easy to use

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#45
post #34

Sorry if it is a bit off-topic. If you just started learning C++, why did you choose it instead of another language? (Rust, C#, Go, etc) I know a bit of C but feel that the sheer "thickness" of C++ is too daunting and scary to even start.

The most complex, demanding and cutting edge computational fields - Machine Learning, Artificial Intelligence, Real-time multi-user Gaming, High frequency Trading, Rendering/Animation, High Performance Computing, Compiler infrastructure (LLVM) - are all at the core written in C++ for the most part. There is no other option in the foreseeable future as the investment needed to rewrite (if you can find the people) is in the $100's of billions. So you will need to know C++ if we want to be the cutting edge and need extreme performance.

On the other hand, if you don't need these "hard-core" features then any language will do. In fact, most of these have Python or other language interfaces so you don't need to know much C++.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#47

Earlier quoted context omitted.

I just wish to _not_ work with Python.

Why is that? I'm genuinely curious. Also, what languages / environments do you prefer?

Same for me. Mainly due to the packaging fiasco (and to a lesser extent, imports).

The actual language is not awful. Some features are even nice, like infinite precision integers by default, and separate / and // operators.

Language is ok. Setting everything up is atrocious.

The other quite annoying thing is that the docs are extremely badly organised so Google rarely points you directly at what you want. Instead you get stuff like w3schools which is trash, but much better organised. Also annoying that the docs still don't include types.

I would use Typescript (via Deno), Go or Rust instead. There are some other Python replacement languages I haven't tried yet that might be an option like Mojo, Lobster, Nim. Probably still too niche for production; I'd stick with Typescript.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#48

Earlier quoted context omitted.

I just wish to _not_ work with Python.

Why is that? I'm genuinely curious. Also, what languages / environments do you prefer?

Because Python falls all over itself in larger projects, and is poor at utilizing resources efficiently. It's fine for smaller things that don't care about cpu cycles. I would much rather use Rust in a large project.

Re: 3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup

#49

Earlier quoted context omitted.

Why is that? I'm genuinely curious. Also, what languages / environments do you prefer?

Same for me. Mainly due to the packaging fiasco (and to a lesser extent, imports). The actual language is not awful. Some features are even nice, like infinite precision integers by default, and separate / and // operators. Language is ok. Setting everything up is atrocious. The other quite annoying thing is that the docs are extremely badly organised so Google rarely points you directly at what you want. Instead you…

Pixi.sh has been great for me so far, it’s a single binary install that can install Python, conda packages and PyPi packages, maybe give it try!
Post reply on HN