Live data from Hacker News

Modern C++ Programming Course

github.com

181–190 of 221 posts

Re: Modern C++ Programming Course

#181
post #176

Earlier quoted context omitted.

I think you missed exceptions often being a problem in low level and embedded targets. That knocks out most of STL anyway. I also think you are a bit harsh on virtual functions - it introduces a single indirection, yes, but sometimes that is fully justified. RTTI on the other hand... of course depends a bit on target characteristics. Perhaps controversial, I've also found (especially bare) lambdas and even std::funct…

If you can't use the STL because of exceptions: https://www.etlcpp.com/

Sure, there are more embedded friendly libraries, but that wasn't the topic.

Re: Modern C++ Programming Course

#182
post #162
post #13

Any ideas where to start learning C++ as an embedded developer? I wrote many lines of bare metal C code and want to transit to higher level jobs. I see many expensive or completely free courses, but I am not sure which one is usable in my complicated situation.

Do you want to do embedded/low level c++, or are you looking to transition out of that?

I will get out. Application development using C++ and Python. Maybe C#.

Re: Modern C++ Programming Course

#183
post #156
post #130

What is the C++ job market like? I do mostly Python / web app developmnt, but I don't like the churn.

If you are strong in C++ you can get pretty good jobs in robotics, trading, game engines. But TBH at that point it might be more interesting to learn Rust that is on the rise across the industry.

Nobody (except hobbyists and maybe an indie or two) is using Rust for game development, and it's unlikely they ever will. The cost of switching far outweighs any benefits in an industry where memory safety is not critical.

C++ is here to stay for a very long time.

Re: Modern C++ Programming Course

#184
post #164

Earlier quoted context omitted.

It really depends on your career goals and whether you're doing greenfield or maintenance coding. If you want to be part of the "new generation" of tech, learn Rust. If you want job security, dont care about doing anything glamorous or exciting, and don't mind a long learning journey, go with C++. It will always be around and it's hard enough to learn that you won't have as much competition.

Only things written in Rust I know are rewrites of decades old C applications or rewrites of js tooling. What "new generation" of games, browsers, editors, CAD applications, etc. are written in Rust? Is Rust used in aerospace, automotive, healthcare, instrumentation or finance industries? What is glamorous in Rust that hasn't been done in other languages?

It is difficult to answer this question because there are so many answers, and they're so broad. I will try to give some partial answers.

> games

Some indie games, a new AAA studio has been working on a game for a while (Embark, their first game is still in C++ but they are building the foundations for the next ones, which takes time), at least one AAA studio known to use it for tooling (Treyarch). The first time I personally gave a talk at a AAA studio about Rust was 2019, though I don't believe that studio is using it for anything I am aware of.

> browsers

Firefox is about 12% Rust by volume, but is also only 41% C and C++, so it's about a quarter of the relevant systems level code. Chromium has Rust in the tree, but only libraries right now, they don't write new code yet except wrappers. Brave has an adblock component in Rust.

> CAD applications

Not aware of movement here.

> aerospace,

Very early days, some small projects, nothing massive yet.

> automotive,

This one is gearing up massively: a rust compiler was just qualified for the relevant safety standards to be used in automotive, several large manufacturers have had job openings open mentioning Rust. It certainly hasn't taken over the world yet but there's a lot of actual movement in this space.

> healthcare,

Not aware of specific things here.

> instrumentation

I don't know what the "instrumentation industry" is.

> finance

Some players are using some things, but as a very proprietary industry, not a lot of specifics are known. I have given an internal talk at a big hedge fund a few years back, unsure if they're doing anything in production just yet.

There are other big successes that aren't covered by these industries; Shopify adding a JIT to Ruby, Cloudflare's heavy use of Rust (which means that a significant chunk of internet traffic passes through Rust code), AWS's heavy use of Rust (the core of products like Lambda and S3 are in Rust these days), Apple using it for network services appparently, Meta keeping their monorepo in a version control system written in Rust, and it being an official language to use on projects there, Google using Rust for significant components in Android, Windows having added Rust code already, with more to come, Rust becoming the next language used in the Linux kernel... the stories are endless at this point.

Re: Modern C++ Programming Course

#185
post #183
post #156

Earlier quoted context omitted.

If you are strong in C++ you can get pretty good jobs in robotics, trading, game engines. But TBH at that point it might be more interesting to learn Rust that is on the rise across the industry.

Nobody (except hobbyists and maybe an indie or two) is using Rust for game development, and it's unlikely they ever will. The cost of switching far outweighs any benefits in an industry where memory safety is not critical. C++ is here to stay for a very long time.

