Live data from Hacker News

C++ Cheat Sheets

hackingcpp.com

21–30 of 82 posts

Re: C++ Cheat Sheets

#22
post #2

Wow, this is really good, there are still things I can learn. C++ really has a lot of good things. It's just a shame it's so slow to compile. I'm curious if anybody is working to make C++ faster to compile. Even if it was a subset of the language, with some features removed, it would be good enough for me.

In the old days C++ pre-processed into C. Then you had to run a special linker to handle how the preprocessor created class part names.

Re: C++ Cheat Sheets

#23
post #7

Earlier quoted context omitted.

CLion from JetBrains and Microsoft Visual Code are the best commercial ones for Linux, NetBeans is a free (as in freedeom and open source) one (that also supports many other languages like Java and Python). What I don't recommend is Eclipse - it's complex and confusing for beginners (but a bit faster than some others).

I didn’t think NetBeans supported C++ anymore?

Yeah, at least according to the repo it seems they now delegate to the ccls language server and just do syntax highlighting via the textmate plist grammars that are so commonly paired with language servers

* https://github.com/apache/netbeans/tree/12.3/cpplite#cpplite

* https://github.com/apache/netbeans/blob/12.3/cpplite/cpplite...

Re: C++ Cheat Sheets

#24
post #6
post #5

Earlier quoted context omitted.

Off topic. Could you recommend an ide to work with c++?

Microsoft Visual Studio for Windows and QtCreator for Linux.

I find visual studio to be absolutely horrendous for C++. Refactoring doesn't work (even a simple rename symbol!) The errors aren't accurate, autocomplete seems to suggest every symbol from the stdlib before the class defined in the file itself and can't tell when it should suggest classes vs functions/variables.

Oh and of course compile errors are absolutely useless but I suppose that's a C++ thing in general. The error panel shows the (last? First?) Error in a chain of errors, which is always something deep in library code. E.g. accidentally tried to copy a non-copyable object using unique_ptr? You can't find the offending callsite, it just points you to xmemory and at best the class being wrongly used.

Re: C++ Cheat Sheets

#25
Probably semi related, but when I was looking at C/C++ job offers, why are they paid so little in comparison to Python or JavaScript? It seems like C/C++ is much more complex. I was mainly looking at embedded stuff vs Web. For example senior C++ role was paying £45k pa on average and over £60k for JS.

Re: C++ Cheat Sheets

#26
This is quite something! I intend to share w/ my coworkers :)

If I had one thing I could have added to it: panel for understanding value categories[0] -- I have an incredibly hard time wrapping my head around how they're described. I attribute the difficulty to the cpp standard being excruciatingly complex, the language itself not being designed holistically, and backwards compatibility with itself and C.

[0] https://en.cppreference.com/w/cpp/language/value_category

Re: C++ Cheat Sheets

#28
post #26

This is quite something! I intend to share w/ my coworkers :) If I had one thing I could have added to it: panel for understanding value categories[0] -- I have an incredibly hard time wrapping my head around how they're described. I attribute the difficulty to the cpp standard being excruciatingly complex, the language itself not being designed holistically, and backwards compatibility with itself and C. [0] https:/…

Honestly, you don't have to understand value categories to this degree. The distinctions are important for writing the standard, but I've never once explained (or was explained) a line of code where diving into the depths of value categories would add anything.

In practice it boils down to "if it has a name, you need to std::move it to get move semantics, otherwise you don't". Caveats apply (e.g. returning a named value).

Re: C++ Cheat Sheets

#29
post #2

Wow, this is really good, there are still things I can learn. C++ really has a lot of good things. It's just a shame it's so slow to compile. I'm curious if anybody is working to make C++ faster to compile. Even if it was a subset of the language, with some features removed, it would be good enough for me.

> I'm curious if anybody is working to make C++ faster to compile.

Yes - C++20 added support for modules to the Core Language (both "header units" and "named modules"; header units are an intermediate step between classic includes and named modules), and support for header units to the Standard Library. Compiler/library support is a work in progress (MSVC's STL, which I work on, is the furthest along - see https://github.com/microsoft/STL/issues/1694 for status), but header units are showing significant improvements in compiler throughput (build speed). This looks like `import ;` in your source code (with significant build system changes to build vector as a header unit, producing vector.ifc and vector.obj).

There's a proposal under review for C++23 to add named modules for the Standard Library, see https://wg21.link/p2465r2 . If this is accepted, `import std;` (or `import std.compat;`) will be the one-line way to use the entire C++ Standard Library with (what we hope will be) even better compiler throughput.

The primary limitation of header units and especially named modules is macros: neither can be influenced by macros defined in the source file, and named modules can't emit macros at all. Thus, one will still need to `#include ` in addition to `import std;` if you want the `assert()` macro.

Re: C++ Cheat Sheets

#30
post #26

This is quite something! I intend to share w/ my coworkers :) If I had one thing I could have added to it: panel for understanding value categories[0] -- I have an incredibly hard time wrapping my head around how they're described. I attribute the difficulty to the cpp standard being excruciatingly complex, the language itself not being designed holistically, and backwards compatibility with itself and C. [0] https:/…

Regarding value categories, maybe this is also useful: https://raw.githubusercontent.com/jeaye/value-category-cheat...
Post reply on HN