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.
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.
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
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 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
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 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.
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.
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 👍🏼
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".
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.)
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.
Same, avoided C++ for the longest time because of its reputation but now its honestly my favourite language to code in Only thing is that people give me funny looks when I tell them I'm a C++ prgrammer
C++ is in an interesting spot. While it is a high(er) level language, you can get very low level and do all the hardware specific things you might want to do.
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.
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 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.
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.
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.
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.
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++.
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 :/
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.
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.
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.
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! 😥
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 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.
What I like about the C style of coding is that with a function named like engine_initialize I can make a search for this exact function name and find only the one I need, you could argue that would be the same by putting Engine::Initialize to find the one implementation I'm looking for but that would require for me to look for the type of the object that calls the function, I cannot just select the function and launch a search.
There isn't a single editor worth using that does not implement the LSP or runs their own language server style thingy. You can just let the LS look for usages and find every single instance where a function is used.
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 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.
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'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 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.
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 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.
From my experience it's more common to typedef an anonymous struct. (ie "typedef struct {} prefix_type_t") or directly say "struct prefix_type" and simply omit doing a typedef. But then again, loads of people do different conventions no matter the language! Personally I would def add "_t" and omit the struct name, or at least captialize it! :) For libraries (your own or public) people tend to add their libraries name or the collection of libraries name as a prefix to structs and functions. Taking hazel as an example would give you something like "struct hazle_engine_t" or maybe shortening the "namespace"/prefix to "void hzl_engine_init()".
@@bitwize If your target against POSIX that is. The problem is of course that it could result collision, if you were to include a header that contains a typedef with the same name (i.e. definately don't name anything `size_t`) because chances are high that you are explicitly or implicitly (via. compiler) including a library that contains this definition, esp. if you target Linux, BSD or macOS.
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?
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.
21:42 - so where is the char array holding "CENGINE" allocated? The "window" struct points to the char array, which is instantiated in the initialize function. Where does the C compiler allocate it? I would have guessed on the local stack, but this would lead to problems accessing it later. EDIT: probably no problem because it is only used for the window initialization? But then, why is it part of the engine struct instead of a local variable in "engine_initialization"?
In the .data section of the executable, same with any other large literal. Basically read-only memory straight from the program. It doesn't go "out of scope" until the program is unloaded. In cpp the scope problem exists because std::string copies the literal into its own allocated heap memory, and if you return a pointer to that, the string will deallocate it before you can use it. So: const char* foo() { return "Hello"; } if fine, but const char* bar() { std::string ret = "Hello"; return ret.c_str(); } is not
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!
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
In C# we like to use static classes, there's no initializing anything and we don't have to worry about some object dangling around in the code. The only time a class gets used is if there's some specific pattern that makes sense.
That's called "abstracting the machine away", which means "giving up control over the machine", which culminates in "betraying your end-users because you wanted to use the easy language instead of the one that lets you make stuff as fast as it possibly could be".
@@CharlesVanNoland When you change a flat tire, do you lift the car up yourself, or do you use a jack? When you need to drive a nail into the wall, do you punch the nail? If you have a talk in front of a large group of people, do you use a microphone, or do you just yell really loudly? Keep in mind, you're not communicating directly with the CPU, you're dealing with the abstract state machine that is the C compiler. Maybe you shouldn't use C but use raw asm? Genuinely I think that is a bad take, and is at best unhelpful. If you're dealing with an OS, the level direct control over everything is basically simulated. "To make an apple pie from scratch, you must first create the universe"
@@IamusTheFox Clearly we have an /r/whooosh situation here. Maybe we should just build computers from scratch? Of course there is value in abstraction. I don't think your analogies with the car jack and hammer track though. My point was that we have TOO MUCH ABSTRACTION and HAND HOLDING which has RESULTED in a CRAPTASTIC DECLINE IN SOFTWARE QUALITY ACROSS THE BOARD. Hope that's not too much for your big brain to follow.
@CharlesVanNoland First, if I missed the joke, you seem very offended by it. Secondly, there is absolutely nothing wrong with abstraction. Abstraction is what c is for native assembly. Again, if all abstractions were bad, we wouldn't need c. If my analogy failed I'm sorry. I was attempting to convey the fact we do have tools, and to look down on tool use is silly at best, and dangerous at worst. I'm not trying to insult you, but I'm not sure you know what an abstraction actually is. Unless you are the 0.01% of programmers, you absolutely need every bit of support you can get both from tools and the language. The programmers who are in the 99.99% who believe that they are in the 0.01% are why the NSA and CIA suggest we abandon C++.
I've been debating if I should continue to write my game engine in C++ or use GO instead... some don't like the fact GO has a garbage collector, but I always thought humans were bad at managing memory anyways and a garbage collector on a compiled language is a no-brainer.
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.
“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.
I feel like I would heavily, heavily disagree with the statement that C "naturally" leads to more correct code. You yourself show some ways this is not true: You have to remember to free if you malloc for example, or the init/shutdown ceremony. There is no issue converting a -1 to uint32_t implicitly. There are so, so many footguns in this language, and at least C++ addresses some of them by making the equivalent thing (in newer versions, that is) much more simple to write, either through RAII alone, or in combination with smart pointers instead of raw ones. Yes, it does not disallow using malloc/free, but if you argue that makes C++ bad, then the very same critique applies to C where that's the _only_ way to use so it's _always_ the most precarious one, full stop.
2:45 Makefiles are simpler to deal with than cmake from my experience, have yet to ever get a cmake file to work but a makefile 9 times out of 10 works with just running the command "make"
@lunarjournal even in my own large projects makefiles are easier to work with. Just slap a makefile in every directory that says "include makefile of parent directory" with the final one launching make with specified build.mak or similar. From there you can do whatever you need in a consistent place :)
I have to disagree, I think modern cmake is objectively simpler than make. You can write a cmake file for small to medium sized programs in 3 lines. And you have the obvious benefit that it's cross platform. getting cmake to build your project isnt much harder than "make". you'd do: cmake -B build && cmake --build build
@@ldov6373 CMake also has the worst syntax I have ever come across. At least with make everything is run as a command, CMake can get complicated very quickly. Make is also cross platform as there are ports for Windows and MacOS..
C is definetly better for begginners than C++ & other langueges it may be hard but assure you once you understand it learning new things in proggraming becomes 10x faster.(sorry for my spelling english is not my native languege)
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.
C is not just one of the best languages to learn for a beginner, it is _the_ best language to learn for a beginner. There is no discussion about this, at all. Everybody who starts programming should first learn a bit of C, then switch to any language you want, doesn't matter.
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.
C I feel like is what really escalated my knowledge in programming. The language literally forces you to think about things a lot of people unfortunately disregard today. Not saying that everyone should switch to C as their goto language, btw. Some things in C are actually a pain in the ass to use.
Please, Sir, Roast us all by doing a video on setting up VSCode for C++, or rather setting up C++ in VSCode, whatever way that makes sense. BTW, the last video I watched of yours was some time ago (I've been busy burying a couple family member, no I didn't kill them) and you were still sick, you look much better now, hope your feeling better. In case anyone cares, I don't expect anyone to, I feel like crap... I did just bury a couple family members so I should feel like crap. You're free to take pity on me and maybe make a video setting up C++ in VSCode? That's all, too much really, good day!
C is such a SMALL and powerful language... Totally uncluttered by modern language concepts like Object Oriented Programming... So yes, I think it's appropriate for beginners! Just keep them the HELL away from Pointers! Until they FULLY understand how a double linked list works! I had my first encounter with the language as a module on my Astrophysics course at University when I was in my early 20s. Now I have C, C++, C#, Javascript, SQL et al under my belt 30 years later! But then, I did code in assembler on 8 and 16 bit machines as a kid 🤷♂️
@@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 would *definitely* use C as a teaching tool over C++, personally. Don't get me wrong, as much as I love C it's not a good language. Neither of them are. But the explicit nature of C allows the learner to see and physically play around with a lot of what's hidden by C++. Sure, when you're experienced you can make use of the constructor and destructor, rely on scoping rules and understand name overloading and namespacing. Many of the convenience features of C++ aren't intuitive, but could be taught in terms of "all that stuff you did manually in C that you now understand, the C++ compiler does for you," and *then* it's useful.
I've been taught C++ in high school, but we were taught the C part, not the whole oop part. Maybe we used it because it has the iostream and fstream instead of stdio.h and stdlib.h . It's a lot less of a headache to use the streams, but with stdio functions you can do more things
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.
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.
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
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 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
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 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.
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.
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 👍🏼
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.
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.)
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 learned to program in C... and then learned C++ thereafter... this in my opinion is the best way to learn programming
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.
Started writing in C++, and have no experience with low level languages. I actually enjoy it more than I did JS or Python
Same, i wasnt in as high as js or python ( i was in java ) and actually c++ was enjoyable
Same, avoided C++ for the longest time because of its reputation but now its honestly my favourite language to code in
Only thing is that people give me funny looks when I tell them I'm a C++ prgrammer
C++ is in an interesting spot. While it is a high(er) level language, you can get very low level and do all the hardware specific things you might want to do.
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.
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 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.
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.
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.
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.
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++.
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 :/
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 🔥
Hey man, great to meet you in real life at yowcon. My colleagues really enjoyed your presentation and learning about hazel.
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
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.
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!
Thumbs up for your explanation of the way cpp is tought in general and that it is not necessary.
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! 😥
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.
yeah, much needed video about configuring vscode for C++ support
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.
What I like about the C style of coding is that with a function named like engine_initialize I can make a search for this exact function name and find only the one I need, you could argue that would be the same by putting Engine::Initialize to find the one implementation I'm looking for but that would require for me to look for the type of the object that calls the function, I cannot just select the function and launch a search.
There isn't a single editor worth using that does not implement the LSP or runs their own language server style thingy. You can just let the LS look for usages and find every single instance where a function is used.
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.
Hey, I love C. What you say is code organization to me is a bit of overhead, or things that don't bother me at all. Quite elegant code.
Glad you differentiate C from C++ , so many think C++ is just suped up C.
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 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.
Enjoyed your discussion on c and c++ data and function organization
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'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.
Would definitely love a video on setting up VSCode for C++
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'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.
Liked this review so much. Hope to see more C stuff and comparisons with C++ with good technique.
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?
Would love to see a VS Code C++ setup video!
We had one semester of C and only then after OOP stuff, I'd say that's one of the best approaches.
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.
From my experience it's more common to typedef an anonymous struct. (ie "typedef struct {} prefix_type_t") or directly say "struct prefix_type" and simply omit doing a typedef. But then again, loads of people do different conventions no matter the language! Personally I would def add "_t" and omit the struct name, or at least captialize it! :)
For libraries (your own or public) people tend to add their libraries name or the collection of libraries name as a prefix to structs and functions. Taking hazel as an example would give you something like "struct hazle_engine_t" or maybe shortening the "namespace"/prefix to "void hzl_engine_init()".
Type names that end with _t are reserved by POSIX (but not C in general). I don't recommend you use that convention for your own types.
@@bitwize If your target against POSIX that is. The problem is of course that it could result collision, if you were to include a header that contains a typedef with the same name (i.e. definately don't name anything `size_t`) because chances are high that you are explicitly or implicitly (via. compiler) including a library that contains this definition, esp. if you target Linux, BSD or macOS.
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! 🥲
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?
A vscode c++ setup video would be really intestesting!
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.
A video about how to read code, using the debugger, would be great for learning best practices.
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.
21:42 - so where is the char array holding "CENGINE" allocated? The "window" struct points to the char array, which is instantiated in the initialize function. Where does the C compiler allocate it? I would have guessed on the local stack, but this would lead to problems accessing it later.
EDIT: probably no problem because it is only used for the window initialization? But then, why is it part of the engine struct instead of a local variable in "engine_initialization"?
you can google something like "where are C string literals stored". string literals live for the entire duration of the program.
In the .data section of the executable, same with any other large literal. Basically read-only memory straight from the program. It doesn't go "out of scope" until the program is unloaded. In cpp the scope problem exists because std::string copies the literal into its own allocated heap memory, and if you return a pointer to that, the string will deallocate it before you can use it.
So:
const char* foo() { return "Hello"; }
if fine, but
const char* bar() {
std::string ret = "Hello";
return ret.c_str();
}
is not
@parcellus ah thanks! Of course, it would treat it like a const Variable. Dummy me.
setting up vscode for c++ would be dope!!
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.
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!
Yes please !!! Do a video on VS Code setup for C++!!
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
Спасибо!
In C# we like to use static classes, there's no initializing anything and we don't have to worry about some object dangling around in the code. The only time a class gets used is if there's some specific pattern that makes sense.
That's called "abstracting the machine away", which means "giving up control over the machine", which culminates in "betraying your end-users because you wanted to use the easy language instead of the one that lets you make stuff as fast as it possibly could be".
Strictly speaking, globals in C++ are default initialized, so you don't have to do so with them in C++
@@CharlesVanNoland When you change a flat tire, do you lift the car up yourself, or do you use a jack? When you need to drive a nail into the wall, do you punch the nail? If you have a talk in front of a large group of people, do you use a microphone, or do you just yell really loudly?
Keep in mind, you're not communicating directly with the CPU, you're dealing with the abstract state machine that is the C compiler. Maybe you shouldn't use C but use raw asm?
Genuinely I think that is a bad take, and is at best unhelpful. If you're dealing with an OS, the level direct control over everything is basically simulated.
"To make an apple pie from scratch, you must first create the universe"
@@IamusTheFox Clearly we have an /r/whooosh situation here. Maybe we should just build computers from scratch?
Of course there is value in abstraction. I don't think your analogies with the car jack and hammer track though. My point was that we have TOO MUCH ABSTRACTION and HAND HOLDING which has RESULTED in a CRAPTASTIC DECLINE IN SOFTWARE QUALITY ACROSS THE BOARD.
Hope that's not too much for your big brain to follow.
@CharlesVanNoland First, if I missed the joke, you seem very offended by it.
Secondly, there is absolutely nothing wrong with abstraction. Abstraction is what c is for native assembly. Again, if all abstractions were bad, we wouldn't need c.
If my analogy failed I'm sorry. I was attempting to convey the fact we do have tools, and to look down on tool use is silly at best, and dangerous at worst.
I'm not trying to insult you, but I'm not sure you know what an abstraction actually is.
Unless you are the 0.01% of programmers, you absolutely need every bit of support you can get both from tools and the language. The programmers who are in the 99.99% who believe that they are in the 0.01% are why the NSA and CIA suggest we abandon C++.
I've been debating if I should continue to write my game engine in C++ or use GO instead... some don't like the fact GO has a garbage collector, but I always thought humans were bad at managing memory anyways and a garbage collector on a compiled language is a no-brainer.
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.
YES that would be greate a video about setting up VSCode for c++ , thanks
I'm very interesting in the video about setting up Vscode for C++!
“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.
10:17
You just made thousands of C programmers cry in pain
You'd fit right in with the Fontconfig crowd though.
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. 😉
I feel like I would heavily, heavily disagree with the statement that C "naturally" leads to more correct code. You yourself show some ways this is not true: You have to remember to free if you malloc for example, or the init/shutdown ceremony. There is no issue converting a -1 to uint32_t implicitly. There are so, so many footguns in this language, and at least C++ addresses some of them by making the equivalent thing (in newer versions, that is) much more simple to write, either through RAII alone, or in combination with smart pointers instead of raw ones. Yes, it does not disallow using malloc/free, but if you argue that makes C++ bad, then the very same critique applies to C where that's the _only_ way to use so it's _always_ the most precarious one, full stop.
Exactly, well said!
2:45 Makefiles are simpler to deal with than cmake from my experience, have yet to ever get a cmake file to work but a makefile 9 times out of 10 works with just running the command "make"
CMAKE is only really necessary for very large projects. Makefile is adequate for most things no need to overcomplicate the build system.
@lunarjournal even in my own large projects makefiles are easier to work with. Just slap a makefile in every directory that says "include makefile of parent directory" with the final one launching make with specified build.mak or similar. From there you can do whatever you need in a consistent place :)
I have to disagree, I think modern cmake is objectively simpler than make. You can write a cmake file for small to medium sized programs in 3 lines. And you have the obvious benefit that it's cross platform. getting cmake to build your project isnt much harder than "make". you'd do: cmake -B build && cmake --build build
@ldov6373 the fact that arguments are needed at all makes cmake LESS SIMPLE than make which requires no arguments whatsoever
@@ldov6373 CMake also has the worst syntax I have ever come across. At least with make everything is run as a command, CMake can get complicated very quickly. Make is also cross platform as there are ports for Windows and MacOS..
C is definetly better for begginners than C++ & other langueges it may be hard but assure you once you understand it learning new things in proggraming becomes 10x faster.(sorry for my spelling english is not my native languege)
C++ Setup for VS Code
I will wait for this video.
If possible, could you describe some bottlenecks associated with this setup?
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.
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 is not just one of the best languages to learn for a beginner, it is _the_ best language to learn for a beginner. There is no discussion about this, at all. Everybody who starts programming should first learn a bit of C, then switch to any language you want, doesn't matter.
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.
I always felt like VS Code setup for C++ is a must in your channel and I always missed it here.
C I feel like is what really escalated my knowledge in programming.
The language literally forces you to think about things a lot of people unfortunately disregard today.
Not saying that everyone should switch to C as their goto language, btw.
Some things in C are actually a pain in the ass to use.
Please, Sir, Roast us all by doing a video on setting up VSCode for C++, or rather setting up C++ in VSCode, whatever way that makes sense. BTW, the last video I watched of yours was some time ago (I've been busy burying a couple family member, no I didn't kill them) and you were still sick, you look much better now, hope your feeling better. In case anyone cares, I don't expect anyone to, I feel like crap... I did just bury a couple family members so I should feel like crap. You're free to take pity on me and maybe make a video setting up C++ in VSCode? That's all, too much really, good day!
C is such a SMALL and powerful language... Totally uncluttered by modern language concepts like Object Oriented Programming... So yes, I think it's appropriate for beginners! Just keep them the HELL away from Pointers! Until they FULLY understand how a double linked list works!
I had my first encounter with the language as a module on my Astrophysics course at University when I was in my early 20s.
Now I have C, C++, C#, Javascript, SQL et al under my belt 30 years later! But then, I did code in assembler on 8 and 16 bit machines as a kid 🤷♂️
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.
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.
I would *definitely* use C as a teaching tool over C++, personally. Don't get me wrong, as much as I love C it's not a good language. Neither of them are. But the explicit nature of C allows the learner to see and physically play around with a lot of what's hidden by C++. Sure, when you're experienced you can make use of the constructor and destructor, rely on scoping rules and understand name overloading and namespacing. Many of the convenience features of C++ aren't intuitive, but could be taught in terms of "all that stuff you did manually in C that you now understand, the C++ compiler does for you," and *then* it's useful.
Yes would love if you do a vs code cpp setup video
Could you share the theme that you are using on vs code.
Could you point me to your colorscheme you're using and would it be ok to port it to Neovim? Thank you
I've been taught C++ in high school, but we were taught the C part, not the whole oop part. Maybe we used it because it has the iostream and fstream instead of stdio.h and stdlib.h . It's a lot less of a headache to use the streams, but with stdio functions you can do more things
with printf you can crash your program :D
1:25 Yes, please.
Do a video on how to set up Vim + Ctags. That set up will work on very low end systems.
Please make a video of setting up VSCode for c++!
Thank you, Mr. Cherno!
So.. when can I sign up for Cherno University?
Where do I sign for the video about c++ on VsCode?