Hacker News new | ask | show | jobs
by mattivc 2057 days ago
One of the C++ project that have influence my programming the most recently, which is to move to a style that is something between C and C++, is Dear ImGUI: https://github.com/ocornut/imgui
2 comments

Yeah as others mentioned this is between C and C++, arguably taking best of each language. But indeed this library is based around the idea of having performant UI (as they mostly redraw whole screen on each frame, it has to be quite quick, though there are ways not to do this, this is the most basic case) and generic containers do not really cut it, also usage of exceptions is sort of impossible with the way you have to structure ImGui code. So it's more of a codebase that illustrates how to write performant code, not so much modern C++ guideline.
Do they have a coding style or similar in which this is outlined?

I had a quick look at the code but I would be interested in what "a style that is something between C and C++" actually entails.

Avoiding templates but using classes/namespaces? Minimizing use of the stl?

Kindof. Almost no standard library but it does use namespaces. (almost) no templates. Lots of pointers and arrays. Lots of explicit begin/end or push/pop functions instead of more idiomatic solutions like RAII/scope guards etc. va_ macros instead of variadic templates or fold expressions.

Also while ImGUI is great and the guy follows good coding practices - it's not at all what I would recommend for learning C++. Not only is it technically not C++, but the problem it solves (GUI-Framework and immediate on top) leads to some pretty hard to follow code with a lot of hidden global state.

> Lots of explicit begin/end or push/pop functions instead of more idiomatic solutions like RAII/scope guards etc. va_ macros instead of variadic templates or fold expressions.

I'm going to have nightmares tonight.

It's a simple API, that's for sure. But it's pretty consistent in itself and obviously is trivial to build abstractions upon. Also makes it easy to port to other languages.
That sounds like uniformly bad code.
Thanks that’s a great explanation