r/cpp • • Jul 21 '23

Hobbyist Developer fed up with C++

0 Upvotes

I started coding 10 years ago while studying something completely unrelated to informatics or technology in general, because I always had a fascination for computers.

I started with C# and the XNA Framework from Microsoft, subscribing to 3dbuzz.com which unfortunately fall apart some years ago when the founder died of cancer. Same goes for XNA, which died from stupid management decisions by Microsoft the time around they had windows Phone going.

I switched to C++ and SFML and that's what I have been literally doing for some years now, small 2D Game Projects which are not too complicated. I wrote an article on my blog about how to code Tetris in C++, so nothing fancy really.

I love C++ for providing powerful abstractions while still being "close to the metal" and as a hobbyist I always enjoyed learning about weird concepts C++ allows, such as compile-time polymorphism via the curiously recurring template pattern for example.

However, some time ago I started to dig into Modules. Modules have a significant impact on how you write code and how it even looks. Since they are there it feels wrong to use #includes. "Imports" are the modern way to do things.

However I noticed I cannot use CMake with Modules. There is some esoteric Blogpost from CMake how to get it work which is way to complicated for me. For me, its a big deal not having CMake available. Its very unfortunate to have to decide "Modules" or "Cmake"? It just feels odd to be forced to make such decision.

I have been used to compile my projects with mingw-w64 on windows and CMake. The latter doesn't support it. And GCC apparently also only rudimentary supports it. I first had to compile the modules and than could compile the program, it was oddly complicated and I hated every minute dealing with it.

This plethora of problems drew me to switch to Visual Studio, which I always avoided since the C# and XNA fiasco. Visual Studio provides decent modules Support, intellisense is most times broken but I can look past that.