Treyarch gave a GDC talk in 2019 that they were using it for tooling, Embark hasn't shipped a game in Rust yet but is larger than an indie. You are absolutely right that it is small right now, but "unlikely they ever will" is a more open question, IMHO.

Memory safety is absolutely important in certain kinds of games. At least, as a player, I want games to not be exploited for cheats, and I don't want progress lost when a game crashes due to memory issues.

All that said, I would agree that if you want a job in games, learning C++ is a better idea than Rust right now.

Re: Modern C++ Programming Course

#186
post #155

I think nowadays smart pointers should not be considered an "advanced topic" in C++. Smart pointers are usually the best way to handle memory management. It's definitely useful to learn about "new" and "delete", because those are the primitives that memory management is built on top of. But it should be followed up with good advice like, rarely use these in practice. You should almost always be using unique_ptr or sh…

> You should almost always be using unique_ptr or shared_ptr I really wish there was a thread unsafe version of shared pointers, without atomics overhead, in the standard. Maybe without weak pointers.

[deleted]

Re: Modern C++ Programming Course

#187

Earlier quoted context omitted.

Maybe, in this context it makes lots of sense, if you know C well there are things which "just work how you expect" in C++ and so they need at most a brief refresher. I agree with Kate Gregory that this is a bad way to teach C++ from scratch. That is, if you know only say, Python or Java (or nothing) and want to learn C++, you should not begin by learning C. Kate's approach skips many of the things you can do in C++…

Can you maybe share some paid/unpaid resources to learn C++ from scratch for someone coming from Java and JS?

Kate has a PluralSight course which I have watched (not really to learn C++ but to see her approach) and that seemed decent to me, although of course I can't vouch for it having taught what you'd need coming from Java and JS, not least because my background is far more polyglot including Scheme and the Standard ML for example.

I definitely think Bjarne Stroustrup's book about his own language isn't very good, even in later editions (which correspond to a more modern language) and so I would avoid buying that, I'm not sure it's a good defence of the language as an idea and I'm sure it isn't an effective tutorial, even if not for being out-of-date.

Re: Modern C++ Programming Course

#188
post #155

I think nowadays smart pointers should not be considered an "advanced topic" in C++. Smart pointers are usually the best way to handle memory management. It's definitely useful to learn about "new" and "delete", because those are the primitives that memory management is built on top of. But it should be followed up with good advice like, rarely use these in practice. You should almost always be using unique_ptr or sh…

> You should almost always be using unique_ptr or shared_ptr I really wish there was a thread unsafe version of shared pointers, without atomics overhead, in the standard. Maybe without weak pointers.

If there's one thing C++ needs, it's more slightly-different varieties of smart pointers in the standard. ;-)

What exactly would you use these for? I find that usually I can get away with unique_ptr for the sort of object that I have many of where pointer performance matters.

Re: Modern C++ Programming Course

#189
post #176
post #96

Earlier quoted context omitted.

It depends on what you target. I do alot of Kernel and really low level C++, and it's a completely different style than even app dev, so you have to be sure you don't go down the completely wrong route. For my target space, there's a few rules for c++. Footguns: A. No STL, it causes to much bloat when binary size is critical. B. (almost) No inheritance or virtual functions. Again, it causes some bloat and adds in som…

I think you missed exceptions often being a problem in low level and embedded targets. That knocks out most of STL anyway. I also think you are a bit harsh on virtual functions - it introduces a single indirection, yes, but sometimes that is fully justified. RTTI on the other hand... of course depends a bit on target characteristics. Perhaps controversial, I've also found (especially bare) lambdas and even std::funct…

You can use quite a lot of STL even with -fno-exceptions. Things that you probably need to ditch are:

std::vector

std::list

std::map

std::unordered_map

std::set

std::unordered_set

std::sort

std::transform

std::merge

std::string

std::regex

std::swap

std::function

std::stable_partition

But there are much more than that in STL.

Re: Modern C++ Programming Course

#190

One thing that would have helped me when I started learning C++ was learning the C++ compilation model i.e. translation units. It is surprising how many people look surprised (that also claim they know the language) when you tell them that code in .cpp does not get inlined into other .cpp files no matter what doing compilation. (yes the linker can (and should) do that with LTO doing linking)

This also helps understanding why template code completely wrecks compiletimes and ram usage since the compiler cant share template instantiations. This becomes very relevant if template metaprogramming is used in bigger projects.

That's not why. Template processing happens during processing of the translation unit, so it would be expensive even if you only had a single TU in your build. It's true that a template has to be reprocessed for each instantiation, however, that's not merely from one TU to the next, but even inside each TU! For every distinct value of T for std::vector in a single TU, the compiler has to process and generate std::vector entirely
Post reply on HN