Live data from Hacker News

LearnCPP: Website devoted to teaching you how to program in C++

learncpp.com

131–140 of 145 posts

Re: LearnCPP: Website devoted to teaching you how to program in C++

#131

Earlier quoted context omitted.

Please do not start with either C++ or C. They are horrible, horrible languages to learn as a beginner. Not because of bad tooling, incompatible compilers, tons of features, or even manual memory management and pointers, no. Two words: undefined behavior. In other languages, if you do a mistake, something fails around the place where you did it, or at least afterwards, or at least you can reason why the failure is ex…

Tooling did help this situation somewhat, but it is not very discoverable. If a beginner started off with a clang or gcc toolchain, then I would immediately suggest the following command line options for the compiler (the exact standard version does not matter, just stick to one): -std=c++20 -pedantic-errors -Wall -Wextra -fsanitize=address,undefined And there are a few toolchain specific macros worth adding. This wo…

For sure, I'd also add -Werror to the mix.

Re: LearnCPP: Website devoted to teaching you how to program in C++

#133
post #118

Earlier quoted context omitted.

Please do not start with either C++ or C. They are horrible, horrible languages to learn as a beginner. Not because of bad tooling, incompatible compilers, tons of features, or even manual memory management and pointers, no. Two words: undefined behavior. In other languages, if you do a mistake, something fails around the place where you did it, or at least afterwards, or at least you can reason why the failure is ex…

People grow by challenging themselves and this certainly applies to programming. One can’t use training wheels and expect to become skilled at system programming. I learned C++ as an absolute beginner in school back when most memory debugging tools didn’t even exist. Undefined behavior was just another bug that one learned to fix and most of the time it was nothing more exciting than a crash. Being disciplined avoide…

Absolutely, but it's much easier to understand arrays, strings, functions, loops and structs as high-level concepts first, and continue to manual memory management and UB only afterwards, rather than trying to do everything at the same time.

C++ is fun for sure, it was (and is) fun for me, but it's a very specific kind of fun.

Re: LearnCPP: Website devoted to teaching you how to program in C++

#134

Earlier quoted context omitted.

Tooling did help this situation somewhat, but it is not very discoverable. If a beginner started off with a clang or gcc toolchain, then I would immediately suggest the following command line options for the compiler (the exact standard version does not matter, just stick to one): -std=c++20 -pedantic-errors -Wall -Wextra -fsanitize=address,undefined And there are a few toolchain specific macros worth adding. This wo…

For sure, I'd also add -Werror to the mix.

It doesn't make a huge difference, if you use your compiler interactively, albeit it requires some discipline to not ignore them.

Absolutely do use -Werror on CI, where nobody even looks at logs of a passing pipeline.

Without -Werror you can see all your warnings at once, for better or worse.

Re: LearnCPP: Website devoted to teaching you how to program in C++

#135
post #120

As a newbie into programming, I get pulled all the time by people to learn my first compiled language either in C++ or Rust. Every time I ask even the most innocent question in any forum it becomes a shitshow, and I can see, I'm late to the party here in HN.

Most Rust stuff is just rewrites, crypto or some specific tool that some corporation or start-up needs. C++ is one of those languages that people write anything and everything in. Whatever you need, whatever you’re curious about, it’s likely out there. As for what it feels like, if you want safe but boring, go with Rust. If you want exciting go with C++. Personally I’d never start with Rust, it’s like biking everywhe…

Thanks for the laugh :)

Re: LearnCPP: Website devoted to teaching you how to program in C++

#136
post #42

Earlier quoted context omitted.

I haven't done any C++ since 2015ish but your link seems incredibly outdated. Sure you'll learn some C++ syntax, but you'll learn the C++ from 20 years ago, not the modern C++ with smart pointers and all that stuff which is basically turning it into a new language.

Is it a bad idea to learn from Stroustrup's 'Principles'?

No, it is a great book to get started with C++ if you already know programming.

Relevant: https://news.ycombinator.com/item?id=34233688

Re: LearnCPP: Website devoted to teaching you how to program in C++

#137
post #103

Earlier quoted context omitted.

Git submodules are definitely a hack. My experience with conan has been unpleasant for several reasons, but mostly in regards to writing dependencies for code bases that use submodules and aren't interested in my team's suggestion they use conan. Vcpkg doesn't seem better, and probably a bit worse. Does hunter make this any easier?

I'm not super clear what your question is. If the dependency you want to use has no dependencies of its own - then it can be used directly with no changes (as long it's CMakeLists.txt is sane and it can use a passed-in toolchain file) https://hunter.readthedocs.io/en/latest/creating-new/create/... If the dependency has its own dependencies, then you need to "Hunterize" it - specify library versions, tweak the targets…