However when I tried to compile a sample tmxlite project for SFML (https://github.com/fallahn/tmxlite) I ran into weird problems.

Basically I noticed that in the main.cpp file some local hpp-files cannot be imported, you have to use #include, otherwise you get cryptic error messages. For me it feels so random that for some local hpp files "import" is totally ok, for others I still need to use #include.

And a lot worse issue: The order of the imports and includes seems to matter. If the SFMLOrthogonalLayer.hpp, which must be "#included" and cannot be "imported", is below the import statements, I get weird compilation errors. The #include-statement needs to be on top of everything else, otherwise it does not work.

I searched a lot for the reasons behind this behavior (did I miss something?), but I cannot find any resources on this topic at all.

I just cannot get rid of the feeling that modern C++ is broken or just not there where it should be years ago, I mean, Modules were released in C++17, how is it in such a bad state in 2023?

The first time in my life investing my free time in learning new C++ Concepts felt like a literal waste of time. It's erratic, it's unfinished, the error messages are still a shit-show, rust is demonstrating for many years how helpful error messages can look like.

How can I love C++ again? Or is it time to let go?

I have a full time job and a kid, I can only code in the evening and getting older, where time is increasingly becoming valuable.


r/cpp • • Oct 18 '26

The intention and spirit behind modules seem diametrically opposed to their actual implementations by compiler toolchains.

9 Upvotes

The lynchpin of C++ modules is the built module interface (BMI). Each BMI is meant to be a lightweight data structure representing the syntax of a module unit (comprised of one primary module interface and potentially one or more partitions), with approximately O(1) complexity of symbol lookup. This massively accelerates repeated lookups into the same translation unit, and avoids paying the cost of a full preprocessor run and front-end lex + parse, as might otherwise happen with header files. In this way both the first clean build, and incremental builds are considerably accelerated and made much more efficient—build the BMI once, reuse it across future compiles, and we don't need large core counts and massively parallel jobs because the BMI is now available afterwards.

However, the way compiler toolchains have actually implemented them seems diametrically opposed to this goal of fast lookup. Today, BMIs are highly sensitive to any change in the command-line invocation of the compiler/dependency scanning tool, including the C++ version, warning and feature flags, and especially macro definitions, with -DMACRO or /DMACRO. This means that changing just one flag is likely to cause a BMI cache miss and a full BMI reconstruction, which can be fairly slow for larger modules (like module std).

BMIs are considered implementation details, and aren't even stable across compiler versions within the same toolchain. Compare to object files, where something compiled by really old versions can still be used on newer versions without too much fuss. This, from the user's perspective, entirely defeats that design ideal mentioned above: fast repeated lookups. Consider a simple example: a certain module uses a project-specific macro representing the platform, to change several function signatures. This module is now precompiled thrice, once each for -DFOO_WINDOWS, -DFOO_DARWIN, -DFOO_LINUX, instead of just once.

I believe that macros and the preprocessor are highly problematic. However, their very limitations are also an advantage here: their effect on code collapses to completely binary decisions. A macro is either defined or not, and a macro is either in the set of accepted values, or it isn't (e.g. #if __cplusplus >= 202603L). The preprocessor state might change throughout the source code of a translation unit, but the entire set of possible states can be enumerated in finite and reasonably short time at compile time—otherwise the front-end would never complete its work. To me, this seems like the preprocessor and parser could enumerate all possible preprocessor states of the source code, and stamp out both possibilities for each macro switch in the BMI; during lookup, the compiler can select the correct code path depending on what is provided at that particular invocation (not code definitions, but command-line invocations, as this would break the module assurance that macros do not leak into BMIs from consumers, nor do consumers see macros from a BMI).

This would make things like library feature configuration with macros really straightforward—specify the macros one wants for that feature at the command-line, which is enshrined in build system code rather than source code—the BMI can be reused, done.

Now, the compiler and C++ standard are a lot harder as these probably affect the internal state of the compiler rather than merely the value of __cplusplus; however, I genuinely feel like there really ought to be a better way forward, especially if C++ is to continue as a 'source may not be available' language. This discussion is moot if we always want to compile from source, but I want to say that is wasteful, and another driving force of the modules feature was to do away with wasteful and repeated recomputation of the same thing.

As mentioned above, build systems are also forced into this rather inefficient model to accommodate compiler behaviour. CMake in its latest iteration, for instance, has a notion of 'BMI compatibility', and probably does some sort of set manipulation on compile flags to determine if another BMI for the same module interface is needed or not, based on how it is imported. Why? This shouldn't be the case, a BMI really ought to be widely (if not universally) compatible, regardless of what flags go in the command-line.

I'm sure I don't have the entire picture as I am not a compiler front-end developer, and I don't mean to sound impertinent here, the effort put into delivering modules has been huge. However there are some decisions made which, as modules user and advocate, seem a little contradictory to the spirit of modules. I've written this after some thought on the situation and I'm interested in hearing from the community and compiler front-end developers who have worked on modules on my thoughts above.

Cheers.


r/cpp • • Oct 18 '20

No, C++ still isn't cutting it.

Thumbnail
da-data.blogspot.com
0 Upvotes

r/cpp • • Oct 10 '19

10 differences between static and dynamic libraries every C++ developer should know

Thumbnail acodersjourney.com
5 Upvotes

r/cpp • • Jan 09 '23

Teaching to program in c++ in the era of chatGPT?

0 Upvotes

Hi, I teach c++ programming for numerical methods, mainly to physicists. I have tried to focus on the programming logic, trying to keep things simple and using a modern c++ approach, while introducing the students to the basic concepts of numerical methods. I think it's very important for them to learn the logic behind programs, how to read and interpret other people codes, and how to debug their own programs. Measuring that learning is a challenging task, specially for large courses. I mix small and frequent exercises, combined with moddle activities like workshops where they evaluate other students codes, and final projects.

But now, with the advent of chatGPT, I see an important shift on teaching programming, not only in c++ but in general. It can write basically all the typical code that one uses as a task for learning structured blocks, loops and selection structures(Euler project and so on). And also more elaborated code plus its own test cases. It can debug code and point out errors in programs or segments of code. It can generate flow charts in either mermaid, graphviz or tikz syntax. It is not perfect, but it's very good.

So now I wonder how can I still help students to think about the logic behind a program a not just use chatGPT directly, how to measure this kind of learning (this is s virtual course where I cannot restrict internet access or similar), and in general how to integrate chatGPT in the learning process. Of course using chatGPT to generate the basic code allows me to go for deeper task, like not only writing the program but also using its results to perform some numerical analysis, but here the programming logic is lost completely. How are you going to integrate chatGPT in your programming classes? What suggestions do you have? How to teach the fundamental programming logic? How to grade st scale? I post this here because I am very interested to hear from people who program in c++. Or maybe is better now to start focusing on code modularization, testing, and so on, whole letting the AI generate the code? I don't feel comfortable with that but maybe that is the future

Thanks in advance


r/cpp • • Oct 06 '13

Nerds Central: Why C++ Unordered Maps (Hash tables) Are Not Great For Strings

Thumbnail
nerds-central.blogspot.com
0 Upvotes

r/cpp • • Aug 31 '21

[Belay the C++] Yet another reason to not use printf (or write C code in general)

Thumbnail
belaycpp.com
0 Upvotes

r/cpp • • Mar 29 '24

Why we stopped using macro assemblers?

0 Upvotes

Here me out, I don't think I've wrongly posted this on r/cpp.

I'm using C++ on daily basis, not the latest standards thought, but still I'm using it really regularly and I'm into MTP, heavy constexpr usage,... I'm also a big expectant of standardized static reflection, so you could say that I'm basically a giant proponent of doing the most at compile time and passing just what you need to runtime. Now, because we still don't have reflection in the standard, we are quite limited with what is possible to do at compile time(another important component, that eventually needs to land in the standard, is code injection but for the sake of this post lets say that code injection is implied when I say "reflection"), so as probably many of you did before, I also tried to "invent" some kind of compile time reflection. For example, I imagine that many of you have tied the same, I've tried to create a compiler plugin that would pull information from the AST and generate code based on it which is essentially what we will eventually get with the standard proposal but with a nicer API. Parallelly with my attempts to compensate the lack of static reflection facilities, I'm looking at what other people are trying to do at compile time, e.g. a full constexpr JSON parser has been created by Jason Turner but as far as I know it has limitations primarily because there is no way to pass the dynamically allocated memory to runtime from constexpr context(another compile time feature that's not available in the language similar to reflection). This is just an example of what people want to do at compile time, and if you ask me, to me it seems that people will find a use case for anything to be done at compile time, or in other words, people want an ability to do whatever they want at compile time. This is something that some languages today allow to a high degree, e.g. zig, circle(c++ compiler). Now here is where I finally start to connect to my title, I am asking myself, if we allow ourself to do whatever at compile time why don't we create a compiler at compile time? I know that this is quite a jump and an extreme, but really, what is stopping us to eventually do that? Even today people are creating full constexpr enabled virtual machines, what is stopping us to eventually start writing compilers at compiler time?(maybe sanity) And with that thought I somehow landed on a thought "why we stopped using macro assemblers?", maybe I'm wrong but to me it seems that pushing this "do everything at compile time"-train leads to some kind of a "modern macro assembler". We are more and more writing a compile time program that generates a program that will be propagated to runtime and eventually executed. And to be honest, I might not even be against it at all. Maybe, just maybe, there is value in trying to go back and try again with macro assemblers, but with modern macros, i.e. no glorified copy-pasting, maybe try with something closer to a particular oxidized language's macros. I'd be interested in seeing a new spin of an old idea, maybe instead of calling them "macro assemblers" maybe they can be called "compile time assemblers" idk.

I tried to aggregate my train of thoughts here and I hope that it is to some extent understandable what I'm trying to say. I've tried searching for articles of something similar that I'm trying to say here but with no success. Maybe there is already something like a "modern macro assembler" out there that I'm not aware of and I'd be grateful if you would point me at it. In the end I want to say that I'm not really searching for answers here, I'm really just trying to see whether anybody has been thinking about anything similar and whether this is even something that makes any sense to anyone but me. Thank you for reading my wall of text and thank you for any kind of input.


r/cpp • • Sep 05 '25

Temperature check on extending namespace declaration syntax

0 Upvotes

Today if I want to declare an unnamed namespace nested in a named namespace, I have to write it like this

namespace a::b {
namespace {
}
}

I want to allow declaring nested unnamed namespaces like this instead:

namespace a::b:: {
}

I have some other places in my work codebase where this would be useful, but the main motivation for this are test files. We place the tests into the same namespace as the code under test, but we also want to give them internal linkage, so there is no risk of collisions, the linker has less work to do, etc, etc.


Possible question is what to do if I want to further nest namespaces after the unnamed one. AFAIK the obvious option, a::b::::c looks weird, but does not introduce new problems.


r/cpp • • May 04 '22

C++ & Rust: Generics and Specialization

Thumbnail
tangramvision.com
0 Upvotes

r/cpp • • Mar 20 '09

Ask c++it: If you disappointed in c++ and still disappointed, why did it happen?

3 Upvotes

r/cpp • • Jun 13 '24

Limit the number of library dependencies

Thumbnail sandordargo.com
0 Upvotes

r/cpp • • May 20 '24

What version of C++ should I be using and why? I never think to check this aspect of my project, but I tried using std::format and it told me I needed to be at v20 for that feature. I don't follow the language improvements so I'm ignorant about which one I should target. Thoughts?

0 Upvotes

What version of C++ should I be using and why? I never think to check this aspect of my project, but I tried using std::format and it told me I needed to be at v20 for that feature. I don't follow the language improvements so I'm ignorant about which one I should target. Thoughts? I'm currently at ISO C++ 14 and I guess that came from a default setting.


r/cpp • • Aug 09 '16

Stack and Heap: Commonly Misused Terms

Thumbnail tartanllama.github.io
6 Upvotes

r/cpp • • Jun 16 '21

[Thought experiment] Why should i care about freeing my memory?

6 Upvotes

I know that this is a really shit practice and nobody should do it, but... why?

When making an application that runs only for a few milliseconds, and has a low memory footprint anyway, why should i care about freeing my heap? The OS will do it anyways a few clock cycles afterwards, when destructing my process and its virtual address space. Yes, it may use 12kb more ram for a few milliseconds, but who cares?

Of course this breaks as soon as your process runs for longer than a few milliseconds, and at that point the program will use so few heap-objects that freeing them is most likely a one-liner. Yes, in kernel space it may not be freed automatically. But as i said, it's a thought experiment.


r/cpp • • Jul 09 '19

Future Live Event Eric Niebler - A Unifying Abstraction for Async in C++

Thumbnail
youtu.be
8 Upvotes

r/cpp • • Mar 11 '24

Why does nobody use real-time bound checks if memory safety is so important?

0 Upvotes

In C and C++, we can turn on bounds to check a container's access at any time with a single additional compiler flag.

This would prevent the majority of unsafe access to memory and prevent most cases of buffer overflow. Additionally, one can use memory sanitizers on release code.

If memory safety were so important, why did no developers use these compiler flags?


r/cpp • • May 28 '25

Kourier: the fastest server for building web services is open source and written in C++/Qt

Thumbnail github.com
0 Upvotes

r/cpp • • Oct 12 '23

Episode 150: Is C++ Dying?

Thumbnail
adspthepodcast.com
0 Upvotes

r/cpp • • Jan 09 '19

Dear /r/cpp

17 Upvotes

Sonny from Codecademy here. Last month (Dec 3rd), we launched 4 modules of our first ever Learn C++ course!

https://www.codecademy.com/learn/learn-c-plus-plus

  1. Hello World

  2. Variables

  3. Conditionals & Logic

  4. Loops

And as of this morning, 87,504 learners around the world have started the course!

I'm extremely happy and proud of this because C++ was my first language that was taught in my CS class and 10 years later, I got the chance to work with Dr. Stroustrup and share something that I love with the world.

However, as my teammate Mariel and I about to author the next few modules, I couldn't help but feel that there can still be a lot of improvements made in the first 4 modules. I'm wondering if anyone has taken or is interesting in taking this course and give me some feedback and ways it can improve.

There are also a few things I'm still conflicted on:

  • Should I include `return 0;` in the very first lesson?

  • Where is the perfect place to introduce `using namespace std;`?

  • Where to introduce the different types of errors and debugging?

Any feedback would be highly appreciated! And happy to mail out some Codecademy tees and Pro memberships too!


r/cpp • • Sep 15 '23

The C++ paradox (and how to solve it)

29 Upvotes

On every post about adding a new library to the standard library: "hey, this should not be in the standard library, this should just be an external dependency, it could be solved if we had a decent package manager"

In a recent poll about package managers: "I don't use any package manager and I am happy with it!"

Well... we have a paradox here.

I use xmake (and its integrated package manager xrepo), and I am very happy about it. xmake can handle C/C++ projects but also Fortran, Go, Rust, Swift, Zig, Pascal, Cuda, Nim, Verilog. It handles cross-compilation, it can generate project files for several IDEs. And xrepo can build external dependencies that use cmake or any other build system, it can fetch packages from conan or vcpkg if needed, it can also check the installed packages on linux distributions. The file for describing the build is pure Lua, and is very easy to read and understand. I feel this tool is what the C++ community needs to solve the paradox. Because once you have tasted xmake, it's very hard to come back to CMake or vcpkg, or any other tool that handles build xor dependencies.


r/cpp • • Mar 16 '25

With the big push for memory safety, how important is it, really?

70 Upvotes

I know the common stat that gets thrown around is "70% of Windows security bugs come from memory issues"

But no one ever follows that up with how many bugs are security bugs? Are we talking half of all bugs? Is it less than 1%?

Is it really that important, outside of critical systems; which could be made 100% safe by simply isolating them from external connection? This entire fervor around 'memory safety' feels like a lot of people buying into a marketing gimmick.

To be clear: obviously being memory safe is important, fundamentally, but is it really so important as to dominate every consideration about language development. Are there really no other more important things we could be working on improving in programming languages, and cpp specifically?

Edit: For additional clarity, my thesis is that having a more transparent, usable language that made memory usage clear and well defined would more effectively reduce memory bugs than having a memory cop to police your code.


r/cpp • • Oct 23 '13

What is a modern C++ replacement?

7 Upvotes

In this post: http://programmers.stackexchange.com/a/29136 , Konrad explains that the advantage C++ has over other high-level languages such as Java, is that it offers abstraction with no performance overhead during runtime at the cost of increased compile time.

I am looking for a modern C++ alternative that attempts to achieve the same goals as C++, that is:

  1. Less code duplication. The more abstract and higher level, the better.

  2. No performance hit.

  3. Compile time is sufficiently slow as is required to achieve 1 and 2.


r/cpp • • Nov 27 '24

Why do some people prefer allocating their own application class instead of using static or global variables?

0 Upvotes

I’ve seen many projects doing this but most of the time they could just have used static member variables or even global ones.

Is it because global variables are messy? Or is it to handle smart pointers better? I’ve never understood the reason why, but I think I might be missing something, therefore I wanna know.