Why I write C++ like it is C?

preview_player
Показать описание
In this video, I will show you my coding style in C++ for game dev 💪🎮🕹️

Join my Discord:

I have a Steam game! 🤯

Join this channel if you want to support me 😻:

No more Leaks! 💦🤽

Learn gamedev full guide! 😍

Use CMake Better! 🤔

O(1) resize vector video: 🤯

Music: Evan King - Spicy Boom

Minecraft soundtrack: C418 - Aria Math
Рекомендации по теме
Комментарии
Автор

As a language lawyer I agree with most of this (not using exceptions for general error handling, not abstracting for no reason, etc.), but a couple bits are misleading.

First some general pedantry: a lot of this isn't really C-like, it's just another way to write C++ 😛
People are slowly moving away from java style OOP (thank god), and parts of this style are being used more, and I enjoy it a lot. But IMO as long as you're consistent and documenting well, it's fine, even if kinda ugly...

You called the move ctor a "copy constructor", and used the const version, which generally isn't correct. (You might already know this next bit but other people might not) moving is meant to act as a transfer, so the object you transfer from should be mutable. The reason we use const T& for copying is you aren't editing that data, so it's better to accept all variants.

Also the specific reason the standard library is like that is they have to handle many C++ versions, platforms, compilers, compilation modes; all while conforming to the spec (which you can find drafts of at eel.is). As someone who's written some of this stuff, user code shouldn't look like that, even for complicated containers. You can just build off other standard features 99% of the time.

But yea overall good video :)

ightfold
Автор

I have no idea what this man is talking about, but his accent makes him sound both funny and smart
10/10

ginnogianni
Автор

For me, C++ is an extension of C that provides a warehouse of neat but not always useful abstractions. I simply grab the ones that I want to use, put them in my toolbelt, and proceed coding as normal. Minimizes cognitive load and code bloat.

Rametesaima
Автор

Forwarding a const& variable? Please don't, use "universal reference" aka "forwarding reference". Meaning vector<T>::push_back(U&& val);.

MarekKnapek
Автор

I think your C++ style is super cool. Just enough of C++ to make life easier but also following the C philosophy to keep your sanity. Nice video.

corvoworldbuilding
Автор

You are so right. I use most of the C++ features to protect myself from my own stupidity because I know that I will forget stuff and I will use my own code not the way it was intended. I will change code and I will break stuff. To protect me from this, C++ features are great.

artur_schutz
Автор

4:04 "write the code first, then make abstractions"
Ah, I have a way more insane strategy: Write the code, notice your abstractions are bad, then rewrite the entire thing. Most effort, but also best results.

Maxjoker
Автор

2:45 Shouldn't the argument of a move-constuctor be non-const?

teknicker
Автор

C++ is crazy. I have some experience in C, like writing a SQLite clone and stuffs, but i can barely understand the code in your video. What's is this tamplete hell, lol. And you use free() without passing the pointer?

lucascamelo
Автор

C++ is multi-paradigm, reducing OOP reliance is still a paradigm that's actually quite preferred, its not a C thing, you desire to build optimized and robust structures out of necessity, keep it otherwise simple, let the structures do all the work and rely on the structure and its operators to handle things for you. Also using the STL (which you should be doing wherever you can, like with raw pointers try to prefer unique_ptr) is a violation of C.

Spartan
Автор

Keep up the good work! I used to do C++ professionally for years, so many fun ways to write buggy code xD

just-squirrels
Автор

I started off writing C++ using the STL,
then I started writing C inspired code in C++ by using stdlib functions,
then exclusively C in C++ but with std::vector,
then not using vector in C++ because most of my arrays didn't NEED to be bigger than a certain size
now I exclusively use C in C.

Then again I mostly like writing smaller tools so it probably makes more sense to write fully in C for me, but I can't overstate what a massive change using C has been.


It has changed my entire way of thinking about programming and I really enjoy writing the simplest code possible, which I think C natively promotes with it's lack of functionality.
Small things like replacing if/else with assert, using named bit flag parameters instead of unclear boolean arguments, Complete change for the better.

Definitely recommend for any programmer to try to use C for smaller projects and see how fast your brain adapts to the lack of complex features. You'll find that you're doing a lot more than you need to a lot of the time.

JFrancoe
Автор

hehe, that's how i describe my style, but i think maybe to you it would be like BASIC. all that address stuff can just be typed in place with more characters.
background in audio dsp on venerable boxes, it's only gonna cut it if it's the fastest it can be. i used to have a little meter and there was about 0.08% cpu difference between a float add and mult, and that taught me everything i ever want to be aware of.

atomictraveller
Автор

That's the beauty of programming, you may develop a style that fit your needs. This is also the cause of much confusion when learning C++, I know because I was faced with such confusion.

C should not be written in C++, they're separate languages with different requirements. When I first began my journey towards learning C++, I gave up many times. You can grab two different code bases, one not using C anywhere, and the other one using C and claiming it's C++ was quite disappointing. A good example is TheForge renderer, says it's C++ but it's completely written in a C-like way.

This is no offense to you at all, I'm sharing my experience and what I learned. Everyone can do as they please in the world of programming.

BerayTriangle
Автор

Writing a proper vector class is actually harder!

rinav
Автор

I like this. I have my own style not using all modern fancy features. I often think of it as "C+". Well, I do like constructors and destructors allocating/deallocating things if needed. I got tired of C++ standards adding more and more complexity, headers containing thousands of lines of convoluted code for things like basic vectors and strings.

kempstonj
Автор

I have to tell you... never search your engine's name followed by the word 'grande' with the safe search disabled... '-'

_hugoi
Автор

I do the same thing, just with a lot less preprocessor

One thing I really really like about C++ (one of the few things) is it's constexpr and inline functions, in my opinion macros just mess me up

kenarnarayaka
Автор

You might like the c3 programming language if you like writing c-style c++

frankc
Автор

Usually people say: I use this X languages, I say: besides C, I use this functional languages or math symbols languages like APL. For me C is above all. No rust, no zig, f*CK it. C for the win

ProjectVastness