Live data from Hacker News

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

learncpp.com

101–110 of 145 posts

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

#101

Is this website any good? It's heavily pushed by some C++ subreddits. I don't even know what I would recommend to a newbie. I learned C 25 years ago, and dabbled in C++ 2 or 3 times since then. Bjarne's books might be great, but they aren't for anyone new to C++ and especially not anyone new to programming in general. C++ For Dummies/21 Days style books are just bad. And there are more bad websites than I can count.

> Bjarne's books might be great, but they aren't for anyone new to C++ and especially not anyone new to programming in general. I disagree. Not sure why PPP[1] wouldn't fit the bill. It's specifically geared to people who haven't programmed before. 1: https://stroustrup.com/programming.html

One example is that he uses a header file called "std_lib_facilities". So right out of the gate it confuses people, it's not actually shown until a little later in the book, there's tons of questions on C++ forums and StackOverflow where people get stuck on it.

It's just not a clear, step-by-step introduction.

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

#102
This is an excellent website to learn modern c++.

I still wish it had better navigation design, like a side bar for easy access to the ToC, or a drop-down menu for the same thing. I have to use the back|forward to do that.

cplusplus.com is out of date, but it has the simplest and easiest web interface to me comparing to either learncpp.com or cppreference.com, super easy and simple to navigate: https://cplusplus.com/doc/tutorial/

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

#103
post #77

Earlier quoted context omitted.

It's been quite a few years since I've really written any C++ and I'm surprised the landscape hasn't evolved at all. People are making the same mistakes... Modern CMake should be using toolchain files to specify the toolchain/flags. That should be included in ever CMake intro. (Hacking those into your CMakeLists.txt is not okay) gitsubmodules are also a hack 1: Many dependencies are not setup to be used as a CMake su…

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 to use namespaces, etc. They're usually small changes. They have a huge list of Hunterized forks:

https://hunter.readthedocs.io/en/latest/packages.html

Finally, a CMakeLists.txt that's been made to work with Hunter can always revert back and be run without Hunter. So the change isn't intrusive. https://hunter.readthedocs.io/en/latest/overview/compatibili...

A minimal CMakelists.txt will look something like:

    HunterGate(
        URL "https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz"
        SHA1 "3319fe6a3b08090df7df98dee75134d68e2ef5a3"
    )
    project(Foo)
    hunter_add_package(Boost COMPONENTS regex system filesystem)
    find_package(Boost CONFIG REQUIRED regex system filesystem)
    add_executable(foo foo.cpp)
    target_link_libraries(foo PUBLIC Boost::regex Boost::system Boost::filesystem)
The first block specifies the available package list (you can fork and host your own). If you disable Hunter this isn't used

The line that reads `hunter_add_package` is the Hunter part that downloads and build the dependency (using the current toolchain file). But if you disable Hunter then that line would simply get skipped.

In the third line `find_package` will run.. and if you had Hunter build the dependency then it'd use that as the target - otherwise it just runs like "normal CMake" and it tries to find the package elsewhere (like from your system package manager or whatever)

If your dependency has its own dependencies as git submodules.. then I'm not super sure you have a very clean migration path b/c they will not be using `find_package` and will instead be using `add_subdirectory`. Maybe you could patch their CMakeLists.txt to use Hunter when explicitely enabled, and then drop down to `add_subdirectory` otherwise. It'd be a bit ugly but they would keep their workflow I guess. You'd need to check that their targets end up with the same namespaced names (with the :: notation) when seen from your project... I don't know off the top of my head how Hunter handles a subdirectory with a project name of it's own

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

#104
post #98
post #48

Earlier quoted context omitted.

I switched from C++ to Java too. Still, every time I type `new MyObject()` without a corresponding `delete` I feel like I got away with some sort of crime ;)

in c++ you probably never want to write 'new MyObject()' at all. perhaps you didn't learn c++ from a good book?

to whoever downvoted this, why would you write 'new MyObject()'?

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

#105
post #65

Earlier quoted context omitted.

This is a good idea. Most modern languages have their own build tool which handle most of these things, so this requires some separate learning with C++. Some ideas for a curriculum: Context - C++ as a standard, compilers as implementations - a build tool's role in handling compilation and linking - compilers having limited abilities, having limited warnings and analysis by default Build tools - evolution: e.g. make…

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…

> 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 france when I started engineering school (early 2010s) we had classes about:

- using the shell, emacs, being at least basically proficient unix tools

- using make, cmake, configuring compilers etc

wild that it isn't more common, this explains a lot!

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

#108
post #98

Earlier quoted context omitted.

in c++ you probably never want to write 'new MyObject()' at all. perhaps you didn't learn c++ from a good book?

to whoever downvoted this, why would you write 'new MyObject()'?

I didn’t downvote and I don’t know C++, but I thought that the new and delete operators are how you manage dynamic memory allocation.

Is it not the way?

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

#109
post #53
post #40

Earlier quoted context omitted.

I'm just a little further down the road than you are and the best course seems to be to learn a little C++ first because it will help inform why Rust works as it does. Then when you try Rust, if you hate it, you've still got C++.

I used to agree with this, but I would actually now suggest doing the inverse. Rust will beat you over the head with a way of thinking that carries nicely back to C++, and the tooling (Cargo, etc) is more comparable to what someone coming from another language ecosystem would know. Smaller things like Rust's decent support for functional programming seems to click with everyone I know who's dabbling from the JS world…

Another way to put it is: Rust is world's best c/c++ teacher. Once you understand and surpass borrow checker, your c++ code will be much less error prone.

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

#110

Earlier quoted context omitted.

to whoever downvoted this, why would you write 'new MyObject()'?

I didn’t downvote and I don’t know C++, but I thought that the new and delete operators are how you manage dynamic memory allocation. Is it not the way?

no, it really isn't. mostly you don't need to manage objects dynamically at all (make them automatic) but if you do, use something like std::make_unique(...)
Post reply on HN