Sorry I wasn't clear. I was responsible for the dependency that another team was using as a plugin. They weren't going to switch to conan, and our code was already using Conan for itself and its dependencies. They wanted to bring us in as a submodule, and that was just never going to work. I think what I'm pulling out of this thread is that c++ package management is so fragmented, there isn't really a safe choice to ensure you can use or be used by people who made other choices.

Re: LearnCPP: Website devoted to teaching you how to program in C++

#138
post #103

Earlier quoted context omitted.

I'm not super clear what your question is. If the dependency you want to use has no dependencies of its own - then it can be used directly with no changes (as long it's CMakeLists.txt is sane and it can use a passed-in toolchain file) https://hunter.readthedocs.io/en/latest/creating-new/create/... If the dependency has its own dependencies, then you need to "Hunterize" it - specify library versions, tweak the targets…

Sorry I wasn't clear. I was responsible for the dependency that another team was using as a plugin. They weren't going to switch to conan, and our code was already using Conan for itself and its dependencies. They wanted to bring us in as a submodule, and that was just never going to work. I think what I'm pulling out of this thread is that c++ package management is so fragmented, there isn't really a safe choice to…

Oh okay - I think in that case it's possible Hunter would solve your problems. If you rewrite your library to use Hunter, then when it gets pulled in with add_subdirectory(), it should just build and get it's dependencies with Hunter - all from within CMake itself. No external tool necessary (the Hunter functions are defined in the project root `.cmake` file)

I don't see any reason that wouldn't work - but.. you'd have to test it. I've never tried running a Hunterless top-level project with a Hunter-ized subdirectory. The top level project would still get some benefits like the namespaced targets (so you won't clobber anything in top-level)

The only small catch is that Hunter inevitably does build a cache of build artifacts/targets for your dependencies. As long as you keep using the same toolchain files these keep getting reused each time you rebuild your project. That does however mean you will get some user folder like ~/.hunter with those build artifacts (look at the Hunter config options.. maybe this can be somehow hidden in the build directory?). I dunno if that would irritate the project users. If it's company internal that's probably an okay ask. If it's random devs on github then that's a bit not-nice :)

Re: LearnCPP: Website devoted to teaching you how to program in C++

#139
post #82
post #65

Earlier quoted context omitted.

In a C++ course we teach at the Technical University of Munich (for students coming from a non-CS background), this is pretty much the direction we have recently steered the curriculum. It is amazing how we were always expected to "just figure out" all these very important practical aspects by ourselves as students, while these are so complicated for C++. In combination with a lot of outdated material out there, stud…

I always thought the pain was the point. They wanted you to struggle to figure it out, it’s how you learned how to learn. If everything is spoon-fed you end up unable to solve your problems when they arise. You expect someone else to have solved the problem and you start looking for them instead of attempting to solve it yourself. Kinda like the main plot point of Enders game.

I understand your point, and I had to argue on it a lot when introducing such changes. I think the answer is struggling for the right task, but again with some guidance. If the learning outcome is to learn to program, then I don't see why you should waste half a semester trying to figure out by yourself the technicalities that could help you go beyond a hello world. Similarly, I don't believe we should (nowadays) force people to write everything in the terminal using Vim. The additional cognitive load is too distracting that it prevents you from digging deeper.

One can say "but that's how I learned, and I am fine and shine today". This is probably true, but then I believe that such a person had the right background to anyway learn by themselves. I see our mission as teachers to help the students that actually need the help, rather than letting them give up too early, in favor of some kind of excellence evolution. And I believe that if we prepare the right groundwork (explaining all the ropes before we start pulling them), then even the more advanced students will be able to learn even more that they would by themselves in a more struggling environment.

Re: LearnCPP: Website devoted to teaching you how to program in C++

#140
post #122

Earlier quoted context omitted.

I'm already fairly deep into python, kinda knowledgeable in JS to make some minor stuff and currently I'm practicing a lot with git. After than it comes Java (i'm following a self-paced bootcamp path). Java seems interesting from an employment perspective, but the small stuff I've touched seems extremely verbose. I feel like I have to write and think way more to do simple stuff. But I just had a brief introduction, I…

The reason I mentioned c# is because it feels like "if Java adopted new features at a decent rate" and these days pretty much all of it is MIT licensed. Coming from Java to c#, I found it much more ergonomic and productive mostly due to less boilerplate and more concise syntax sugar. There are several ways to compile it to native if you need to and it has great c/c++ ffi support, although if you're doing a lot with m…

Hmm, so if java is a good introduction, I'll wait until I learn Java, thanks.
Post reply on HN