Is C BETTER than C++ for beginners? // Code Review

  Рет қаралды 89,916

The Cherno

The Cherno

Күн бұрын

Пікірлер: 740
@TheCherno
@TheCherno Ай бұрын
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.
@GenericInternetter
@GenericInternetter Ай бұрын
VSCode for C++?! YES PLEASE!!!
@AnimeGIFfy
@AnimeGIFfy Ай бұрын
if you strt with C and you'll like it, youll hate object oriented programming, so yes.
@purpasmart_4831
@purpasmart_4831 Ай бұрын
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.
@alexmiller3260
@alexmiller3260 Ай бұрын
after Rust experience I have a trigger on sentinel values and old days naming style with m_'s for struct or class members
@adrianordp
@adrianordp Ай бұрын
Yep. I think C is better for beginners than C++.
@NordicFrog
@NordicFrog Ай бұрын
"I like what I C" - The Cherno 30:00
@cameonn
@cameonn Ай бұрын
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.
@ArThur_hara
@ArThur_hara Ай бұрын
​@@cameonn you knew shell language? 🥲
@toddwasson3355
@toddwasson3355 Ай бұрын
Me programming at 13: 10 CLS 20 PRINT "HI MOM!"
@Bempus
@Bempus Ай бұрын
Having access to the internet/unlimited tutrials is a huge advantage though, not saying I wasn't a lazy pos 17 years ago! 🤣
@kermitdafrog8
@kermitdafrog8 Ай бұрын
30 GOTO 20
@vxcute0
@vxcute0 Ай бұрын
I mean vulkan didn't exist back then, so you are fine.
@cybernit3
@cybernit3 Ай бұрын
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.
@zlcoolboy
@zlcoolboy Ай бұрын
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.
@countchocula7985
@countchocula7985 Ай бұрын
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.
@mangodoor408
@mangodoor408 Ай бұрын
I was hoping someone would point this out 👍
@bies_moron4404
@bies_moron4404 Ай бұрын
The designated initializer has been available in c since 1999, it is more functional than in c++20
@daven9536
@daven9536 Ай бұрын
@@bies_moron4404 because it allows out of order initialization (hilarious how C++ is just objectively worse here)
@evildrkirby
@evildrkirby Ай бұрын
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.
@Manuel-fg1ol
@Manuel-fg1ol Ай бұрын
im sure a lot of us would absolutely love a video on VSCode C++ setup. please take it into consideration
@guilhermecorrea3604
@guilhermecorrea3604 Ай бұрын
yes please
@CoderShare
@CoderShare Ай бұрын
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.
@buycraft911miner2
@buycraft911miner2 Ай бұрын
​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
@ldov6373
@ldov6373 Ай бұрын
@@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.
@seankayll9017
@seankayll9017 Ай бұрын
+1
@digital_hoboz
@digital_hoboz Ай бұрын
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.
@DiamondWolfX
@DiamondWolfX Ай бұрын
Isn't that what professional code reviews are for?
@digital_hoboz
@digital_hoboz Ай бұрын
@@DiamondWolfX you can’t cover everything 100% of the time. Emergencies and time pressure will increase error rate.
@arjix8738
@arjix8738 Ай бұрын
​@@DiamondWolfXif only we did reviews at my company
@aresye
@aresye Ай бұрын
JavaScript: **slowly backs out of room**
@Diego-Garcia
@Diego-Garcia Ай бұрын
​@@DiamondWolfX Do they do code reviews at your company?
@Saturate0806
@Saturate0806 Ай бұрын
I love C for it's simplicity. I think it should be the first language people learn
@AssemblyWizard
@AssemblyWizard Ай бұрын
Sure but what about siplusplusmplicity?
@friedrichmyers
@friedrichmyers Ай бұрын
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.
@delicious_seabass
@delicious_seabass Ай бұрын
It's the only language people should learn. Everything else is a waste of time.
@tolkienfan1972
@tolkienfan1972 Ай бұрын
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
@Saturate0806
@Saturate0806 Ай бұрын
@@tolkienfan1972 Some parts of C is really fucked up I agree
@ivan_reshetnikov
@ivan_reshetnikov Ай бұрын
Hell yes, VScode for C++ is what we want.
@KayleighOwO
@KayleighOwO Ай бұрын
windows 11 settings icon
@ivan_reshetnikov
@ivan_reshetnikov Ай бұрын
@@KayleighOwO yes, I'm useless when it comes to changing settings, everyone uses the control panel instead of me :(
@Raspredval1337
@Raspredval1337 Ай бұрын
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.
@mr.fantasee
@mr.fantasee Ай бұрын
​@@ivan_reshetnikovlol i use the research bar 😂
@wowyomad
@wowyomad Ай бұрын
​@@Raspredval1337why not use msvc on windows?
@Barnardrab
@Barnardrab Ай бұрын
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.
@Soraphis91
@Soraphis91 Ай бұрын
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".
@sacredgeometry
@sacredgeometry Ай бұрын
Absolutely it is OOP. By literal definition.
@na50r24
@na50r24 16 күн бұрын
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.
@m4rt_
@m4rt_ Ай бұрын
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".
@hashtable3212
@hashtable3212 Ай бұрын
We typedef a struct to be able to use it like a type, without writing struct first
@anon_y_mousse
@anon_y_mousse Ай бұрын
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.
@TheEdmaster87
@TheEdmaster87 Ай бұрын
Been using c++ for embedded systems for years, still does the job pretty well
@hwstar9416
@hwstar9416 Ай бұрын
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.
@rvoisey
@rvoisey Ай бұрын
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.
@ProfShibe
@ProfShibe Ай бұрын
@@hwstar9416 you don't have to use it just because it's there. Just use the convenience features. Arrays are more performant anyways.
@MrHaggyy
@MrHaggyy Ай бұрын
@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.
@sdwone
@sdwone Ай бұрын
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 👍🏼
@giffiyt
@giffiyt Ай бұрын
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.
@JohnnyThund3r
@JohnnyThund3r Ай бұрын
GO compiles even faster then C!
@JohnnyThund3r
@JohnnyThund3r Ай бұрын
@@Pear64 Why? What didn't you like about GO? Particularly what makes C better? I find it ~mostly~ pretty easy to work with.
@healthystrongmuslim
@healthystrongmuslim Ай бұрын
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.)
@stone8684
@stone8684 Ай бұрын
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.
@vaolin1703
@vaolin1703 Ай бұрын
experienced devs don't spend much time coding anyway these days
@shavais33
@shavais33 Ай бұрын
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.
@F1nalspace
@F1nalspace Ай бұрын
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.
@LordHog
@LordHog Ай бұрын
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.
@alexmiller3260
@alexmiller3260 Ай бұрын
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
@-rya1146
@-rya1146 Ай бұрын
@@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.
@alexmiller3260
@alexmiller3260 Ай бұрын
@@-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
@alexmiller3260
@alexmiller3260 Ай бұрын
​@@-rya1146well, for some reason I can't see my recent reply to you, so, I hope you still can 🥲
@GonziHere
@GonziHere Ай бұрын
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.
@CobainSnake
@CobainSnake Ай бұрын
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.
@willemvdk4886
@willemvdk4886 Ай бұрын
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
@XeZrunner
@XeZrunner Ай бұрын
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.
@Arcane_Ayush
@Arcane_Ayush Ай бұрын
​@@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.
@fkk1002
@fkk1002 Ай бұрын
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.
@OneMeanDragon
@OneMeanDragon Ай бұрын
@@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.
@friedrichmyers
@friedrichmyers Ай бұрын
​@@Arcane_Ayush Same, brother. JEE has me fucked.
@pweddy1
@pweddy1 Ай бұрын
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.
@spacelem
@spacelem Ай бұрын
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.
@CrossbowBeta
@CrossbowBeta Ай бұрын
5:19 c++/cmake aficionado being stumped that a project compiles fast.
@-rya1146
@-rya1146 Ай бұрын
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.
@JaDanBar97
@JaDanBar97 Ай бұрын
I learned to program in C... and then learned C++ thereafter... this in my opinion is the best way to learn programming
@h3llloworld
@h3llloworld 15 күн бұрын
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.
@mjthebest7294
@mjthebest7294 Ай бұрын
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.
@user-sl6gn1ss8p
@user-sl6gn1ss8p Ай бұрын
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.
@mjthebest7294
@mjthebest7294 Ай бұрын
​@@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.
@glee21012
@glee21012 Ай бұрын
Glad you differentiate C from C++ , so many think C++ is just suped up C.
@keyojack2010
@keyojack2010 Ай бұрын
Hey man, great to meet you in real life at yowcon. My colleagues really enjoyed your presentation and learning about hazel.
@plescandenis8474
@plescandenis8474 Ай бұрын
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.
@j.ysr0
@j.ysr0 9 күн бұрын
what theme you're using?
@paulooliveiracastro
@paulooliveiracastro Ай бұрын
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.
@frankreich5018
@frankreich5018 Ай бұрын
Thumbs up for your explanation of the way cpp is tought in general and that it is not necessary.
@marekdorobczynski1727
@marekdorobczynski1727 Ай бұрын
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!
@shaheryarahmad5706
@shaheryarahmad5706 Ай бұрын
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 :/
@sandro5437
@sandro5437 Ай бұрын
yeah, much needed video about configuring vscode for C++ support
@xbmarx
@xbmarx Ай бұрын
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.
@heavymetalmixer91
@heavymetalmixer91 Ай бұрын
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?
@vcv6560
@vcv6560 Ай бұрын
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.
@the_clown
@the_clown 11 күн бұрын
01:30 yes please. Will definitely love that
@cd860viu
@cd860viu Ай бұрын
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..
@MrHaggyy
@MrHaggyy Ай бұрын
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.
@JavedAlam-ce4mu
@JavedAlam-ce4mu Ай бұрын
you can write all C in C++ so why not if you like the classes?
@cd860viu
@cd860viu Ай бұрын
@@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..
@SystemsDevel
@SystemsDevel Ай бұрын
Rock and Roll 🔥
@ADSharpeSr
@ADSharpeSr Ай бұрын
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.
@Adrian-ld4oz
@Adrian-ld4oz Ай бұрын
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.
@jamespong6588
@jamespong6588 Ай бұрын
Exactly, after decades of trying all the shiny fancy c++ I reverted back to c style c++ code, it's the best
@ryandodrill6904
@ryandodrill6904 Ай бұрын
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.
@ldov6373
@ldov6373 Ай бұрын
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.
@ryandodrill6904
@ryandodrill6904 Ай бұрын
@@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.
@IamusTheFox
@IamusTheFox Ай бұрын
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++.
@RebelGangTv-ge4if
@RebelGangTv-ge4if Ай бұрын
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?
@d1metron702
@d1metron702 Ай бұрын
Liked this review so much. Hope to see more C stuff and comparisons with C++ with good technique.
@godkingwashington
@godkingwashington Ай бұрын
Would definitely love a video on setting up VSCode for C++
@romanpolishchuk4517
@romanpolishchuk4517 Ай бұрын
10:35 names ending with _t are reserved in C and should be avoided
@cemgecgel4284
@cemgecgel4284 Ай бұрын
no, they are reserved in posix
@ashton7981
@ashton7981 Ай бұрын
Typedefs that end in `_t` are only reserved if they start with `int` or `uint`. So unless you're extending stdint.h, you're free to suffix your types with `_t`
@xCwieCHRISx
@xCwieCHRISx Ай бұрын
"typedef struct Foo_s { .. } Foo;" ist what I use.
@Chriva
@Chriva Ай бұрын
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)
@claeslundin5865
@claeslundin5865 25 күн бұрын
Would love to see a VS Code C++ setup video!
@CharlesCarter-j3p
@CharlesCarter-j3p 26 күн бұрын
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
@danielsharp2402
@danielsharp2402 Ай бұрын
We had one semester of C and only then after OOP stuff, I'd say that's one of the best approaches.
@leolaroca
@leolaroca Ай бұрын
A vscode c++ setup video would be really intestesting!
@ohwow2074
@ohwow2074 Ай бұрын
Next video: the guy says he's an infact just 3 weeks old, writing his own weather simulator 😐😐😐😐
@RoySATX
@RoySATX Ай бұрын
My neighbor's kid wrote an app before leaving the maternity ward. 🚼 It sucked 👎, but still rather impressive.
@silvermig
@silvermig Ай бұрын
A video about how to read code, using the debugger, would be great for learning best practices.
@Riacho_lol
@Riacho_lol Ай бұрын
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!
@thewalkingjuju
@thewalkingjuju Ай бұрын
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! 😥
@matsim0
@matsim0 Ай бұрын
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"?
@emilien.breton
@emilien.breton Ай бұрын
you can google something like "where are C string literals stored". string literals live for the entire duration of the program.
@parcellus
@parcellus Ай бұрын
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
@matsim0
@matsim0 Ай бұрын
@parcellus ah thanks! Of course, it would treat it like a const Variable. Dummy me.
@timstevens3361
@timstevens3361 Ай бұрын
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.
@mattgti86
@mattgti86 Ай бұрын
Enjoyed your discussion on c and c++ data and function organization
@oleksiistri8429
@oleksiistri8429 Ай бұрын
setting up vscode for c++ would be dope!!
@arrowsdev
@arrowsdev Ай бұрын
YES that would be greate a video about setting up VSCode for c++ , thanks
@RobinJohannesson
@RobinJohannesson Ай бұрын
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.
@TheRealJman87
@TheRealJman87 Ай бұрын
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.
@anon_y_mousse
@anon_y_mousse Ай бұрын
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.
@Ikogn
@Ikogn Ай бұрын
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.
@robinkuster1127
@robinkuster1127 Ай бұрын
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.
@en_hawk6928
@en_hawk6928 Ай бұрын
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.
@mardagit
@mardagit Ай бұрын
11:55 Thank you for that take! Unfortunately, Rusters and Zigooners didn't hear that :(
@DylanMatthewTurner
@DylanMatthewTurner Ай бұрын
10:26 The standard type naming would be to add the suffix "_t". It shouldnt be "engine" but "engine_t"
@phantom7333
@phantom7333 Ай бұрын
yeah he mentions it like 10 seconds later
@DylanMatthewTurner
@DylanMatthewTurner Ай бұрын
​​​@@phantom7333Not really. When he brings up engine_t he's talking about it from the idea of using something different from the "struct engine" part, which is not why. Even if you didnt include the first "engine," you would still do "typedef struct { .. } engine_t;" bc it's a style thing, not a necessary thing.
@forijlab
@forijlab Ай бұрын
C++ Setup for VS Code I will wait for this video. If possible, could you describe some bottlenecks associated with this setup?
@ИвелинъСтояновъ
@ИвелинъСтояновъ 26 күн бұрын
Could you share the theme that you are using on vs code.
@yoshmeme931
@yoshmeme931 Ай бұрын
I'm very interesting in the video about setting up Vscode for C++!
@xb_salami
@xb_salami Ай бұрын
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.
@MostafijulIslam-r3b
@MostafijulIslam-r3b Ай бұрын
Yes please, with the VS code setup! Using MacOs. And in dire need of a decent IDE setup to start my C/C++ journey.
@IamusTheFox
@IamusTheFox Ай бұрын
I might also suggest XCode or CLion. I personally use CLion on Mac.
@MostafijulIslam-r3b
@MostafijulIslam-r3b Ай бұрын
@@IamusTheFox CLion requires a subscription tho! 🥲
@rivershi8273
@rivershi8273 16 күн бұрын
really need a video for setting c++ in vscode for mac/linux/windows
@user-tw2kr6hg4r
@user-tw2kr6hg4r Ай бұрын
23:55 using memset to initialize structs to 0 is outdated. in modern c you would either write mystruct_type mystruct = {0}; or in c23/gnu extension mystruct_type mystruct = {};
@richtw
@richtw 25 күн бұрын
Or even better, use a designated initializer to explicitly initialize the members you want, while zero-initializing the rest.
@AbhinavChalla
@AbhinavChalla Ай бұрын
1:30 yes I would definitely love to learn how to setup c++ the cherno's way in vs code
@rm5960
@rm5960 Ай бұрын
Yes please !!! Do a video on VS Code setup for C++!!
@Test-iv4pm
@Test-iv4pm Ай бұрын
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.
@Neuroszima
@Neuroszima Ай бұрын
"app" then? XD
@maelstrom57
@maelstrom57 Ай бұрын
A C dev would never use a long name like "application_start". The longest you'd see would be "ap_s" most likely.
@IamusTheFox
@IamusTheFox Ай бұрын
Or in c++, it could be application app{}; :D
@kakalisaha9428
@kakalisaha9428 Ай бұрын
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
@oct_nate
@oct_nate Ай бұрын
Very big respect what you've done is very impressive keep on learning and stay passionate
@kakalisaha9428
@kakalisaha9428 Ай бұрын
Thank u
@rnts08
@rnts08 Ай бұрын
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!
@bitwize
@bitwize Ай бұрын
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.
@JohnnyThund3r
@JohnnyThund3r Ай бұрын
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.
@aloluk
@aloluk Ай бұрын
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.
@SansidarUploads
@SansidarUploads Ай бұрын
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.
@peacefulexistence_
@peacefulexistence_ Ай бұрын
10:17 You just made thousands of C programmers cry in pain You'd fit right in with the Fontconfig crowd though.
@DerrickChea
@DerrickChea Ай бұрын
Loved this code review
@SeishukuS12
@SeishukuS12 Ай бұрын
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. 😉
@jsdutky
@jsdutky Ай бұрын
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.
@JohnnyThund3r
@JohnnyThund3r Ай бұрын
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.
@SweLindN
@SweLindN Ай бұрын
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
@bitwize Ай бұрын
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.
@dealloc
@dealloc Ай бұрын
@@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.
@CristiNeagu
@CristiNeagu Ай бұрын
1:25 Yes, please.
@lucasgandara4175
@lucasgandara4175 Ай бұрын
Where do I sign for the video about c++ on VsCode?
@skeleton_craftGaming
@skeleton_craftGaming Ай бұрын
Yes objectively so, but neither is good for the truest of beginners [I recommend learning JavaScript first personally (specifically using something like p5, which is a library for artists to make procedural art ) 0:49 Is there a way to make raw GL calls that isn't an absolute mess? 1:04 yeah, that's a valid reason to not use Visual Studio on Windows or Mac I suppose... ...
@vsadrn
@vsadrn Ай бұрын
Could you point me to your colorscheme you're using and would it be ok to port it to Neovim? Thank you
@ZKachmer
@ZKachmer Ай бұрын
Thank you, Mr. Cherno!
@zxuiji
@zxuiji Ай бұрын
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
@lunarjournal Ай бұрын
CMAKE is only really necessary for very large projects. Makefile is adequate for most things no need to overcomplicate the build system.
@zxuiji
@zxuiji Ай бұрын
@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 :)
@ldov6373
@ldov6373 Ай бұрын
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
@zxuiji
@zxuiji Ай бұрын
@ldov6373 the fact that arguments are needed at all makes cmake LESS SIMPLE than make which requires no arguments whatsoever
@lunarjournal
@lunarjournal Ай бұрын
@@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..
@kopilkaiser8991
@kopilkaiser8991 Ай бұрын
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 😊
@michaelhaslow1876
@michaelhaslow1876 Ай бұрын
Please make a video of setting up VSCode for c++!
@carlriemann925
@carlriemann925 Ай бұрын
Make a tutorial series on C++ 23.
@AlexMG54
@AlexMG54 Ай бұрын
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.
@lennuard_6998
@lennuard_6998 29 күн бұрын
pls make a video were you show a vscode setup for c++
@sumgamelab
@sumgamelab Ай бұрын
So.. when can I sign up for Cherno University?
Ай бұрын
23:44 Why would you use memset? No need for that. Just assign it like this = {0}; and this will zero out all the members of a struct. This is modern C.
@jamesmnguyen
@jamesmnguyen Ай бұрын
As much as I love C, I can't live without operator/function overloading.
@CharlesVanNoland
@CharlesVanNoland Ай бұрын
Operator overloading is the only thing that is missing from C that would make it perfect, IMO.
@xCwieCHRISx
@xCwieCHRISx Ай бұрын
@@CharlesVanNoland Worst thing about C is its tiny basic standard library. You have to implement the most basic data structures by yourself.
@CharlesVanNoland
@CharlesVanNoland Ай бұрын
@@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.
@pttest2079
@pttest2079 Ай бұрын
yes please show how to setup vscode for c++ and can it support vcxproj files?
@PapaJoeRobertson
@PapaJoeRobertson Ай бұрын
Do a video on how to set up Vim + Ctags. That set up will work on very low end systems.
Is this a Great Example for Beginners? // Code Review
40:05
The Cherno
Рет қаралды 39 М.
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 163 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 850 М.
i dove down the 7z rabbit hole (it goes deep)
12:50
Low Level
Рет қаралды 588 М.
TETRIS CLONE! // Code Review
36:55
The Cherno
Рет қаралды 62 М.
I made it FASTER // Code Review
38:46
The Cherno
Рет қаралды 553 М.
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 185 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 199 М.
Why I Don't Like Singletons
29:05
The Cherno
Рет қаралды 99 М.
Why i think C++ is better than rust
32:48
ThePrimeTime
Рет қаралды 341 М.
The Problem With Procedural Generation
17:57
Acerola
Рет қаралды 306 М.
Weak Pointers in C++ (std::weak_ptr)
17:25
The Cherno
Рет қаралды 62 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН