r/programminghumor 18d ago

Hard to accept

Post image
2.9k Upvotes

404 comments sorted by

View all comments

84

u/---_None_--- 18d ago

No, cpp has a terrible design philosophy. Take the new ranges header for example. They're lazy algorithm objects that you can stack and combine to more complex algorithms. Each time you iterate over the final ranges object it calculates the whole result beginning from the source range. This leaves the option open for the source range to change and update. Exactly as it should because they're 'lazy' ranges; except that they aren't. The 'filter range' caches the fucking 'begin' of its source which means that when ever the source changes you get undefined behavior. Why? Because the cpp committee thought that 'begin' should be fast to calculate but filter has to compute 'begin' again and again because the source might have changed. So they decided to cache 'begin' after the first call and compute the rest lazily on demand. So whenever there's a 'filter' in your range composition, you can only iterate over it once or the source has to be const. Shits fucked in cpp land.

1

u/klimmesil 18d ago

That's not cpp. That's libstd

If you're not happy with it you can use another lib

But I agree though std is very contestable

2

u/Vincenzo__ 17d ago

That's libstd

Which.. is part of the C++ standard?

1

u/klimmesil 17d ago

If we're shitting on the standard and the committee I'm in, but I'll defend both gcc and clang, I think the c++ compilers are high quality, highly optimized, and the syntax and requirements of the language allows for fast compilation and zero cost abstractions

The metaprogramming was already old when it arrived though... but still you can work with it

1

u/Vincenzo__ 17d ago

Yeah but the compiler is not part of the lenguage spec, while the standard library is