Live data from Hacker News

Modern C++ for C Programmers: part 5

ds9a.nl

41–50 of 82 posts

Re: Modern C++ for C Programmers: part 5

#41
post #7

Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.

Single-file header libraries are actually all the rage in C++ these days. Here's[1] a list even!

[1] https://github.com/nothings/single_file_libs

Re: Modern C++ for C Programmers: part 5

#42
post #7

Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.

The way things are going, you can thank the "macros or bust" crowd for getting modules in C++23 if we are lucky.

Re: Modern C++ for C Programmers: part 5

#43
post #8

Earlier quoted context omitted.

C compilers can do copy ellision when inlining code as long as the result is identical. That's not quite the same thing as RVO, which deliberately relaxes the notion of "identical result" such that it's possible to write C++ code to detect whether or not RVO was actually performed. That's not possible in C (or shouldn't be).

It's possible that I'm missing something, but I believe that the result is necessarily identical in C, because there can be no observable side-effect of a struct copy in the C abstract machine.

Don't quote me on this, but I think padding bytes might have different values in certain cases.

Re: Modern C++ for C Programmers: part 5

#44

Earlier quoted context omitted.

It's possible that I'm missing something, but I believe that the result is necessarily identical in C, because there can be no observable side-effect of a struct copy in the C abstract machine.

Don't quote me on this, but I think padding bytes might have different values in certain cases.

I'm fairly sure it's always undefined behavior to observe those differences, so while it's possible in practice, it'd never work in theory.

Re: Modern C++ for C Programmers: part 5

#45

Earlier quoted context omitted.

Also if Rust is not cutting it yet in your specific niche.

I find D to be a good tradeoff between C++ and Rust. I can't stand not having compile-time evaluation, code generation and reflection in Rust and C++ is just too slow to iterate with.

Working with Python lately I very much got to like the interactive REPL and its immediate feedback.

I actually think I forgot how to program in C. It lacks almost every data structure I'd deem useful to getting complex and mixed problems solved quickly. C++ provides many things and is useful if you are in a tight spot or you want/need the speed.

If Rust keeps evolving at a quick pace I think I'll look into it a lot in the future.

D seems to me like a good thing that is better in many ways but has some critical drawbacks for me like not working on many microcontrollers (an area where C++ really shines). On the other hand it isn't radical enough to really dive into it.

Re: Modern C++ for C Programmers: part 5

#46
post #40

Earlier quoted context omitted.

Includes mixed with #ifdef leaks state across module borders and the whole C preprocessor feels like a dirty hack. What a header actually does depends on compiler flags, #defines from other files and then the order in which you include things as one header file might define something that changes the behavior of another header file. The compiler loses state in between C++-files and caching precompiled header files wa…

Compiling Chromium, the biggest C++ project I know, takes on the order of 8 hours with a somewhat old but quite powerful server. Linking Chromium on my laptop, with 8GB of RAM, required me to increase my swap space from 8GB to 16GB. Going away from C's linker and header file-model, which really doesn't work well for C++, to something based on a proper module system, would be amazing.

What I'd like to have is someone to devise a plan on how to seamlessly progress from C++ to a language with a wholly new and cleaned up syntax. A way to slowly break out of the shell given by current backward compatibility. But at the same time being able to seamlessly interact with the old C and C++ world. Maybe something like "unsafe" in Rust.

Having modules in C++ smells like the connector we're missing in order to accomplish something like that.

Re: Modern C++ for C Programmers: part 5

#47
post #7

Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.

Single-file header libraries are actually all the rage in C++ these days. Here's[1] a list even! [1] https://github.com/nothings/single_file_libs

This is what you get if you're missing a proper package management that allows users to easily install their libraries.

That single file is the substitute for a package that you can simply put somewhere, include it and it works.

Re: Modern C++ for C Programmers: part 5

#48
post #38

is there a modern C++ for python programmers? i have ~5 years programming in dynamic/interpreted (python/js) and compiled/gc'd(java/go) languages and i'd like to learn a systems language. i'm reading the rust programming book (and it's really good/easy to grok) but i'd also like to learn C++. the problem is that most books are either too easy (C++ as your first language) or too hard (straight into RAII and templates)…

Yes! And be careful and very picky about what you read! To quote a popular Quora answer [1]: "If you really want to learn C++, I advise against any and all online tutorials and against most books. Without any kind of quality control, many professional book writers published many awful C++ textbooks that may be easy to read and sell well, but teach lies. Stick with the community-verified book list available at StackOv…

I second the C++ Primer suggestion. It was the book that made the pieces fit in my head.

Re: Modern C++ for C Programmers: part 5

#49

Earlier quoted context omitted.

Single-file header libraries are actually all the rage in C++ these days. Here's[1] a list even! [1] https://github.com/nothings/single_file_libs

This is what you get if you're missing a proper package management that allows users to easily install their libraries. That single file is the substitute for a package that you can simply put somewhere, include it and it works.

It takes all sorts, but I prefer the headers. Each project’s copy only gets upgraded explicitly, the debug info is always there, single stepping always works, there’s never a problem with ABI/compiler option mismatches (and you get the unoptimised version in your unoptimised build), anybody that gets the repo automatically gets all the dependencies too.

Re: Modern C++ for C Programmers: part 5

#50
post #49

Earlier quoted context omitted.

This is what you get if you're missing a proper package management that allows users to easily install their libraries. That single file is the substitute for a package that you can simply put somewhere, include it and it works.

It takes all sorts, but I prefer the headers. Each project’s copy only gets upgraded explicitly, the debug info is always there, single stepping always works, there’s never a problem with ABI/compiler option mismatches (and you get the unoptimised version in your unoptimised build), anybody that gets the repo automatically gets all the dependencies too.

I.e. all the things you would get from a proper package manager if there was one for C++.
Post reply on HN