#CodingDiscussion #CvsC++ #GraphicsProgramming
Have you ever wondered why some people prefer C over C++ for graphics programming? 🤔 Here are a few reasons that might shed some light on this popular debate:
– C is often favored for its simplicity and direct control over hardware, making it efficient for graphics programming.
– While C++ is indeed newer and offers more features, it can sometimes be seen as bloated or overly complex for certain tasks like graphics programming.
– Many programmers believe that if you stick to the core features of C++, avoiding unnecessary complexity, you can achieve similar results to C while still benefiting from object-oriented design and other modern practices.
One possible solution to this debate could be to carefully evaluate the requirements of your graphics programming project and choose the language that best aligns with your goals and preferences. By staying informed and open-minded, you can make an informed decision that will ultimately lead to successful and efficient coding. 💻✨
What are your thoughts on this topic? Share your experiences and insights!
Alot of the libraries for graphics are written in c because it is a simpler language, plus alot of interpreters for other languages are written in c or something that eventually turns into c, so making one graphics library that is easy to wrap for other languages means you can use the same libraryfor many other languages, plus if you write the library in c there is a pretty high chance that it is interoperable with c++, but the opposite isn’t usually true.
I don’t think people pick C over C++. In general C is picked over C++ in hardware branch. And sometimes is about preference.
C is perceived as more straightforward I guess and afaik many DSLs for graphics coding are basically subsets of C with libraries (at least were ages ago). Also you can’t use overly complex and unnecessary features if they are not there.
Simplicity, resources, predictability. If all the additions of C++ are unnecessary for a project, then C is a natural choice. For me is the natural way in embedded. I know C++, but is a very large language at this point, I would not be comfortable with it. C is a small language, it works.
At least for embedded systems, C gives you more control over your system (specifically memory use and allocation) and is more predictable. This is crucial if you have limited resources or your code is highly optimized to reduce compute time.
Simplicity
C’s simplicity is a feature, not a bug. Less room for errors.
>Why do people prefer c over c++? especially in graphics programming
Surprised no one has said this. This is definitely not true. Every graphics engine I’ve worked on has been primarily C++. It’s true that some low-level APIs are written in C (OpenGL/Vulkan) but I think this is because C is lower level, has a much simpler compiler that’s implemented in everything that would use the APIs. But idk just a guess lol.
As my teacher said in class, it’s simplicity and robustness. C also used majorly in embedded systems because of this.
C is known by more, and when I say known, I mean you can learn most of C in a semester or two. CPP is a language you can learn all your life and still have just scratched the surface of the language. It’s absolutely massive. CPP does some things better, some things worse. Embedded is one field where you’ll almost always see C over CPP, simply because C is more lightweight, and lightweight is better for that certain application. TBH I’ve seen graphics like OpenGL, Vulkan, and DirectX all done a lot more in CPP than in C, but that’s my experience. Most C code will work perfectly fine in CPP, so I wouldn’t worry too much about it.
there is also a good saying which engineers live by : “if something works don’t touch it” lmao but rest other reasonings is really insightful.
How is this even true?
Sure, OpenGL, Vulkan etc. are generally C because you can easily have bindings for other languages.
But apart from that C++ absolutely dominates the graphics industry.
Check any 3D/Game engine – Unreal, Unity, Godot.. https://en.wikipedia.org/wiki/List_of_game_engines look at the languages, the C ones are generally just the older ones.
People like Carmack also long switched to what you suggest – “minimalist” C++.
Related – PyTorch calls all C kernels legacy (TH kernels) and migrated everything to C++. There is a thin layer of C for the bindings, as usual, but they call out to C++ then (see http://blog.ezyang.com/2019/05/pytorch-internals/
Nvidia tooling is almost all C++ besides on the driver level.
People like C because some C++ codebases/people go overboard with language features and I totally get that. I also always used a rather small feature set.
It’s a bit like the discussions between Go and Rust people. I absolutely like minimalistic Go approach so type system and Macro freaks can’t produce (extended-) alphabet soups ;).
But honestly I have seen so many C codebases where people also ad-hoc implemented (buggy) lists all over the place. Do almost ad-hoc implementations of LISP in their codebase.
Check for example this function which I regularly have to dig in 😉
https://github.com/espeak-ng/espeak-ng/blob/063e3962dfc108db4c8b6fd05f4a9b531d74dd2f/src/libespeak-ng/translate.c#L924