So what do you think - does the way that C is typically taught teach better programming principles than C++? 👇 To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TheCherno . You’ll also get 20% off an annual premium subscription.
Yeah C++ reliance on OOP is so bad. Whenever I write C++ it looks like C because I just prefer it that way. No classes, lambas, operator overloading, non of that junk.
It's really mind blowing that a 13-year old already in graphics programming. I was only playing games and knew nothing about programming except shell languages around that age.
Ya, in the mid 80s I looked in BASIC than eventually 6510 assembly; then by 1990 got into C on the Amiga. The assembly helped to fully understand the computer that later allowed me to do microcontroller programming later in the 1990s at work. But that is impressive that a 13 can do Vulkan; most programmers complain how much of a pain Vulkan is because of its verbosity.
I tried to get into programming early on, the only programming language I knew of was python. I stopped trying because the setup process for the compiler at the time was so terrible. Most I actually got into was advanced batch files, which doesn't really coun t.
I'm so confused by these comments. VSCode is a text editor and C++ is just a compiled language. Just learn a compiler and write C++? Microsoft has a debug adapter for C++ that should work fine as an extension if you're trying to debug.
thats what it comes down to: learning the compiler + learning how vs code interscts with debugging tools. not exactly the most begginer friendly topics, and all to just be able to run code @@CoderShare
24:12 there is a modern way of doing structure initialization since C supports strict assignment. You can do (type){ .field = Val, .field2= val2}; All unmentioned fields get zero initialized.
You can do designated initializers in C++, but only for classes and structs that are "Plain Old Data." I forget what exactly are the qualifications for that, but I believe the type must have no declared constructors, no private or protected fields, and no virtual methods. An important difference between the feature in C vs. C++ is that in C, fields may be initialized in any order, but in C++, they must be initialized in the order they appear in the struct or class. I *think* you can also use designated initializers with unions, but don't quote me on that.
The basic setup would look something like this: c++ extension, clangd extension (provides a better LSP than the default), make or cmake extensions (not really needed, since both make and cmake are text based, the extensions don't add much value), git extension. If you're on unix-like system (linux\bsd\mac) use the system package manager to download the compiler (I'd prefer clang, but gcc is also fine) and 3d party libraries. If you're on windows, use MSYS2 to get a unix-like environment + a package manager to download the compiler (mingw (a port of gcc for windows) or clang) and the 3d party libraries.
I think it should be the de facto standard way to program things. Not C++ Only a few features of C++ are useful. Like Handmade hero uses a lot of C++ but it is still pretty good code. It doesn't become too anal with the features.
I would recommend against any language with undefined behavior as a pedagogical language. There's no point in making things harder than they need to be. Plus C has all kinds of implicit rules that beginners won't know. So stick to something where as much as possible is explicit. Example: suppose x is an unsigned char with value 5. What is the value of (~x) >> 2? In any reasonable language the result would be 0x3e, I think. Tell me what C does is reasonable here
I think the problem with language being flexible is that when you are in a company and that company has 50 programmers, you can't expect those 50 programmers to be necessarily "good" programmers. So if the language is too flexible then you will get hit with chunks of weird code every now and then.
I didn't pick up programming until late in my life. I can relate to the thing you mentioned regarding being an adult. Having to hold down a job really limits how much time you can spend learning.
It's totally doable - the key is to remember you don't have to use every feature of the language! I have lots of C projects filled with pointers to functions that honestly would have been cleaner in C++ for close to the same object output.
@hwstar9416 a wrong symbol in any language can totally break your code. With C++ you have some really nice control about types and where exactly stuff get's stored in memory. Which makes it a perfect choice for many embedded applications. Because once you made something SPI_1 nothing can cause it by accident, neither UART_1 nor SPI_2.
Good for you Dude! And you know how the game works, don't worry what the usual naysayers have to say here! This is a "social" media platform after all 👍🏼
The fact that a 13 year old made this blows my mind. My son is 13 year old and I tried to learn him LUA a few weeks ago to help him with his Roblox adventures. It was way too much to comprehend for him. I can't imagine him writing a game engine in C haha
Sometimes, it feels like some people are born with, or somehow end up with natural care for programming :D This 13 year-old could have found their interest for programming at its core, whereas others trying to *intentionally* learn it might not end up feeling as much deep interest, making it less smooth to learn.
@@XeZrunner yeah ikr.. but sometimes you need an spark too and sometimes it comes from your end purely am 18 now ( started at 14-15 ) and like am good in python , lua , C ( ofc I won't claim to be actually good but am at intermediate level in all these ) , JS(almost advanced ... can make what I want like games on websites , mini applications etc. but may not be best optimised ) , Java .... and then there a bit of other things like scripting , vulnerability explorationg and ofc several detours in other fields like networking and hacking.. rn have took break from coding intentionally for a year so that could prep for entrance exams and pick CSE there, talking about IITs if you know -- am Indian , but still often find myself to these videos.
@@XeZrunner the want to learn needs to be present is all, it could take 1 application to peak an interest, when I started it was telnet and irc that pushed my interest lol so i went the hard route not only did i have to mess with sockets but also with gui's, mfc gui's are a mess top it off with sockets lol.
I really like how fast C compiles compared C++. I like programming in C++ more, but sometimes when starting a new project i choose to write it in C just for the compilation speeds.
how much additional delay do you find C & C++ compile times? Also, do you mean "it's faster using a compiler built for C"? Cuz I sometimes use gcc instead of g++ even when both work, but I don't see the difference. (doubt file extension makes a difference). Though I admit I haven't made anything much in C (just used it for Computer Networks' socket programming a little -- REALLY hated how scanf worked, after having used just cpp's cin for 3 semesters prior.)
@@healthystrongmuslim if you run gcc against C++ code it actually runs g++ under the hood. That's probably why gcc worked for you and there were no diffrences in comp times. C++ compilation is slow because of templates, huge headers and much more semantic rules.
@ilikebananas342 Hmm I know running g++ with C code returns the same result as with gcc, but gcc doesn't seem like it can replace g++ Just tried with a cpp, copy pasting the exact output (the only change in command is "gcc"→"g++"; the result is simply that gcc is throwing a linking error whereas g++ compiles it as usual): ~ $ gcc $m/pity.cpp -o a ld.lld: error: undefined symbol: operator new[](unsigned long) >>> referenced by pity.cpp >>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(main) ld.lld: error: undefined symbol: operator delete[](void*) >>> referenced by pity.cpp >>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(main) ld.lld: error: undefined symbol: pow >>> referenced by pity.cpp >>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(double std::__ndk1::__math::pow[abi:ne180000](double, double)) gcc: error: linker command failed with exit code 1 (use -v to see invocation) ~ $ g++ $m/pity.cpp -o a ~ $
To clarify, the reason typedef is often used is that if you just do struct Foo { ... } you can then only use it like this struct Foo my_foo; (You have put struct before the name of it.) So we typedef it, which then could be done like this typedef struct Foo Foo; This creates an alias for struct Foo that is just Foo. But you could also inline it like this typedef struct Foo { ... } Foo; or you could use an anonymous struct (one that doen't have a name) and make an alias for it (giving it a name) like this typedef struct { ... } Foo; This is also the case for enums, but instead it forces you to prefix it with the keyword "enum".
What I like to do is typedef the struct as an array of one element, then you get stack allocation and you can pass it around as a pointer. It's like references in C.
There are some C projects that forbid typedefing a struct (e.g. Linux Kernel). The rationale for this is that you're not able to diffrentiate between structs, enums and unions.
@@anon_y_mousse It is a rationale, a style preference, not for compatibility. From Linux Kernel coding standards: "5) Typedefs: Please don’t use things like 'vps_t'. It’s a mistake to use typedef for structures and pointers. When you see a 'vps_t a;' in the source, what does it mean? In contrast, if it says 'struct virtual_container *a;' you can actually tell what a is. [...]" I would link you to this but any comment with link gets deleted on youtube. There are more reasons given in those docs. I hope you'll find them with google search. OpenBSD and Suckless have similar coding standards. I also heard some technical opinions against typedef'ing the struct but I don't quite remember them (something about symbols clashing).
This was so helpful for me - as a hobbyist and someone who did not get a CompSci / SoftEng degree or professional training, it's hard to sift through the noise from the different camps and get at more practical, or construction discussions around programming choices (either stylistic, or language etc.). It becomes so confusing to me when bandwagons and/or sub-communities bandy words together. I like the general idea of - more tools good for solving problems. I've recently learned C, using Raylib to make a simple survivors x asteroids clone, and learning the help that c++ provides (even if it may just be semantics) is so rewarding (and refreshing) to hear.
13:25 ... it is OOP (data and logic are semantically grouped) which is exactly not like an ECS (data and logic are separated). OOP does not mean "inheritance" (that is one part of OOP), but the most fundamental part is grouping logic and data to form an "object".
Got confused about that as well but yeah, it's OOP. Go for example doesn't support inheritance but allows to group data and logic together, which means it still support OOP, albeit no Inheritance.
I must say, I have enjoyed this channel quite a lot. Content creators who pay some attention to the comments in general, and kind of put themselves into the content, are a great boon to the world. I think it really helps make all us introverted nerds feel a bit less isolated.
I was listening to your comments on C vs C++ and it reminded me of my Analysis of algorithms class. We spent most of the semester implementing different algorithms using dynamic memory allocation and determining the big O notion for each algorithm. The last couple week, we reimplemented all the algorithms we learned throughout the semester using arrays, typically on the stack, instead of dynamic memory allocation. And almost every algorithm was faster when you implemented them using arrays on the stack instead of allocating everything on the heap. And you don’t wind up with memory leaks, even if there’s a bug. Now I know this isn’t possible for all software, but perhaps not everything in your code needs to live in the heap.
This is probably the best video you made recently. While I strongly disagree about the goodness of "data + functions" linked together, I think you made justice to the C programming language, shutting down the "everything should be modeled" toxic mindset. Let's remember how actual computers work. I guess HandmadeHero alias the legend Casey Muratori would be proud. :D Raytracing series comeback please.
I like linking data and functions when the functions are really about said data and only about it, and each piece of the data makes sense in the context of the whole.
@@user-sl6gn1ss8p linking functions to specific data imposes a psychological constraint that stifles creativity. By shifting your perspective to focus on functions as tools for transforming data, you unlock boundless potential, eliminate unnecessary complexity, and achieve unparalleled reusability. That way you are close to the metal. Object-oriented programming, while offering an _apparent_ simplification, with its rigid focus on objects, deviates significantly from the fundamental nature of computation, offering a narrowly constrained approach that often limits the true power of programming.
I'm late to the party, but I would LOVE to see a VSCode C++ setup tutorial, as someone who's been using it for a couple of years (VS too laggy for me, and I like that it's multi-platform)
In the first year of my maths degree, I took CS as an outside subject, and we learned Java (this was 2003, so Java 1.4 I think), which was my first introduction to programming. Meanwhile in maths we learned Maple, a computer algebra system (CAS) which is an entirely different beast! A few years later I learned R, then Matlab, then _finally_ I started learning C++, and used that for many years (along with GNU Octave to plot data, which was a mistake in hindsight, I should have been using R), but I was using in a way that was basically C with vectors and function overloading. Anyway, despite starting with Java, I never really got into OOP, and now my preferred coding style sits somewhere in the middle of C's procedural style with some of C++'s syntactic sugar, and R's functional style. But I do think if you're starting to learn to program, you could do worse than watch the MIT SICP lectures that used Lisp to introduce the various fundamental principles.
Fully agree with your thoughts about OOP. But i have 1 question. When we should use stack allocation and when heap allocation. Stack have speed advantage, what about heap ? The only heap advantage i think is using external memory.
You should use stack when possible. If what you're trying to do is not possible on stack, you then allocate it on heap. Examples (debatable): sharing resources between threads or devices; returning resources from function very deep in a callstack; allocating big chunk of memory that could overflow the stack; allocating memory of variable size that needs to grow over time.
@@Gandalf18404 Not really. It's impossible to detected when exacly stack overflows (a function like alloca never fails and there is no way to detect if next function call would overflow). However, you can probably assume that allocating 10MB of mem will overflow it. See? You have to use heap in said case. Another case: you need to load a resource on one thread and then use it on another. Threads do not share the same stack space. See? Again, you need to use heap here. Don't think in terms "stack vs heap" . You just use stack by default because this is how C and C++ (and any other assembly-based language) work. Heap is just like additional memory that OS lets you use. There are situation (e.g. some embeded systems / micro controllers) that don' t even have heap.
I started coding BASIC in a summer course, then 8085 ASM in tech school. That was in the late 80s / early 90s. I was 16 y/o. Moved to TP (Pascal) then TC (Turbo C) then Turbo C++. I wrote a Serial based VT220 Terminal Emulator in C then C++ (no windows, no networking) when I started working as a telecoms tech. I finished that project in 1992, when I was 22. I used C++ to treat each serial session in COM1 and COM2 as an object, and used a hot key to switch between one and the other. Fond memories. Today I use and still use C++ Builder. A windows based C++ compiler from embacadero.
You skipped Delphi? Builders compiler is rocket fast (proper precompiled headers/libs) - I used it up until about 5 years - couldn't handle d/com mess with it. Interestingly TP->TC->Object Vision->Delphi/Builder->VCL- are the precursors to C# - same dude designed it.
13:37 what you've also done is made it harder for any 3rd party devs (aka those who USE the types and functions) to use the data in any way other than the 1st party dev approved way. I consider that disgusting, the purpose of a library is to be used, not to control. **Edit:** Another con to classes is that they don't enable error checking during initialisation phase. Where in Engine() did you see it RETURNING a failed initialisation? Nowhere because the only way to catch said error is with a try block but that forces you to continually create new scopes just to catch each and every initialisation failure. For example try { Class1 cls1; try { Class2 cls2; try { ClassN clsN; ... And that just looks ugly as f**k in addition to being inconvenient. The more I think about C++ quirks the more hateful I find it.
One cannot write `engine engine;` in C, not even in C23, it is invalid. It has to be `struct engine engine;`, which is very clear and there is no need to capitalize it like `Engine engine;` in such case. The reason it is compileable is probably because the compiler (most likely MSVC) treats it as C++ code or it is just being very permissive by default and you did not bother to change the default behavior.
I enjoy C because its simplicity kind of forces you to rethink problems and reframe things to a way that's more simple before you solve them. With C++, you have so many powerful tools to sledgehammer complex problems with even more complex solutions.
It was one of the best day, when I found your Channel for learning C++ and eventually fallen in love with your content. One things are starting making sense and understandable, you would definitely start enjoying. Make sense to me, when I am watching your content which is 6 years old, but regrets me why I haven't watched it back then :/
13:10 You could kind of do that by using pointers to functions. Yea, yea, is not the same and you would need to pass the object as an argument (obj->init(obj)) and the function could be accessed from anywhere, but I saw a lot of projects do this to mimic this part of OOP.
Brilliant advice 12:50 onwards - a nuanced take on C++ and about using features in a sensible way. I like C, but I can use C++ like C, but with many better features. And it's only as complicated as one makes it. Keep it as simple as is appropriate for the task.
One of the issues I think with c++ is how rapidly and dramatically things can change with each standard. A simple example but when I first learned c++ everything was pointers with new. Then c++11 hit and it was smart pointers everywhere and raii. Then we had make_unique and initializers and new was frowned upon. Then we changed all that to instead pass by reference and return by value and the compiler will use move semantics to avoid copies of objects. I get that the compiler maintains compatibility with all old code but it makes it very difficult to keep up with best practices for the language. C on the other hand doesn’t ever really change. What was best practices when I was on school 20 years ago is still best practices today.
From my point of view we don't get much change with each new release. I've been waiting for a networking solution to be added to the standard library for like 10 years, they keep deferring it. C++23 gave us a bunch of tiny changes an ordinary programmer wouldn't even notice. RAII has been a part of the language basically since the beginning, any class that cleans up its resources in its destructor is exhibiting RAII which is pretty much everything in the std library like string, vector, map, list, etc.
@@ldov6373 I suppose it all depends on what we're looking at. I'm mostly focusing on what's considered the "right" way to write c++ which seems to change with every standard. It's not as though everything changes, there is a lot of similarity but it seems like recommending new things all the time.
C++ doesn't change that much though, it rarely deprecates, but provides new and better ways to do the same thing. RAII has been in C++ before the first standard C++.
C is definitely a good place to start imo. There are instances when you need to do your own memory management raw-style with malloc/calloc and, in particular, realloc; something you don't really learn about in c++ courses. (And later, C++ has the added benefit of letting you free and handle stuff "automatically" upon destruction of classes)
I wish I could do this much good programming at 13 years old. The only minor thing I was able to spot, is some for loop were using int iterator type, for indexing the arrays. I think more proper way is to use size_t type for that. Cheers!
Listening to you break this C code down without personally having any foundation in C programming went way over my head! The best I've ever done is teach myself a functional understanding of HTML from a book I found in the garbage! 😥
I love your reviews & I've been watching your content for years. This is my first time commenting. When it comes to the whole "engine engine" thing, a great way for him to differentiate type from variable would have been to use the common method of postfixing "_t" to user defined types. So, that should have been declared as "engine_t engine". But since engine is most likely a struct, it would have also been perfectly acceptable to do a typedef struct with a tag. This would have given him a definition that looks something like "typedef struct engine_s { } engine_t;". That would've allowed him to use the declaration "engine_t engine". Edit: Also, I wrote that comment before finishing the whole video.
Interesting review and regards the actual answer if C is better for starters than C++. My answer is yes, because you learn how the computer actually works. C is such a simple language and still very powerful. You can easiely follow the code flow, which is the opposite of C++. The OOP concept of classes, templates, etc. has nothing todo with computers at all. Its an arbitary thing that some people started and thought it may a good idea. And indeed for some stuff C++ or even other object oriented languages are a great tool. I like both, but am tending more towards C, because it is much simpler and i have more control over it.
Whether one should use C or C++? I would say it might be better to start off learning what that particular industry uses. For game development it might be C++. For kernel or embedded development it might be best to learn C.
C is better to learn particularly because it's much closer to ASM, than any other language (except Fortran), but looks extremely familiar to most languages at the same time. learning C++ make it unobvious what happens under the hood of obj.call() or move semantics magic. in C you use those features as something you construct by hand and understand at first place before switching to syntactic sugar in C++ or even Rust. maybe not everyone must begin with C to then be able to write in C#, Python or JS (despite some facts), but C++ requires a bit more background
@@alexmiller3260 Yeah but c++ memory management is a lot simpler than C especially if the C library uses a complex reference counting system. In C sometimes you have to figure out which 'clean up' function to call because it is no longer clear. Whereas in C++ you can just rely on RAII to handle all of that for you while you just develop your program not spend extra time on unnecessary stuff. Though this is mostly because C has very little standardisation when learning C one of the first things I was told was 'There was as many concurrency libraries as there was C developers' because everyone created there own ways to do it. Meaning every codebase was different despite them all doing the samething.
@@-rya1146 it's easier because of destructors, which are called automatically and smart pointers born with RAII in mind, but again, it's a magic which complicate things in C++ specific manner that is supposed to be learnt after you got the basic idea. concurrency is a good point in this case, same can be said about hash tables, inheritance and other things that come from box in C++, on the other hand ease doesn't make it better to begin with (like nobody begin learning concurrency with Go coroutines). yeah, for a working projects I would probably think twice before choosing C, but learning it is essential
Nah. Programming is taking data and transforming it. How it relates to the computer that's running it, is absolutely crucial for a good gut feeling down the line (for example, that a small-say10k array might easily outperform hashmap). So for learning, something like C, rust and the likes might be annoying, but absolutely crucial. Learning anything else afterwards is easy, but what you've gained from those will stay with you forever. Also, it's arguably a difference between programmer and a scripter.
Please make a video on how to set up VS Code for C++, I am pretty much exlusively using VS Code and had so many issues with it when I was trying to compile C++ code with it.
This is my favorite video of yours. C is my favorite language atm and I agree with you on the repetition of namespaces/types part, I keep writing thing_function(&thing) all the time and it is annoying. Maybe very lean C++ would be the best language for me in the future. Really cool video!
I only use the most basic functionality of C++, just classes/objects to help organise the code (no inheritance or polymorphism) . For me it is the easiest, fastest and most agile way to develop.
I found your review useful and helpful 😊🎉 Thank you for all your efforts and hardwork to educate us with meaningful programming tips. Indeed, C and C++ are both powerful languages. I am a C# programmer but I do enjoy watching othet programming languages being used to develop such great applications. The learning and digging the rabbit hole never stops 😊
i love C ! i know other languages, before university i knew basic, assembly and C. modula-2 and C++ at university. 15 yrs ago java, 10 yrs ago it was python, 7 yrs ago go. last 6 yrs only C. in C, i only write things as i need them. i made a program in C that uses opengl to make 2d drawings or 3d models from a casual text description, executing on words it knows and ignoring words it doesnt. i once described something to my father, after which i asked him "see what i mean", he said no, n i realized, i know how to make that happen, so i did. i call it ncptr, because it incepts what i want.
Hey I just started learning c++ & I watch your videos a lot. Is there a way we can get on 1 on 1 where we discuss the best way to find imployment & write better c++ code?
The type system and templates might also be something you would appreciate. It let's you separate different things that are represented in the same datatype. So you get an compiler error and not just a warning if cast or point something wrong. Templates go along with this as they provide functionality for each datatype you implement once. So for example you don't need some "if in range of do ... " for each type, only for each native datatype. I use both languages and while you would use those features with classes, i personally found them more usefull than the oop features.
Would love to see the video about how to set up VS Code for C++. I've tried to do so, but I couldn't get it to see libraries that I had linked to and so on.
Thank u for reveiwing my code! Sir see my other projects, there I used premake and cmake also! In fact this is the only repo that uses make Sir I dont copy and paste code!! I use C++ for most of my projects in fact this is the only proj I use C only for this proj Also sir, this is the exact way I write C++ code. Also I am really 13 yrs old not kidding I am born on 2011, if u dont believe then I can send u my birth certificate
Don't sweat it too much. The most important thing is that you're writing code and learning. Your age is an advantage, listen to multiple sources and form your own style and learn the ins and outs of each language you like. You'll do great!
Look mate, I was programming in C and assembly at your age and raw-dogging Win16 programming just a few short years later. A kid like you tackling Vulkan is no surprise to me. Enjoy that youthful energy while you've got it, and put it to use. Have fun.
C is very nice in some ways, especially for interoperability between dynamically-linked libraries, and I also find that working with a pure C interface is often more user-friendly compared to C++. HOWEVER, I would definitely not recommend trying to implement the internals of your project in pure C. The C standard library is very bare bones and you will find yourself spending all your time reinventing the wheel instead of making progress on your actual project. There are no C alternatives to std::vector, string, list, map, unordered_map, set, etc. and the fact that C does not support templates means that if you want generic containers, they have to be written as preprocessor #defines. You could have just written it in C++ internally and created a pure C interface on top of it in the time it would take you to reinvent linked lists and destructors every time something needs them.
There are plenty of libraries written in C that provide the equivalent to standard C++ containers. Just because it's not in the standard library doesn't mean you have to write it yourself. I'll give you templates though, as using preprocessor macros and _Generic are more of a pain in the ass than templates are.
I think you should pick up a project that uses intermediate to aadvanced concepts in cpp and try to go about the code and explain it and go further to show alternatives and more. You can add parts to it and that could go on Code review. Not to mention how much it would help the beginners like me.
Love your video's dude, Love how you almost get C red pilled looking and nice C code, almost! Also I definitely think the submission was by a programmer with 13 years experience not a 13 year old and that was lost in translation. Finally "Yeah, well, you know, that's just, like, you opinion man" The Dude 12:27
I'd love to see how you set up C++ and/or C on VS Code. Btw, I can't understand why C still doesn't have namespaces, is there anything wrong with them?
I'm quite a grey-beard, so I learned to program on something before C (BASIC and Pascal), and I still recall the brain breakage (e.g. the bewildering for loop syntax, pre- and post-increment/decrement, pointers, type syntax) that was learning C as a new language (prior to the ANSI standard). There is so much about C, and C++ that is just not conducive to the novice, and there are so many better languages available today, that I could not recommend that anybody learn C or C++ as their first language. Python is a better language for the novice: dynamic types, minimal syntax, lots of room to grow. Swift is a better language: the interactive tooling is top notch, the language is stricture than I would like for a novice, but the error messages are really good. Even Java and C# are better than C/C++, though I think they are not very well designed for novices because they are too slavish to C/C++ syntax.
I started programming as a minor subject at university in 1979 where we used AlgolW, PL360 and assembler before moving to Pascal. I learned C in my first job and used it until 1995 when I started with C++ which was overtaken by Python in 2000, with a smattering of Java after inheriting someone else's project. Recently I failed to reverse engineer an HDF5 format results file using the Python h5py module and was forced to go back to the low level HDF5 API in C. What a revelation! Pro: you really have to think about data structures and memory packing. Con: you really have to think about data structures and memory packing. But it does make you appreciate ease of use of C++ std:vector, std::map, and iterators and the easier use of Python list and dict even though you can't get at the bare metal that C gives you.
with C you will shoot your foot off after you miss several times with C++ makes it harder with the safety but when you do take off the safety you proceed to blow off your entire leg. java well it gives you a water gun.
I feel you. C doubles up on the words. C++ can be application.start() while C is application_start(application) Why do I have to write "application" twice 😢my lines are so long.
Hey, could you make a video talking C++ 20 modules? What we should/shouldn't use it. Which is preferred header and source files or modules? I have started to write a game engine, but I am wondering if I should switch over to modules instead. Since it enhances building times and modularity of your source code.
@@xCwieCHRISx But once you do you basically never have to again. C lets you build your own language on top of it that you can use for the rest of your life.
considering the two most popular desktop operating systems still don't support C11 correctly, you might want to wait a while until you tackle on C23 (which is great, but absolutely not ready to be used yet)
@@atijohn8135 Guess I need to learn something else before I worry about C23 (or any programming language, for that matter). I don't even know what I am asking for and why. Thank you so much.
Ya I’d watch a video about optimizing dev environment setup. Do a linter, static analysis, dev container maybe, intelisense for third party headers, idk what else
“By the time you’re an adult you’ll know everything.” No, by the time you’re an adult, the officially blessed build system and IDE will have completely changed multiple times. Just learn the principles and keep up with current trends. Being an efficient lifelong learner is most of the job.
So what do you think - does the way that C is typically taught teach better programming principles than C++? 👇
To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TheCherno . You’ll also get 20% off an annual premium subscription.
VSCode for C++?!
YES PLEASE!!!
if you strt with C and you'll like it, youll hate object oriented programming, so yes.
Yeah C++ reliance on OOP is so bad. Whenever I write C++ it looks like C because I just prefer it that way. No classes, lambas, operator overloading, non of that junk.
after Rust experience I have a trigger on sentinel values and old days naming style with m_'s for struct or class members
Yep. I think C is better for beginners than C++.
"I like what I C" - The Cherno 30:00
It's really mind blowing that a 13-year old already in graphics programming. I was only playing games and knew nothing about programming except shell languages around that age.
@@cameonn you knew shell language? 🥲
Me programming at 13:
10 CLS
20 PRINT "HI MOM!"
Having access to the internet/unlimited tutrials is a huge advantage though, not saying I wasn't a lazy pos 17 years ago! 🤣
30 GOTO 20
I mean vulkan didn't exist back then, so you are fine.
Ya, in the mid 80s I looked in BASIC than eventually 6510 assembly; then by 1990 got into C on the Amiga. The assembly helped to fully understand the computer that later allowed me to do microcontroller programming later in the 1990s at work. But that is impressive that a 13 can do Vulkan; most programmers complain how much of a pain Vulkan is because of its verbosity.
I tried to get into programming early on, the only programming language I knew of was python. I stopped trying because the setup process for the compiler at the time was so terrible. Most I actually got into was advanced batch files, which doesn't really coun t.
im sure a lot of us would absolutely love a video on VSCode C++ setup. please take it into consideration
yes please
I'm so confused by these comments. VSCode is a text editor and C++ is just a compiled language. Just learn a compiler and write C++? Microsoft has a debug adapter for C++ that should work fine as an extension if you're trying to debug.
thats what it comes down to: learning the compiler + learning how vs code interscts with debugging tools. not exactly the most begginer friendly topics, and all to just be able to run code @@CoderShare
@@CoderShare he wants to know how to configure vscode to use a compiler and debugger, so that it acts more like a full-fledged IDE.
+1
24:12 there is a modern way of doing structure initialization since C supports strict assignment. You can do (type){ .field = Val, .field2= val2}; All unmentioned fields get zero initialized.
I was hoping someone would point this out 👍
The designated initializer has been available in c since 1999, it is more functional than in c++20
@@bies_moron4404 because it allows out of order initialization (hilarious how C++ is just objectively worse here)
You can do designated initializers in C++, but only for classes and structs that are "Plain Old Data." I forget what exactly are the qualifications for that, but I believe the type must have no declared constructors, no private or protected fields, and no virtual methods.
An important difference between the feature in C vs. C++ is that in C, fields may be initialized in any order, but in C++, they must be initialized in the order they appear in the struct or class.
I *think* you can also use designated initializers with unions, but don't quote me on that.
Hell yes, VScode for C++ is what we want.
windows 11 settings icon
@@KayleighOwO yes, I'm useless when it comes to changing settings, everyone uses the control panel instead of me :(
The basic setup would look something like this: c++ extension, clangd extension (provides a better LSP than the default), make or cmake extensions (not really needed, since both make and cmake are text based, the extensions don't add much value), git extension.
If you're on unix-like system (linux\bsd\mac) use the system package manager to download the compiler (I'd prefer clang, but gcc is also fine) and 3d party libraries. If you're on windows, use MSYS2 to get a unix-like environment + a package manager to download the compiler (mingw (a port of gcc for windows) or clang) and the 3d party libraries.
@@ivan_reshetnikovlol i use the research bar 😂
@@Raspredval1337why not use msvc on windows?
I love C for it's simplicity. I think it should be the first language people learn
Sure but what about siplusplusmplicity?
I think it should be the de facto standard way to program things. Not C++
Only a few features of C++ are useful. Like Handmade hero uses a lot of C++ but it is still pretty good code. It doesn't become too anal with the features.
It's the only language people should learn. Everything else is a waste of time.
I would recommend against any language with undefined behavior as a pedagogical language. There's no point in making things harder than they need to be. Plus C has all kinds of implicit rules that beginners won't know. So stick to something where as much as possible is explicit. Example: suppose x is an unsigned char with value 5. What is the value of (~x) >> 2? In any reasonable language the result would be 0x3e, I think. Tell me what C does is reasonable here
@@tolkienfan1972 Some parts of C is really fucked up I agree
I think the problem with language being flexible is that when you are in a company and that company has 50 programmers, you can't expect those 50 programmers to be necessarily "good" programmers. So if the language is too flexible then you will get hit with chunks of weird code every now and then.
Isn't that what professional code reviews are for?
@@DiamondWolfX you can’t cover everything 100% of the time. Emergencies and time pressure will increase error rate.
@@DiamondWolfXif only we did reviews at my company
JavaScript: **slowly backs out of room**
@@DiamondWolfX Do they do code reviews at your company?
I didn't pick up programming until late in my life. I can relate to the thing you mentioned regarding being an adult. Having to hold down a job really limits how much time you can spend learning.
Been using c++ for embedded systems for years, still does the job pretty well
hmmm i wouldnt agree tbh. In C++ a missed & can cause a vector to clone itself. RAII has no place in embedded, it's too risky.
It's totally doable - the key is to remember you don't have to use every feature of the language! I have lots of C projects filled with pointers to functions that honestly would have been cleaner in C++ for close to the same object output.
@@hwstar9416 you don't have to use it just because it's there. Just use the convenience features. Arrays are more performant anyways.
@hwstar9416 a wrong symbol in any language can totally break your code.
With C++ you have some really nice control about types and where exactly stuff get's stored in memory. Which makes it a perfect choice for many embedded applications. Because once you made something SPI_1 nothing can cause it by accident, neither UART_1 nor SPI_2.
Good for you Dude! And you know how the game works, don't worry what the usual naysayers have to say here! This is a "social" media platform after all 👍🏼
The fact that a 13 year old made this blows my mind. My son is 13 year old and I tried to learn him LUA a few weeks ago to help him with his Roblox adventures. It was way too much to comprehend for him. I can't imagine him writing a game engine in C haha
Sometimes, it feels like some people are born with, or somehow end up with natural care for programming :D
This 13 year-old could have found their interest for programming at its core, whereas others trying to *intentionally* learn it might not end up feeling as much deep interest, making it less smooth to learn.
@@XeZrunner yeah ikr.. but sometimes you need an spark too and sometimes it comes from your end purely am 18 now ( started at 14-15 ) and like am good in python , lua , C ( ofc I won't claim to be actually good but am at intermediate level in all these ) , JS(almost advanced ... can make what I want like games on websites , mini applications etc. but may not be best optimised ) , Java .... and then there a bit of other things like scripting , vulnerability explorationg and ofc several detours in other fields like networking and hacking.. rn have took break from coding intentionally for a year so that could prep for entrance exams and pick CSE there, talking about IITs if you know -- am Indian , but still often find myself to these videos.
Your son is really dumb. When I was 13 I programmed mods for my favorite games left and right. I don't want to brag, it's just the harsh truth.
@@XeZrunner the want to learn needs to be present is all, it could take 1 application to peak an interest, when I started it was telnet and irc that pushed my interest lol so i went the hard route not only did i have to mess with sockets but also with gui's, mfc gui's are a mess top it off with sockets lol.
@@Arcane_Ayush Same, brother. JEE has me fucked.
I really like how fast C compiles compared C++. I like programming in C++ more, but sometimes when starting a new project i choose to write it in C just for the compilation speeds.
GO compiles even faster then C!
@@Pear64 Why? What didn't you like about GO? Particularly what makes C better? I find it ~mostly~ pretty easy to work with.
how much additional delay do you find C & C++ compile times? Also, do you mean "it's faster using a compiler built for C"?
Cuz I sometimes use gcc instead of g++ even when both work, but I don't see the difference. (doubt file extension makes a difference).
Though I admit I haven't made anything much in C (just used it for Computer Networks' socket programming a little -- REALLY hated how scanf worked, after having used just cpp's cin for 3 semesters prior.)
@@healthystrongmuslim if you run gcc against C++ code it actually runs g++ under the hood. That's probably why gcc worked for you and there were no diffrences in comp times. C++ compilation is slow because of templates, huge headers and much more semantic rules.
@ilikebananas342 Hmm I know running g++ with C code returns the same result as with gcc, but gcc doesn't seem like it can replace g++
Just tried with a cpp, copy pasting the exact output (the only change in command is "gcc"→"g++"; the result is simply that gcc is throwing a linking error whereas g++ compiles it as usual):
~ $ gcc $m/pity.cpp -o a
ld.lld: error: undefined symbol: operator new[](unsigned long)
>>> referenced by pity.cpp
>>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(main)
ld.lld: error: undefined symbol: operator delete[](void*)
>>> referenced by pity.cpp
>>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(main)
ld.lld: error: undefined symbol: pow
>>> referenced by pity.cpp
>>> /data/data/com.termux/files/usr/tmp/pity-cc8521.o:(double std::__ndk1::__math::pow[abi:ne180000](double, double))
gcc: error: linker command failed with exit code 1 (use -v to see invocation)
~ $ g++ $m/pity.cpp -o a
~ $
To clarify, the reason typedef is often used is that if you just do struct Foo { ... } you can then only use it like this struct Foo my_foo; (You have put struct before the name of it.) So we typedef it, which then could be done like this typedef struct Foo Foo; This creates an alias for struct Foo that is just Foo. But you could also inline it like this typedef struct Foo { ... } Foo; or you could use an anonymous struct (one that doen't have a name) and make an alias for it (giving it a name) like this typedef struct { ... } Foo;
This is also the case for enums, but instead it forces you to prefix it with the keyword "enum".
We typedef a struct to be able to use it like a type, without writing struct first
What I like to do is typedef the struct as an array of one element, then you get stack allocation and you can pass it around as a pointer. It's like references in C.
There are some C projects that forbid typedefing a struct (e.g. Linux Kernel). The rationale for this is that you're not able to diffrentiate between structs, enums and unions.
@ Is that really the rationale, or did it have to do with compatibility with older standards?
@@anon_y_mousse It is a rationale, a style preference, not for compatibility.
From Linux Kernel coding standards:
"5) Typedefs: Please don’t use things like 'vps_t'. It’s a mistake to use typedef for structures and pointers. When you see a 'vps_t a;' in the source, what does it mean? In contrast, if it says 'struct virtual_container *a;' you can actually tell what a is. [...]"
I would link you to this but any comment with link gets deleted on youtube. There are more reasons given in those docs. I hope you'll find them with google search. OpenBSD and Suckless have similar coding standards.
I also heard some technical opinions against typedef'ing the struct but I don't quite remember them (something about symbols clashing).
This was so helpful for me - as a hobbyist and someone who did not get a CompSci / SoftEng degree or professional training, it's hard to sift through the noise from the different camps and get at more practical, or construction discussions around programming choices (either stylistic, or language etc.). It becomes so confusing to me when bandwagons and/or sub-communities bandy words together.
I like the general idea of - more tools good for solving problems.
I've recently learned C, using Raylib to make a simple survivors x asteroids clone, and learning the help that c++ provides (even if it may just be semantics) is so rewarding (and refreshing) to hear.
13:25 ... it is OOP (data and logic are semantically grouped) which is exactly not like an ECS (data and logic are separated).
OOP does not mean "inheritance" (that is one part of OOP), but the most fundamental part is grouping logic and data to form an "object".
Absolutely it is OOP. By literal definition.
Got confused about that as well but yeah, it's OOP. Go for example doesn't support inheritance but allows to group data and logic together, which means it still support OOP, albeit no Inheritance.
I must say, I have enjoyed this channel quite a lot. Content creators who pay some attention to the comments in general, and kind of put themselves into the content, are a great boon to the world. I think it really helps make all us introverted nerds feel a bit less isolated.
I was listening to your comments on C vs C++ and it reminded me of my Analysis of algorithms class.
We spent most of the semester implementing different algorithms using dynamic memory allocation and determining the big O notion for each algorithm.
The last couple week, we reimplemented all the algorithms we learned throughout the semester using arrays, typically on the stack, instead of dynamic memory allocation. And almost every algorithm was faster when you implemented them using arrays on the stack instead of allocating everything on the heap. And you don’t wind up with memory leaks, even if there’s a bug.
Now I know this isn’t possible for all software, but perhaps not everything in your code needs to live in the heap.
This is probably the best video you made recently.
While I strongly disagree about the goodness of "data + functions" linked together, I think you made justice to the C programming language, shutting down the "everything should be modeled" toxic mindset. Let's remember how actual computers work. I guess HandmadeHero alias the legend Casey Muratori would be proud. :D
Raytracing series comeback please.
I like linking data and functions when the functions are really about said data and only about it, and each piece of the data makes sense in the context of the whole.
@@user-sl6gn1ss8p linking functions to specific data imposes a psychological constraint that stifles creativity. By shifting your perspective to focus on functions as tools for transforming data, you unlock boundless potential, eliminate unnecessary complexity, and achieve unparalleled reusability. That way you are close to the metal. Object-oriented programming, while offering an _apparent_ simplification, with its rigid focus on objects, deviates significantly from the fundamental nature of computation, offering a narrowly constrained approach that often limits the true power of programming.
It's never too late to start learning programming, but it might be too late to become a prodigy. Making this at the age of 13 is insane.
experienced devs don't spend much time coding anyway these days
I'm late to the party, but I would LOVE to see a VSCode C++ setup tutorial, as someone who's been using it for a couple of years (VS too laggy for me, and I like that it's multi-platform)
In the first year of my maths degree, I took CS as an outside subject, and we learned Java (this was 2003, so Java 1.4 I think), which was my first introduction to programming. Meanwhile in maths we learned Maple, a computer algebra system (CAS) which is an entirely different beast!
A few years later I learned R, then Matlab, then _finally_ I started learning C++, and used that for many years (along with GNU Octave to plot data, which was a mistake in hindsight, I should have been using R), but I was using in a way that was basically C with vectors and function overloading.
Anyway, despite starting with Java, I never really got into OOP, and now my preferred coding style sits somewhere in the middle of C's procedural style with some of C++'s syntactic sugar, and R's functional style.
But I do think if you're starting to learn to program, you could do worse than watch the MIT SICP lectures that used Lisp to introduce the various fundamental principles.
Would love to see a VS Code C++ setup video!
Спасибо!
I learned to program in C... and then learned C++ thereafter... this in my opinion is the best way to learn programming
hey, please can you help with the why?
I want to learn C++ for data structures and algorithms but I don't know if not starting with C will affect me.
Fully agree with your thoughts about OOP. But i have 1 question. When we should use stack allocation and when heap allocation. Stack have speed advantage, what about heap ? The only heap advantage i think is using external memory.
You should use stack when possible. If what you're trying to do is not possible on stack, you then allocate it on heap. Examples (debatable): sharing resources between threads or devices; returning resources from function very deep in a callstack; allocating big chunk of memory that could overflow the stack; allocating memory of variable size that needs to grow over time.
@ilikebananas342 So basically I need use stack until it overflow.
@@Gandalf18404 Not really. It's impossible to detected when exacly stack overflows (a function like alloca never fails and there is no way to detect if next function call would overflow). However, you can probably assume that allocating 10MB of mem will overflow it. See? You have to use heap in said case. Another case: you need to load a resource on one thread and then use it on another. Threads do not share the same stack space. See? Again, you need to use heap here. Don't think in terms "stack vs heap" . You just use stack by default because this is how C and C++ (and any other assembly-based language) work. Heap is just like additional memory that OS lets you use. There are situation (e.g. some embeded systems / micro controllers) that don' t even have heap.
Thumbs up for your explanation of the way cpp is tought in general and that it is not necessary.
Imagine getting a CS degree when you can do this at 13.
5:19 c++/cmake aficionado being stumped that a project compiles fast.
More often than not in these code reviews the code doesn't compile from the instructions given. So the fact that it compiled at all was a surprise.
Glad you differentiate C from C++ , so many think C++ is just suped up C.
yeah, much needed video about configuring vscode for C++ support
I started coding BASIC in a summer course, then 8085 ASM in tech school. That was in the late 80s / early 90s. I was 16 y/o. Moved to TP (Pascal) then TC (Turbo C) then Turbo C++. I wrote a Serial based VT220 Terminal Emulator in C then C++ (no windows, no networking) when I started working as a telecoms tech. I finished that project in 1992, when I was 22. I used C++ to treat each serial session in COM1 and COM2 as an object, and used a hot key to switch between one and the other. Fond memories.
Today I use and still use C++ Builder. A windows based C++ compiler from embacadero.
You skipped Delphi? Builders compiler is rocket fast (proper precompiled headers/libs) - I used it up until about 5 years - couldn't handle d/com mess with it. Interestingly TP->TC->Object Vision->Delphi/Builder->VCL- are the precursors to C# - same dude designed it.
That must have taken you a lot of time.
very little documentation and tools, plugins were not supported like they are now.
13:37 what you've also done is made it harder for any 3rd party devs (aka those who USE the types and functions) to use the data in any way other than the 1st party dev approved way. I consider that disgusting, the purpose of a library is to be used, not to control.
**Edit:** Another con to classes is that they don't enable error checking during initialisation phase. Where in Engine() did you see it RETURNING a failed initialisation? Nowhere because the only way to catch said error is with a try block but that forces you to continually create new scopes just to catch each and every initialisation failure. For example
try
{
Class1 cls1;
try
{
Class2 cls2;
try
{
ClassN clsN;
...
And that just looks ugly as f**k in addition to being inconvenient.
The more I think about C++ quirks the more hateful I find it.
One cannot write `engine engine;` in C, not even in C23, it is invalid. It has to be `struct engine engine;`, which is very clear and there is no need to capitalize it like `Engine engine;` in such case. The reason it is compileable is probably because the compiler (most likely MSVC) treats it as C++ code or it is just being very permissive by default and you did not bother to change the default behavior.
Hey man, great to meet you in real life at yowcon. My colleagues really enjoyed your presentation and learning about hazel.
01:30 yes please. Will definitely love that
I enjoy C because its simplicity kind of forces you to rethink problems and reframe things to a way that's more simple before you solve them. With C++, you have so many powerful tools to sledgehammer complex problems with even more complex solutions.
It was one of the best day, when I found your Channel for learning C++ and eventually fallen in love with your content. One things are starting making sense and understandable, you would definitely start enjoying. Make sense to me, when I am watching your content which is 6 years old, but regrets me why I haven't watched it back then :/
13:10 You could kind of do that by using pointers to functions.
Yea, yea, is not the same and you would need to pass the object as an argument (obj->init(obj)) and the function could be accessed from anywhere, but I saw a lot of projects do this to mimic this part of OOP.
Brilliant advice 12:50 onwards - a nuanced take on C++ and about using features in a sensible way. I like C, but I can use C++ like C, but with many better features. And it's only as complicated as one makes it. Keep it as simple as is appropriate for the task.
Would definitely love a video on setting up VSCode for C++
One of the issues I think with c++ is how rapidly and dramatically things can change with each standard. A simple example but when I first learned c++ everything was pointers with new. Then c++11 hit and it was smart pointers everywhere and raii. Then we had make_unique and initializers and new was frowned upon. Then we changed all that to instead pass by reference and return by value and the compiler will use move semantics to avoid copies of objects.
I get that the compiler maintains compatibility with all old code but it makes it very difficult to keep up with best practices for the language. C on the other hand doesn’t ever really change. What was best practices when I was on school 20 years ago is still best practices today.
From my point of view we don't get much change with each new release. I've been waiting for a networking solution to be added to the standard library for like 10 years, they keep deferring it. C++23 gave us a bunch of tiny changes an ordinary programmer wouldn't even notice. RAII has been a part of the language basically since the beginning, any class that cleans up its resources in its destructor is exhibiting RAII which is pretty much everything in the std library like string, vector, map, list, etc.
@@ldov6373 I suppose it all depends on what we're looking at. I'm mostly focusing on what's considered the "right" way to write c++ which seems to change with every standard. It's not as though everything changes, there is a lot of similarity but it seems like recommending new things all the time.
C++ doesn't change that much though, it rarely deprecates, but provides new and better ways to do the same thing. RAII has been in C++ before the first standard C++.
Enjoyed your discussion on c and c++ data and function organization
YES that would be greate a video about setting up VSCode for c++ , thanks
I'm just a few minutes in and yes I already be one of those voting for a video on setting up VSCode. Thank you.
C is definitely a good place to start imo.
There are instances when you need to do your own memory management raw-style with malloc/calloc and, in particular, realloc; something you don't really learn about in c++ courses.
(And later, C++ has the added benefit of letting you free and handle stuff "automatically" upon destruction of classes)
I wish I could do this much good programming at 13 years old. The only minor thing I was able to spot, is some for loop were using int iterator type, for indexing the arrays. I think more proper way is to use size_t type for that. Cheers!
Listening to you break this C code down without personally having any foundation in C programming went way over my head! The best I've ever done is teach myself a functional understanding of HTML from a book I found in the garbage! 😥
setting up vscode for c++ would be dope!!
A vscode c++ setup video would be really intestesting!
I love your reviews & I've been watching your content for years. This is my first time commenting. When it comes to the whole "engine engine" thing, a great way for him to differentiate type from variable would have been to use the common method of postfixing "_t" to user defined types. So, that should have been declared as "engine_t engine". But since engine is most likely a struct, it would have also been perfectly acceptable to do a typedef struct with a tag. This would have given him a definition that looks something like "typedef struct engine_s { } engine_t;". That would've allowed him to use the declaration "engine_t engine".
Edit: Also, I wrote that comment before finishing the whole video.
Interesting review and regards the actual answer if C is better for starters than C++. My answer is yes, because you learn how the computer actually works. C is such a simple language and still very powerful. You can easiely follow the code flow, which is the opposite of C++. The OOP concept of classes, templates, etc. has nothing todo with computers at all. Its an arbitary thing that some people started and thought it may a good idea. And indeed for some stuff C++ or even other object oriented languages are a great tool. I like both, but am tending more towards C, because it is much simpler and i have more control over it.
I would really love a video on how to set up C++ in VS Code. I am using Linux and VS Code is probably the best option I have right now!
A video about how to read code, using the debugger, would be great for learning best practices.
Liked this review so much. Hope to see more C stuff and comparisons with C++ with good technique.
Whether one should use C or C++? I would say it might be better to start off learning what that particular industry uses. For game development it might be C++. For kernel or embedded development it might be best to learn C.
C is better to learn particularly because it's much closer to ASM, than any other language (except Fortran), but looks extremely familiar to most languages at the same time. learning C++ make it unobvious what happens under the hood of obj.call() or move semantics magic. in C you use those features as something you construct by hand and understand at first place before switching to syntactic sugar in C++ or even Rust. maybe not everyone must begin with C to then be able to write in C#, Python or JS (despite some facts), but C++ requires a bit more background
@@alexmiller3260 Yeah but c++ memory management is a lot simpler than C especially if the C library uses a complex reference counting system. In C sometimes you have to figure out which 'clean up' function to call because it is no longer clear. Whereas in C++ you can just rely on RAII to handle all of that for you while you just develop your program not spend extra time on unnecessary stuff. Though this is mostly because C has very little standardisation when learning C one of the first things I was told was 'There was as many concurrency libraries as there was C developers' because everyone created there own ways to do it. Meaning every codebase was different despite them all doing the samething.
@@-rya1146 it's easier because of destructors, which are called automatically and smart pointers born with RAII in mind, but again, it's a magic which complicate things in C++ specific manner that is supposed to be learnt after you got the basic idea. concurrency is a good point in this case, same can be said about hash tables, inheritance and other things that come from box in C++, on the other hand ease doesn't make it better to begin with (like nobody begin learning concurrency with Go coroutines). yeah, for a working projects I would probably think twice before choosing C, but learning it is essential
@@-rya1146well, for some reason I can't see my recent reply to you, so, I hope you still can 🥲
Nah. Programming is taking data and transforming it. How it relates to the computer that's running it, is absolutely crucial for a good gut feeling down the line (for example, that a small-say10k array might easily outperform hashmap).
So for learning, something like C, rust and the likes might be annoying, but absolutely crucial. Learning anything else afterwards is easy, but what you've gained from those will stay with you forever.
Also, it's arguably a difference between programmer and a scripter.
Please make a video on how to set up VS Code for C++, I am pretty much exlusively using VS Code and had so many issues with it when I was trying to compile C++ code with it.
This is my favorite video of yours. C is my favorite language atm and I agree with you on the repetition of namespaces/types part, I keep writing thing_function(&thing) all the time and it is annoying. Maybe very lean C++ would be the best language for me in the future. Really cool video!
I only use the most basic functionality of C++, just classes/objects to help organise the code (no inheritance or polymorphism) . For me it is the easiest, fastest and most agile way to develop.
Exactly, after decades of trying all the shiny fancy c++ I reverted back to c style c++ code, it's the best
Yes would love if you do a vs code cpp setup video
Thank you, Mr. Cherno!
I'm very interesting in the video about setting up Vscode for C++!
I found your review useful and helpful 😊🎉 Thank you for all your efforts and hardwork to educate us with meaningful programming tips. Indeed, C and C++ are both powerful languages. I am a C# programmer but I do enjoy watching othet programming languages being used to develop such great applications. The learning and digging the rabbit hole never stops 😊
Next video: the guy says he's an infact just 3 weeks old, writing his own weather simulator 😐😐😐😐
My neighbor's kid wrote an app before leaving the maternity ward. 🚼 It sucked 👎, but still rather impressive.
i love C !
i know other languages,
before university i knew basic, assembly and C.
modula-2 and C++ at university.
15 yrs ago java,
10 yrs ago it was python,
7 yrs ago go.
last 6 yrs only C.
in C, i only write things as i need them.
i made a program in C that uses opengl
to make 2d drawings or 3d models
from a casual text description,
executing on words it knows
and ignoring words it doesnt.
i once described something to my father,
after which i asked him "see what i mean",
he said no, n i realized, i know how to
make that happen, so i did.
i call it ncptr,
because it incepts what i want.
Hey I just started learning c++ & I watch your videos a lot. Is there a way we can get on 1 on 1 where we discuss the best way to find imployment & write better c++ code?
Yes please !!! Do a video on VS Code setup for C++!!
I make games in C and absolutely love it. I like the classes in C++ but that's about it. Not good enough reason to use C++ for me at least..
The type system and templates might also be something you would appreciate. It let's you separate different things that are represented in the same datatype. So you get an compiler error and not just a warning if cast or point something wrong. Templates go along with this as they provide functionality for each datatype you implement once. So for example you don't need some "if in range of do ... " for each type, only for each native datatype.
I use both languages and while you would use those features with classes, i personally found them more usefull than the oop features.
you can write all C in C++ so why not if you like the classes?
@@JavedAlam-ce4mu Guess I'm just a purist. I can live without classes.. it's just one of the few positives I see with C++ that's all..
Rock and Roll 🔥
Would love to see the video about how to set up VS Code for C++. I've tried to do so, but I couldn't get it to see libraries that I had linked to and so on.
1:30 yes I would definitely love to learn how to setup c++ the cherno's way in vs code
really need a video for setting c++ in vscode for mac/linux/windows
Thank u for reveiwing my code!
Sir see my other projects, there I used premake and cmake also! In fact this is the only repo that uses make
Sir I dont copy and paste code!!
I use C++ for most of my projects in fact this is the only proj I use C only for this proj
Also sir, this is the exact way I write C++ code.
Also I am really 13 yrs old not kidding I am born on 2011, if u dont believe then I can send u my birth certificate
Very big respect what you've done is very impressive keep on learning and stay passionate
Thank u
Don't sweat it too much. The most important thing is that you're writing code and learning. Your age is an advantage, listen to multiple sources and form your own style and learn the ins and outs of each language you like. You'll do great!
Look mate, I was programming in C and assembly at your age and raw-dogging Win16 programming just a few short years later. A kid like you tackling Vulkan is no surprise to me. Enjoy that youthful energy while you've got it, and put it to use. Have fun.
Have you considered using Go instead of C? You're young and C is kinda for old farts now, I bet you would write killer GO code.
Yes please, with the VS code setup!
Using MacOs. And in dire need of a decent IDE setup to start my C/C++ journey.
I might also suggest XCode or CLion. I personally use CLion on Mac.
@@IamusTheFox CLion requires a subscription tho! 🥲
C is very nice in some ways, especially for interoperability between dynamically-linked libraries, and I also find that working with a pure C interface is often more user-friendly compared to C++. HOWEVER, I would definitely not recommend trying to implement the internals of your project in pure C. The C standard library is very bare bones and you will find yourself spending all your time reinventing the wheel instead of making progress on your actual project. There are no C alternatives to std::vector, string, list, map, unordered_map, set, etc. and the fact that C does not support templates means that if you want generic containers, they have to be written as preprocessor #defines. You could have just written it in C++ internally and created a pure C interface on top of it in the time it would take you to reinvent linked lists and destructors every time something needs them.
There are plenty of libraries written in C that provide the equivalent to standard C++ containers. Just because it's not in the standard library doesn't mean you have to write it yourself. I'll give you templates though, as using preprocessor macros and _Generic are more of a pain in the ass than templates are.
I think you should pick up a project that uses intermediate to aadvanced concepts in cpp and try to go about the code and explain it and go further to show alternatives and more.
You can add parts to it and that could go on Code review. Not to mention how much it would help the beginners like me.
Love your video's dude, Love how you almost get C red pilled looking and nice C code, almost! Also I definitely think the submission was by a programmer with 13 years experience not a 13 year old and that was lost in translation. Finally "Yeah, well, you know, that's just, like, you opinion man" The Dude 12:27
Loved this code review
I'd love to see how you set up C++ and/or C on VS Code.
Btw, I can't understand why C still doesn't have namespaces, is there anything wrong with them?
I'm quite a grey-beard, so I learned to program on something before C (BASIC and Pascal), and I still recall the brain breakage (e.g. the bewildering for loop syntax, pre- and post-increment/decrement, pointers, type syntax) that was learning C as a new language (prior to the ANSI standard). There is so much about C, and C++ that is just not conducive to the novice, and there are so many better languages available today, that I could not recommend that anybody learn C or C++ as their first language. Python is a better language for the novice: dynamic types, minimal syntax, lots of room to grow. Swift is a better language: the interactive tooling is top notch, the language is stricture than I would like for a novice, but the error messages are really good. Even Java and C# are better than C/C++, though I think they are not very well designed for novices because they are too slavish to C/C++ syntax.
I started programming as a minor subject at university in 1979 where we used AlgolW, PL360 and assembler before moving to Pascal. I learned C in my first job and used it until 1995 when I started with C++ which was overtaken by Python in 2000, with a smattering of Java after inheriting someone else's project.
Recently I failed to reverse engineer an HDF5 format results file using the Python h5py module and was forced to go back to the low level HDF5 API in C. What a revelation! Pro: you really have to think about data structures and memory packing. Con: you really have to think about data structures and memory packing. But it does make you appreciate ease of use of C++ std:vector, std::map, and iterators and the easier use of Python list and dict even though you can't get at the bare metal that C gives you.
I've been in the industry for 25 years!!!!! This 13 year olds C code is damn good! I'm very very impressed. Well done indeed.
with C you will shoot your foot off after you miss several times
with C++ makes it harder with the safety but when you do take off the safety you proceed to blow off your entire leg.
java well it gives you a water gun.
I feel you. C doubles up on the words.
C++ can be application.start()
while C is application_start(application)
Why do I have to write "application" twice 😢my lines are so long.
"app" then? XD
A C dev would never use a long name like "application_start". The longest you'd see would be "ap_s" most likely.
Or in c++, it could be application app{}; :D
I seen you after lot of .time still you are working on c and c++. Also my favorite especially c.
Would love to see a VSCode setup!
Good video and points made. Code looks pretty good to me as an experienced dev that's been also working on a hobby C engine.
C++ Setup for VS Code
I will wait for this video.
If possible, could you describe some bottlenecks associated with this setup?
Looks like a pretty good start for a newb!
I'd still like to see what you think about my C engine, but it's ok. 😉
11:55 Thank you for that take!
Unfortunately, Rusters and Zigooners didn't hear that :(
Hey, could you make a video talking C++ 20 modules? What we should/shouldn't use it. Which is preferred header and source files or modules?
I have started to write a game engine, but I am wondering if I should switch over to modules instead. Since it enhances building times and modularity of your source code.
VS Code video would be crazy
Please make a video of setting up VSCode for c++!
As much as I love C, I can't live without operator/function overloading.
Operator overloading is the only thing that is missing from C that would make it perfect, IMO.
@@CharlesVanNoland Worst thing about C is its tiny basic standard library. You have to implement the most basic data structures by yourself.
@@xCwieCHRISx But once you do you basically never have to again. C lets you build your own language on top of it that you can use for the rest of your life.
I feel envious of those who can code comfortably.
Also, a petition for The Cherno to release a C23 course for beginners and intermediate? Please.
considering the two most popular desktop operating systems still don't support C11 correctly, you might want to wait a while until you tackle on C23 (which is great, but absolutely not ready to be used yet)
@@atijohn8135 Guess I need to learn something else before I worry about C23 (or any programming language, for that matter). I don't even know what I am asking for and why. Thank you so much.
Meanwhile me back in my 13 y. o. playing Garrys Mod all day long 🤣
Gmod's addon "Wiremod" got me into programming though LUA/Expression 2.
what theme you're using?
Ya I’d watch a video about optimizing dev environment setup. Do a linter, static analysis, dev container maybe, intelisense for third party headers, idk what else
10:17
You just made thousands of C programmers cry in pain
You'd fit right in with the Fontconfig crowd though.
“By the time you’re an adult you’ll know everything.”
No, by the time you’re an adult, the officially blessed build system and IDE will have completely changed multiple times. Just learn the principles and keep up with current trends. Being an efficient lifelong learner is most of the job.
Yes please make that video for VS Code
YES. I need VS Code setup for C/C++