Тёмный

How I program C 

Eskil Steenberg
Подписаться 17 тыс.
Просмотров 749 тыс.
50% 1

This is a talk I (@eskilsteenberg) gave in Seattle in October of 2016. I cover my way of programing C, the style and structure I use and some tips and tricks. Fair warning: There is a fair bit of Programming religion in this talk.
My projects can be found at www.quelsolaar.com
My source can be found at: www.gamepipelin...
On twitter i am: @eskilsteenberg // private
and: @quelsolaar // work.

Развлечения

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1,7 тыс.   
@henrykkaufman1488
@henrykkaufman1488 2 года назад
"In the beginning you always want the results. In the end all you want is control." These two lines more or less sum up my 10 years of programming experience.
@grimvian
@grimvian Год назад
With my experince - almost seven decades, I think that statement address everything in my life. Except regarding my wife, I still in the beginning. 🙂
@dancom6030
@dancom6030 Год назад
@@grimvian 70 years? Damn you must've met Dennis Ritchie himself lol. But joking aside that's awesome.
@grimvian
@grimvian Год назад
@@dancom6030 It's over 40 years ago, I got my first computer born with BBC Basic and inline assembler. One second to boot and no noise. So back then, I learned hexadecimal and 6502 assembler. I could even have met Dennis in the discotheque in the seventies and having beers together, but I did not know English either. :o)
@Hoofinite
@Hoofinite Год назад
@TozzaYT
@TozzaYT Год назад
what does he mean control
@randomrfkov
@randomrfkov 2 года назад
The video is nearing 6 years, yet one of the most profound video on C programming.
@draganjonceski2639
@draganjonceski2639 Год назад
When will C99 be old enough though lol
@potatofuryy
@potatofuryy 3 месяца назад
@@draganjonceski2639 Maybe when it’s 25 years old lol
@Pico_444
@Pico_444 4 года назад
The only thing better than C is HolyC
@badwolf8112
@badwolf8112 4 года назад
A statement of Divine Intellect.
@adirmazhir9159
@adirmazhir9159 4 года назад
True
@MrScarf-zm9ih
@MrScarf-zm9ih 4 года назад
Amen
@sorryvol
@sorryvol 4 года назад
RIP Terry A Davis
@runescapefreedownload
@runescapefreedownload 4 года назад
RIP
@Stillow
@Stillow 4 года назад
pretty dissapointing video, no indian accent
@purplep3466
@purplep3466 4 года назад
I WANNA SEE JOMBO 😭
@SimGunther
@SimGunther 4 года назад
If you squint your ears enough, you'll hear a vaguely Indian accent from his beautiful Swedish voice
@RagHelen
@RagHelen 4 года назад
A coding tutorial without honking cars in the background.
@azenkwed
@azenkwed 4 года назад
... and he used a good microphone. ... and there no loud generic techno music playing in the background. Very disappointing indeed.
@azenkwed
@azenkwed 4 года назад
@Sebastian Oleński He's being sarcastic.
@heapslip8274
@heapslip8274 4 года назад
Thank you for this. I wish there was more of this kind of content available, but nowadays it's full of "Learn X in 2 hours", "How to make a CLI tool in X", etc. This was something I watched closely and took notes.
@seabass6106
@seabass6106 4 года назад
This boosts my self esteem to program in a way that !not strictly uses design patterns, but the way you understand best! Thanks for sharing!
@its0xFUL
@its0xFUL 10 месяцев назад
Keep coming back to this video. Such a gem.
@a.b.c.d.e...
@a.b.c.d.e... Год назад
I would advise anyone to take this with a grain of salt. It's a good talk and there a lot of valid points made, but I suggest not to take everything he says as ground truth. There are millions of productive programmers in the languages this guy is effectively calling "inherently wrong". And many smart minds who have designed them. You have to find and use what works for you, not what works for someone else.
@grimvian
@grimvian Год назад
Content with very skilled competence. After 18 month of C++ and writing two relation databases and tons of training code, I realize, that C must be the future for me. I’m hoping Eskil is making more talks about C. It’s is gold and super interesting. The parts with structs, pointers and memory management is fantastic and explained very well!
@Seedwreck
@Seedwreck Месяц назад
You know its good when you enter the video and see controll
@MoveTrueRecords_
@MoveTrueRecords_ Год назад
Dude this is how teaching should be. I been really trying to innerstand the concept of what code is doing and why numbers are needed. Why why why. Thank you man ❤
@CaptainTechnicalityLP
@CaptainTechnicalityLP 8 месяцев назад
23:32 On this point, most IDEs or even text editors have a "match whole word" option when searching, which looks for word boundaries when searching. This removes the issue of searching "my_function" and getting "my_function_with_stuff" and also works for other types like variables.
@voicev8426
@voicev8426 2 года назад
1. About function overloading, I do actually prefer c++ here, as it has a way to specify the type, and be less cryptic about it. It's literals for when that is available or explicitly calling type constructors when not. There is an argument as this is not enforced and implicit type conversions may cause a bug, but when you need it, providing argument type with the arguments themselves, instead of in the function name will force you to change them once you want to edit the function call. As a benefit, you also get arguments types as part of function signature which helps a lot with naming, as while it is good to be explicit, and not have ambiguity, going too much in that direction will lead to code becoming white noise, and it's much harder to not make mistakes, or miss anything while reading. 2. I agree crashes are good, but to me it's obvious that compile time errors are strictly better. Love the video otherwise
@skipdrill373
@skipdrill373 2 года назад
That is true ++
@loucadufault6549
@loucadufault6549 Год назад
Agree. In general I think any language feature that forces typings from the syntax into the naming tokens (in this case method names) is a bad one. This usually devolves into having to maintain some kind of consistent notation to encode the type into the name in the interface (like Hungarian notation), and quickly becomes unruly. This is also a case where a compiler could easily warn that one of the arguments is being downcast or whatever in the given example
@okie9025
@okie9025 Месяц назад
After you said thing.Hello in "Java script" returns 0, I actually considered keeping track of how many inconsistencies or flat out wrong statements there were in this video, but then I realized that was just 15 minutes into the video.
@JA-in3hw
@JA-in3hw 2 года назад
I love this talk a lot. Watched it a year or two ago when I was starting out moving over to c from c++. Just re-watched it after actually getting into a c opengl project pretty good. Got a lot more out of it this time. I really agree with your philosophy and found myself doing a few of these "wrong". Gonna incorporate some of these tips. Cache friendly main loop is still eluding me. Thanks for all the sharing you do.
@catocall7323
@catocall7323 Год назад
I started with C and then went to Python. I actually felt uneasy with Python right away because it felt like I had no idea what was going on half the time and stuff was happening by magic. 😅
@tathtath
@tathtath 6 лет назад
Nice overview Eskil! I found that people who love C are people who know their hardware. I am one for sure :).
@nathanaelmoh5848
@nathanaelmoh5848 2 месяца назад
I have exactly about 5 weeks coding with C. I hadn't coded in 8 years. I don't have much education but about 25 minutes into your video and I do most of the things you have said are good. Made me feel really good even though I really struggled with pointers. I'm doing C Primer Plus by Stephen Prata page by page. After it I'm doing a book that's only about pointers in C. It has good reviews so I hope after that I'll be a more or less decent C programmer. Very nice video though I don't agree with everything but I do enjoy getting to hear the reasoning behind your decisions.
@Devdevbruh
@Devdevbruh 2 месяца назад
Don't get stuck in tutorial hell. Just code. Solve problems with C everyday. If you don't understand a concept well enough use ChatGPT and ask for exercises/projects using said concept and work through it. Only book I ever used was C Programming A Modern Approach 2nd Ed. Everything will just click eventually if you keep practicing. Also, google Aalto C MOOC and go through the content and try the exercises. University of Helsinki's MOOCs are amazing and offer certification as well. Got my Java I and Java II certs but I am by no means an expert.
@brucetungsten5714
@brucetungsten5714 4 года назад
Got back to your video after archiving it and I'm pretty pleased. Great work + love your approach!
@wlcrutch
@wlcrutch Год назад
Another thing I have picked up from this video: long functions. I have always been taught to “abstract away” and “encapsulate” things and then it becomes an easter egg hunt to find the function within the function within the function! Having however One loop like you suggest that simply does things based on conditions/state and is very clear about that and reads top down like a story book is Sooooo much easier to read when coming back to later. The problem though is that though I like it, other people don’t…
@Schnorzel1337
@Schnorzel1337 11 месяцев назад
I absolutely wholeheartely disagree to the biggest extend. The analogy of a story book reading from front to back is sorry to say stupid. If you have a problem with your electric utensils do you want a manual with chapters and subchapters or a block of 200 pages starting in chinese? Finding a bug is not a story, its a specific line. Imagen this scenario. You have a 2D Game with a gigantic draw loop of 1000 lines of code. Lets say the drawing of one particular scenario has a bug. Do you want to a) read through 1000 lines of code, skimming over it ofc, but still 500 lines average. or b) Follow down a tree of smaller and smaller boxes to zoom down to your scenario? Your IDE is happy to help. One you skim over 500 lines, where the other you read and think about 10 lines of function names. Not convinced? You still have 1000 lines of code and the bug is super hard to find. Have fun testing one function of 1000 lines of code. Imagen the stacktrace. Bug happened at line 643 of function x. Instead of: Bug happed at line 13 of function x, called by function y, called by function a called by function f. Which for my example would be something like: DrawDoomEyeMonster , DrawFlyingMonster, DrawEnemies, DrawGame, Draw Another point, if someone is a bad programmer the difference between the one line someone hid by accident, is either 20 or 999 lines away. Whoever says big functions are easier to read is lying or super bad at naming functions. --- However every rule has its exceptions. If there is no reasonable way to split code, dont. Make sure every function is free of side effects.
@fullmontis
@fullmontis 10 месяцев назад
​@@Schnorzel1337I disagree, strongly. A better example would be a malfunctioning drill that you need to repair. You open it up and troubleshoot the energy lines linearly from the power supply to the end tip. The simpler and the more straightforward the design of the drill, the easier to find where a broken trace or burned component may be. But if the drill has a bunch of smaller different units jumping off from each other it becomes increasingly difficult to see where the energy may flow and it becomes much more time consuming to find where the problem starts A procedural program is executed from start to end. A bug may start anywhere in that line and make itself manifest anywhere else beyond that point. Tracing that problem back is relatively easy of you have a straightforward block of code to step through. But if you have a backtrace of dozens of functions, tracking where it may start is much, much more time consuming. Especially for something like c, where silent but killer pointer bugs are everywhere I recommend checking out an article by John Carmack on inlined code (you can google it), he is a lot more terse in explaining why it's a good idea
@Grynjolf
@Grynjolf 4 года назад
In the javascript example, it wouldn't define "Hello" nor would it be "0". It would be the value "undefined".
@Grynjolf
@Grynjolf 4 года назад
@Adam ISRx I'm not sure what you mean. You can print out both undefined and null fine.
@Grynjolf
@Grynjolf 4 года назад
@Adam ISRx I'm not sure what kind of Javascript you're using, but you can 100% print out null. `console.log(null);` does NOT error.
@20dareason09
@20dareason09 2 года назад
"Build a mountain!" This resonates with me. Thanks for creating this video!
@monad_tcp
@monad_tcp Год назад
You can't have control, the purpose of a programming language is to abstract the machine, otherwise you would write machine code directly. You are giving up control. The real question is how much. I don't want control, I want abstraction power, I'm more of a top-down designer coming from mathematics side of things. The machine does the computation for me, not the other way around.
@skejeton
@skejeton 2 года назад
2:08:20 this opened my eyes... this is the most clever thing i've seen in my life
@paulofonseca7664
@paulofonseca7664 3 года назад
Very nice talk, filled with valuable advice. Thanks for taking the time.
@NikoKauppi
@NikoKauppi 7 лет назад
I think I still prefer C++ although you make some good points that I agree with. C++ tends to make things overcomplicated sometimes, a bit more verbal and somewhat cryptic but then again the thinking is different. I have a feeling that C programmers spend less time creating the structure of the program and more time debugging the program while C++ is more like taking care that you have a good structure and that you wouldn't have to debug your program much later. Some weak points that you mentioned about C++ are some of the things I fell into when I was learning it the first time but it's been pretty smooth sailing after that. I don't deal with memory leaks nowadays anymore and generally I don't really spend any time debugging my applications nowadays other than threading race conditions and things like that. Also I do dare to say that in practice C++ programs are not any slower than C programs. I think we can agree that it's mostly about preference of which one you prefer but I don't understand why you wouldn't want to write C code and let the C++ compiler handle it for you? I don't see a reason why you would want to stick to plain C while mixing it with C++ you could still program like in C but with added features like namespaces and even better C++11 constexpr, nullptr and std::swap() function. Keeping it pure C is just shooting yourself in the foot. If you're feeling adventurous a little you could try returning std::vector from a function instead of handling arrays / pointers. C++11 makes returning a temporary std::vector fast btw. And you could do all this while still keeping the functional programming style in your programs. I am genuinely curious why you would limit yourself to just plain C as you can mix all the new C++ stuff to your C style code just fine. Not that you have to reply to me but I don't accept "just evil" as an answer without some serious proof of it. You could use vector class from stl to simplify your coding and making it more sturdy, it's not like you have to start coding classes yourself. Vector class is also really simple to understand, there's nothing mystical about it, it will behave exactly the same way every time.
@pekkak.1411
@pekkak.1411 7 лет назад
"C while mixing it with C++ you could still program like in C but with added features.. " Yes I agree. If I was doing C I would add the best features of C++ so its still almost C but just some benefits from C++. Nobody says you have to do OOP if you use C++. Its just optional.
@Bozemoto
@Bozemoto 7 лет назад
I think there's a saying that "somewhere inside c++ there's a great language". Think that only using a subset of the features is correct c++, different use cases needing different subsets.
@Bobster536
@Bobster536 9 месяцев назад
Currently working in unity, but i feel whatever you have to say will be worth for me to take notes off. 20 minutes into video so far and youre very well spoken especially since a noobie like me can get your point
@matthiasschuster9505
@matthiasschuster9505 4 года назад
Good video that skips HM type systems and how they overcome half of these issues while providing a good chunk of other improvements
@noxagonal
@noxagonal Месяц назад
You do have some valid points, C is definitely easier to read at a glance, and get familiar with. I guess my primary problem with this is that you say conventions are unclear and need to be studied, like vector multiplications, and then define your own conventions like typedefs being upper case, functions lower case. In the end they're also just conventions. Function documentation should be written into the source code of course. The second problem I have is that you don't seem to fully realize what's possible in other languages. Like, I think having addf(4, 0.3f) is just bad practice overall, eg. In C++ you can prevent this with compile time error if you wish, and force the user to explicitly convert types into the same type first, yes the function is going to be harder to read, but there won't be dublicate functions, and I'd argue that if you needed to look inside a function to figure out what it does, it's not named properly or its documentation is lacking. Just some thoughts.
@Kobold666
@Kobold666 Год назад
I almost agree with everything in this video, except for the typedef void Something; Void pointers can be assigned without a cast, so you lose type checking completely here. You could pass any pointer and the compiler won't notice the error. I prefer a forward definition like typedef struct Something Something; You get type checking and still can't access the struct if it isn't defined in public header files.
@kynos6219
@kynos6219 Год назад
1:06:49 one of my favorite cursed, weird c things is that 2[arr] == arr[2]
@eskilsteenberg
@eskilsteenberg Год назад
I know. I know why it is like that but still... why?
@badwolf8112
@badwolf8112 4 года назад
every programmer should know about memory segments. and if you know about memory segments, you can't "be fooled into thinking" an object is "a thing with data and code". OOP is about (good) abstractions. thing.do_something() is more natural because it corresponds to how we perceive the real world. the naming system you have going on is solid, but if it's also redundant when compared to well-defined abstractions.
@thinksie
@thinksie 11 месяцев назад
The best ever sum up of good programming and C omg
@kitastro
@kitastro Год назад
I appreciate you sharing your philosophy and methods, even if I don't aggree with everything I enjoyed seeing a different perspective.
@eskilsteenberg
@eskilsteenberg Год назад
Thats the intended way to watch the video!
@montenegro3167
@montenegro3167 4 года назад
I love your religious beliefs. it sure makes life easy for the most part when programming in C.
@Zero_Contradictions
@Zero_Contradictions Год назад
These are philosophical beliefs, not religious ones. Philosophy is shaped by reason, whereas faith is not.
@MichaelPohoreski
@MichaelPohoreski Год назад
22:37 putting a space after the function name but before the parentheses *has two use cases:* 1. When you _define_ your function it makes it trivial to find the definition in a plain text editor. (IDEs used to be slow and bloated and this was a “trick” to help navigate your codebase without the crutch of an IDE.) 2. Multi column vertical alignment can, in specific instances, help with readability when all the parentheses are aligned vertically.
@eskilsteenberg
@eskilsteenberg Год назад
So is the idea to use space everywhere, except where the fundtion is defined so that you can search for funaction_name( to find the definition only? Interesting idea.
@MichaelPohoreski
@MichaelPohoreski Год назад
@@eskilsteenberg I actually do the reverse. :-) (Almost) all function calls have *foo();* but where foo is defined it will be *foo ()* { ... }. (I also use Allman style; just compressing it on one line for the YT comment.) I've been using this trick in AppleWin's debugger source code for almost 20 years where I first experimented with it. In that codebase I actually used it in both the declarations in the .h files and in the definitions in the .cpp files but I've found it is OK to leave it only for the definitions in the .cpp implementation.
@nullplan01
@nullplan01 2 года назад
24:58 "This is legal C" no it isn't. The lexer must always necessarily consume as many characters as possible to form a token, so the string of plusses is tokenized to two increment operators and a plus, but the second increment operator is not applied to an lvalue, and therefore the compiler errors out on a constraint failure.
@eskilsteenberg
@eskilsteenberg 2 года назад
Thanks! I don't know that!
@chadkroger9183
@chadkroger9183 3 года назад
I'd really love to see more about how your memory debugging system works, that's actually pretty cool.
@eskilsteenberg
@eskilsteenberg 3 года назад
You can check out the code docs here: gamepipeline.org/forge_Debugging_.html The source is also downloadable from there. I'm thinking about maybe making a video just about debugging as I dont find there are a very good resources on debugging.
@chadkroger9183
@chadkroger9183 3 года назад
@@eskilsteenberg You really should, there are so much bad takes and advice out there. Thanks so much for the quick response too I really appreciate it
@r.f.mineguy7715
@r.f.mineguy7715 Год назад
That point at 31 minutes makes no sense to me. Wouldn't you want to be able to read your code flow without having to worry about scrolling through it and potentially getting lost in it? Like forgetting about some state that you set 300 lines earlier that matters later in the code?
@lamegunner
@lamegunner 4 года назад
As I'm writing this, there are already 255 comments, so... First post! (also, great video)
@tobiasbergkvist4520
@tobiasbergkvist4520 4 года назад
Zeroth post**
@W1ngSMC
@W1ngSMC 4 года назад
My only problem with C is namespacing. It is way more convenient when an IDE shows only the relevant functions for a struct/class.
@Bomag
@Bomag 3 месяца назад
A lot of the opinions in this video remind me of Andrew Kelly and his reasoning behind the zig language. Even things like making the language easy to parse. I wish more people would write code like this.
@tenix6698
@tenix6698 Год назад
1:08:25 They are actually NOT equivalent, because the second implementation changes the value of p, the first implementation doesn't.
@Leon-yi3of
@Leon-yi3of 4 года назад
I started learning C a week ago or so, and this video is kind of a god sent. I feel like C is super interesting.
@ME0WMERE
@ME0WMERE Год назад
Bit off-topic, but I'm genuinely curious: are you dyslexic?
@eskilsteenberg
@eskilsteenberg Год назад
Yes I am!
@nangld
@nangld 2 года назад
12:30 in GLSL/Intel/Clang/GCC vector extensions it means pairwise multiplication. So sqrt(sum(v*v)) would be the vector's length. Pairwise multiplication makes more sense, since it is just an extension of 1d multiplication to higher dimensions. Lets hope this definition sticks, and further C versions will support it out of the box.
@lionbryce10101
@lionbryce10101 Год назад
I love the video explaining the inverse sqrt algorithm relates to the structure of a float
@mbartelsm
@mbartelsm 2 года назад
Regarding your object orientation section, it doesn't really make much sense. You claim that OO languages fool you into thinking that programs can have both instructions and data when that isn't the case because in computers instructions are protected... but in OO you also cannot modify instructions, it comes off as trashing on OO simply because you are unwilling to depart from a purely imperative way of thinking. Nevermind that the idea of code reflecting the way computers behave is a false dream to begin with. Nowadays even assembly is too high level if that's your rationale.
@superclue
@superclue 3 года назад
Thanks, very helpful! For your perusal at 1:46:00 you give a tip on how to allocate contiguously an array within a struct. There is another way to do it which I have seen in a presentation by Prof. Kernighan: malloc(offsetof(array, data) + sizeof(uint8)*length) . In that case the same technique is used for allocation, but the offsetof macro is implemented.
@eskilsteenberg
@eskilsteenberg 3 года назад
Yes, you can do it that way too! offsetof is a macro that was added in C99. I tend to avoid using macros, especially macros that looks like functions but take types as arguments. The clarity of using straight C is valuable, especially in a video where you try to make clear, how pointers and memory really work. Neither is wrong, its a matter of taste.
@AriKath
@AriKath Год назад
I love your coding philosiphy. Thank you, I am grateful
@anthonydotmoe
@anthonydotmoe 4 года назад
I like the way you think!
@zacharystreeter1965
@zacharystreeter1965 Месяц назад
John Carmack didn't come up with the fast inverse square root algorithm - you can see the history on the wiki. IIRC, the cool thing was that constant is from a paper that tabulated great initial guesses for newton iterations so it only needs to do one iterations before converging
@glenneric1
@glenneric1 2 года назад
You will need to turn every volume knob up to hear this.
@BrandonDyer64
@BrandonDyer64 4 года назад
How do you feel about Rust? It seems to be a language designed around the same ideas you're presenting. In the four years since you've posted this, the language seems to have become extremely robust, while remaining simple.
@happygimp0
@happygimp0 4 года назад
But why does Rust use { and } ? A python syntax would be better. The rest can be the same.
@BrandonDyer64
@BrandonDyer64 4 года назад
@@happygimp0 So does C. The question I asked was for a C programmer and had nothing to do with Python. Rust uses curly braces because the language is extremely expressive. Something that becomes obtuse and hard to read with a Pythonic syntax. It was a design choice, not an accident. There's also a lot more to a language than just whether or not it uses braces.
@someghosts
@someghosts Год назад
Would love to hear an answer to this too as someone forming their opinions on the two languages
@salardelavarqashqai
@salardelavarqashqai 28 дней назад
Awesome teaching ❤️ 👏
@runescapefreedownload
@runescapefreedownload 4 года назад
I'm a bit late to the party, but thank you for this video! I hope you start creating content again. :)
@mmddyyyy-his
@mmddyyyy-his 3 года назад
I have a higher level language background and now try to learn c , but for just hobby, because no company i work use c, i just want to learn deeper about CS.
@serebbi
@serebbi 2 года назад
There are so many topics in C . Just finished with cryptography and now doing sockets and threads
@zactron1997
@zactron1997 Год назад
You should be very proud of your skills in C and a very well made video! I do have to say that since using Rust, I think that is the direction programming needs to head towards, and mostly for the very reasons you like C. Compiler errors are absolutely your friend, and Rust out of the box gives possible the best error messages I've ever seen. Not just a file, line number, and context, but even the exact characters that potentially caused the issue. Unambiguous code is the best code, but verbose code can obfuscate intent. Rust infers intent from the programmer, but only at compile time, and only when it is entirely unambiguous. The directory structure you've added to your function names to ensure readability? Replace those underscores with double colons and you're at Rust's module and implementation system. Data being separate from code? Absolutely. Even operator overloading is forbidden in Rust. If you want to redefine how comparison operators work on an abstract structure, you define how comparison works explicitly, not how ,>=,
@chair547
@chair547 Год назад
rust has operator overloading in the form of impl std::ops::Add
@zactron1997
@zactron1997 Год назад
@@chair547 Again, only through consistent definitions. You can't define + and += to do different things. So your types get very explicit definitions of what addition, comparison, multiplication, etc. mean.
@chair547
@chair547 Год назад
@@zactron1997 this doesnt solve the problem of even though Mul on vectors is obviously the dot product, some people think it means pairwise multiplication
@zactron1997
@zactron1997 Год назад
@@chair547 True. I will concede it does not solve that problem. The way I've seen this tackled in Rust API's (nalgebra for example) is they do not define multiplication, and instead rely on structure methods for "dot" and "mul".
@alexisandersen1392
@alexisandersen1392 4 года назад
44:15 ... ... bro.... what? Macros have a whiff of C++ in them... ... you're daffed. Also I like how you go on to say that debuggers can't debug macro prossessed code for shit, and but with the __Line__ macro, you can accomplish GLORIOUS DEBUGGING XD. You make mess of macros, and you call it "beautiful code" ... right after you said you don't like macros you don't use them, they have a whiff of C++. You criticize the fuck out of C++ and then you talk about being careful of memory management pitfalls like leaking memory.... Mate, MATE.... do you not realize what the whole point of smart pointers is? We don't bother to manually specify memory management, we avoid that whole foot gun... by hand off responsibility through levels of abstraction... the problem with C++ is that it's socially obligated to maintain a level of backward compatibility to the antiquity of C99.... that's the problem with C++, it's the whiff of C in it! You fuck'n... aauuugh! AAUGH! So you fix the debugger by padding all your data with commentary.... so you can look at the memory and find out what is what.... yeah.... you know what else does that.... static analyzer information and modern runtime debug tools. You know... all the development of the programming workflow that took place over the last quarter century, you freak'n CAVEMAN. I love how at one point you're like "now this is actually a macro not a function, even though it looks like one, see hold on... let me find my debug file... where did I put it...." and then you find it in an include processor directive at the BOTTOM OF THE FILE And it's revealed that you're macros collide with your function names, and you're so proud of this messy cruft... Your "beautiful code" is a dumpster fire, mate. The description goes "Fair Warning: There is a fair bit of Programming religion in this talk." Yeah man, I love how many people are drawing the parallel with Terry Davis, because you are SO far down that path already.... Eskil, friend, heed the lessons of the past, man. Sheesh
@samhsmith
@samhsmith 4 года назад
Hahaha, main memory is 50 cycles. That has aged really badly, should be like 500-1000.
@thought2007
@thought2007 6 лет назад
1:08:06 - Your pointer example is not valid because it is a void pointer. Even if you correct it, it will not be any faster than the index versions. Every compiler can optimize the plain version.
@jannesnagel6995
@jannesnagel6995 Год назад
Isnt the array of bytes example at 1:47:00 technically buggy since the structure will get 3 byte padded at the end and these bytes will be used as part of the array? It still works but the mental model you are presenting is actually slightly incorrect. I think in your latest UB video you are also warning about that (Awesome video by the way - thank you!)
@creamyhorror
@creamyhorror Год назад
Wait, the LOVE guy?! Blast from the past, damn
@jimbob7281
@jimbob7281 Год назад
Thank you so much for this excellent video!!! (from a cs50 noob) A video dedicated to architecture design would be amazing!
@kuklama0706
@kuklama0706 Год назад
>fix it now, it won't be easier in the future No, it will be. If you're actively coding and learning newbie, tomorrow you'll understand it more, maybe your brain will even tip you some useful decisions after sleeping with it.
@mrpropano5325
@mrpropano5325 4 года назад
Great video, I learnt a lot. Do you have any recommendations on books or resources about the topics you cover in the video? Especially about the memory one.
@eskilsteenberg
@eskilsteenberg 4 года назад
Not really, that's why I made the video. I'm currently reading "What every programmer should know about memory". Its very dense and deep but very good.
@ekrem_dincel
@ekrem_dincel 3 года назад
@@eskilsteenberg thanks for the book!
@Inkarnid
@Inkarnid 11 месяцев назад
So you’re telling me you declare your for loop variable outside of the for loop? That is probably the main thing that would bother me about using C89 lol
@stephenkamenar
@stephenkamenar 3 года назад
"people don't want to type" it's not that i don't want to type, i don't want to read. verbose code is more to read
@sebvv5219
@sebvv5219 Год назад
"You want errors" Not surprised to hear that from someone who writes in C89. :p
@KANJICODER
@KANJICODER 2 года назад
I don't like "wide" code. But I like explicit. Public : A3F_SOME_FUNCTION A3T_SOME_TYPE A3D_SOME_DATA A3M_SOME_MACRO Private : ( on the honors system , basically not part of the public API , don't fuck with it unless you are fixing the library it belongs to. ) a3f_some_function a3t_some_type a3d_some_data a3m_some_macro
@jrstf
@jrstf 4 года назад
At 38:40, object orientation. Because code and data are stored in different memory segments you say computers really aren't object oriented. Yet you use functions with local variables. As an OOP fan, all I ask is that I be given an option to allocate variables from the heap rather than the stack. Isn't that the primary addition that objects provide? That particular argument against OOP is also an argument against local variables in functions.
@eskilsteenberg
@eskilsteenberg 4 года назад
Code and data are stored in different memory, even if you use a object oriented language. You can have C objects either in Stack or Heap Memory.
@wlcrutch
@wlcrutch Год назад
coming back to this after getting my ass kicked by a few hobby projects in C 😂
@jiayu5988
@jiayu5988 2 года назад
0:00 intro 5:00 garbage collection is not suitable for high performance scenarios 6:20 prefer stable & concise language features & technology stack 8:25 avoid ambiguity 11:00 don't be "clever" 11:45 be explicit 14:40 static-type language can catch more errors 16:00 early crashes are better than hidden bugs 17:30 improve your developing tools 20:20 general naming convention & coding style 27:20 prefer imperative & sequential code, long functions are OK 31:40 function naming 35:20 API design 36:00 how to organize .h & .c files 38:40 C & OOP-style APIs 41:00 void pointer is your friend to hide internal data 44:18 macros: __FILE__, __LINE__ 49:40 a custom allocator for memory debugging 53:10 macro utilities for binary data packing/unpacking 57:10 memory control & pointers 1:03:00 malloc 1:06:00 arrays 1:09:20 struct 1:11:15 inheritance via C pointer casting 1:16:35 struct packing, padding, memory alignment 1:22:55 memory pages, realloc, gflags.exe 1:33:42 memory caches 1:42:30 don't store data twice 1:45:25 trick to reduce allocations: Flexible Array Member 1:48:30 trick to reduce allocations: joint malloc (dangerous) 1:50:48 use "stride" for better handling of Array Of Struct (AOS) 1:53:15 architecture on top of small & flexible primitives 1:55:45 prefer incremental progress 2:00:00 fix code ASAP 2:01:55 UI application design 2:08:50 Carmack's fast square root algorithm 2:09:56 magical random number generator 2:10:30 closing, contacts
@rutabega306
@rutabega306 Год назад
Nit: fast sqrt isn't Carmack's. From Wikipedia: > The algorithm was often misattributed to John Carmack, but in fact the code is based on an unpublished paper by William Kahan and K.C. Ng circulated in May 1986. The original constant was produced from a collaboration between Cleve Moler and Gregory Walsh, while they worked for Ardent Computing in the late 1980s.
@montyoso
@montyoso Год назад
I added this list of chapters to SponsorBlock so the users of that extension can see them on the timeline.
@eyadsy6208
@eyadsy6208 Год назад
Thx
@Kitejrpaladin
@Kitejrpaladin Год назад
He has a point about 5:00, the biggest optimization you tend to do in GC languages aside from improving the algorithm is minimizing allocations to reduce garbage. Languages like C#, Java, and Go are massively improving their performance stories. I can really only speak on C# as I’ve been following the changes. Access to CPU instrinsics, stackalloc, no copy slicing, Ahead of time compilation, These languages have gotten much better in that area, they can definitely reach really high throughput, where the GC can trip you up is in latency sensitive scenarios. Also runtime reflection.. it’s used a bit too willingly by libraries. I think these days if I really wanted to write in a systems language like C, with a batteries included Stdlib, and explicit control over memory I’d probably use something like Zig. Keep the core language simple, use type inference, treat types as first class so the language should have the ability to modify types and run expressions at compile time. Pretty much don’t use macros let type system be expressive enough to do what macros do so everything is type safe.
@cuongtrinh714
@cuongtrinh714 Год назад
> 1:11:15 inheritance via C pointer casting Personally, I think this is Polymorphism concept in OOP instead, fix me I'm wrong.
@potatoxel7800
@potatoxel7800 4 года назад
Wow. this guy doesnt even use powerpoint. he uses C for slides :D.
@bjarnestronstrup9122
@bjarnestronstrup9122 4 года назад
Disappointment he uses Visual Studio
@sharishth
@sharishth 4 года назад
@@bjarnestronstrup9122 lol you expected vim?
@bjarnestronstrup9122
@bjarnestronstrup9122 4 года назад
@@sharishth Vim is great , Emacs is also acceptable . IDE's are overrated bunch of bloat.
@sharishth
@sharishth 4 года назад
@@bjarnestronstrup9122 nano is love nano is life
@bjarnestronstrup9122
@bjarnestronstrup9122 4 года назад
@@sharishth Yes nano is alright, but once you get used to vim keybinds everything else seem like torture :).
@billowen3285
@billowen3285 3 года назад
I've been trying to learn C++ and have realised that C is actually the place for me
@danflurry
@danflurry 2 года назад
“Fuck macros!” *proceeds to discuss benefits of macros for ten minutes*
@Ganerrr
@Ganerrr Год назад
First half is just "language X does Y which sounds really nice until Z" except you basically never experience Z and Y is absolutely amazing and makes you code faster
@eskilsteenberg
@eskilsteenberg Год назад
People keep telling me you all these features to be effective. So why do people who don't use them keep running circles around the people who do?
@Ganerrr
@Ganerrr Год назад
​@@eskilsteenberg en.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites C is 5%, you think they'd catch on? Not to mention the percent of high severity security bugs related to memory problems
@konnosgar
@konnosgar 11 месяцев назад
@@GanerrrThe web is the jungle my friend. Full of wild animals
@koktszfung
@koktszfung 4 года назад
"Typing is not a problem" proceed to make lots of typo LOL but I agree, that's why we have an editor
@potatoxel7800
@potatoxel7800 4 года назад
yeah, along with refactoring tools to rename things. ;D
@Tasty_sand
@Tasty_sand 4 года назад
I think he deliberately made the typos so other people who steals the video to present to others will look dumb.
@TheExiledMeriler
@TheExiledMeriler 4 года назад
"Typing is not a problem" But reading what you typed is. You need to read this multiple times and that takes your time. And the more time you spend on reading abd understanding the more time you lose on other tasks. We kinfa don't have 3 years to write server for our project, cause during that time it would be outdated enough.
@matthiasschuster9505
@matthiasschuster9505 4 года назад
@@TheExiledMeriler See the guys homepage. I think this is some form of learning disorder or so. As you hear, can he speak just fine, so it'ss not about his native origin or so. I know for a fact, that there are disabilities who prevent consistent and correct spelling. That does not impact your ability as programmer, obviously
@94Quang
@94Quang 3 года назад
I think he mentioned that he is dyslexic. So I think we should give him a break :).
@mannycalavera121
@mannycalavera121 4 года назад
As a beginner I can't explain how much I appreciate this video. Clear, concise and simplified without sacrificing content. I started with python and am struggling with picking up C. Learning syntax is one thing, learning HOW to apply it is another
@daemonzap1481
@daemonzap1481 2 года назад
I am a college student and C is my first language and now I am learning Python and it feels wrong not putting brackets or semicolons everywhere lol
@LazizbekYusupov92
@LazizbekYusupov92 Год назад
You hit the point! Some paper I have learned by heart and my mentor pointed me millions of times how to apply things I already knew!
@raihankhan197
@raihankhan197 3 года назад
I would really love to see a whole C tutorial. I have been searching someone like you, who can really teach C. Please, I really insist you to make aa whole tutorial series for C. I am a new CS student. And I absolutely love C. I also want to do some networking, system programming. You tutorials will help me a lot and others too. Please make a series.
@williamreji435
@williamreji435 3 года назад
Try Casey handmade hero ,chillitomatonoodle and cherno..with some algorithms and books on the side
@dinethnirmal7888
@dinethnirmal7888 3 года назад
Try jacob sorber, brian will, brian fraser and barry brown
@apresthus87
@apresthus87 3 года назад
Don't think you should learn C by following tutorials, it's really a terrible idea, and I speak from personal experience. You become a much better programmer by doing your own projects that you care about, from scratch and try to figure out things as you go, looking up certain things a long the way if you get stuck. Getting stuck in tutorial hell will get you nowhere. Just many hours of videos watched when you could have been making stuff and honing your skills. That being said, C is an amazing language. I come from a C# and JS background and I fell in love with C once I decided to learn it properly. It's so pure in a way, I find that I can focus a lot more of my time of figuring out how to implement functionality in my code rather than worrying about abstractions and things not related to what I'm actually trying to do. Good luck!
@raihankhan197
@raihankhan197 3 года назад
@@apresthus87 What you just said, I did that exactly the same way. I wrote that comment 5 months ago. I already learnt C and C++ then. But I wanted to know more From experienced programmers. I did small and also big projects with C and C++. I love lower level things so much, that after 1 and a half year I am still using C and C++. Learning new things, trying frameworks, graphics library etc. I just wanted to know more, thats why I wrote that comment.
@apresthus87
@apresthus87 3 года назад
@@raihankhan197 That's good to hear! My answer was just as much for beginners that stumble over videos like this. Many beginners get tricked into thinking you can become a good programmer by watching tutorials. I used to be one of them :D I wanted to see how experienced programmers structured the code as I went on instinct more so than anything when making my game engine as my first big C project. I'm happy to hear that you are doing well and still using C though! :)
@LagMasterSam
@LagMasterSam 3 года назад
1:42:00 - If you already know the index to remove, you can just use memmove. It's much faster than most people realize because it will invoke SIMD operations and hardware intrinsics to move multiple chunks of memory per cycle. It can actually be faster to memmove an array to remove an element than to remove an element from a linked list using pointer reassignment. Pointers can make things very slow if they aren't used correctly.
@nicholasmaniccia1005
@nicholasmaniccia1005 9 дней назад
I wish I could save comments that is interesting i'll have to test this out.
@gazehound
@gazehound 4 года назад
"the compiler is your friend when it tells you something is wrong." This is very true, but the problem with that is that C compilers give the least detailed or useful error messages out of any language I use, not to mention that managed languages give you actual error info at runtime instead of just "segmentation fault." Edited for clarity.
@gazehound
@gazehound 4 года назад
that js snippet would set x to undefined, not zero
@gazehound
@gazehound 4 года назад
anyway i mostly agree with the stuff in this video but i think the takeaways can be applied to non-garbage-collected languages that are much better than C
@gazehound
@gazehound 4 года назад
or even to garbage collected languages, because GC in a lot of applications is fine
@Jam_Spam
@Jam_Spam 4 года назад
@Simon Farre just don't make errors it takes so much time out of your day as a programmer and one of the things that impacts your efficiency the most
@Bennyhanaa
@Bennyhanaa 4 года назад
@@Jam_Spam You're expecting people to write thousands of lines of code perfectly without any error whatsoever. are you dumb?
@Krakatou1
@Krakatou1 3 года назад
You are a legend! I've been writing C code for 20 years and you've taught be a few ticks I just hadn't realised until now. Thank you.
@tadeln
@tadeln 4 года назад
11:34 - C++ tries to hide things 55:30 - I've hidden my macro really well
@stewartzayat7526
@stewartzayat7526 4 года назад
If this isn't meant as a joke, you misunderstood what he meant by saying c++ hides things
@nextlifeonearth
@nextlifeonearth 4 года назад
It's you hiding something yourself versus the language mandating things stay hidden from you.
@johnjackson9767
@johnjackson9767 3 года назад
@@nextlifeonearth Exactly
@nyyakko
@nyyakko Год назад
@@stewartzayat7526 except it doesn't. in the same way it was the guy's decision to encapsulate that macro, it also was his decision to do the same with the operator overloading example
@me_12-vw1vi
@me_12-vw1vi Месяц назад
@@nextlifeonearththis. control is what you get with c
@itellyouforfree7238
@itellyouforfree7238 Год назад
1:47:10 "because I know what the hell I'm doing": no you don't! if you access data past the first element it's UB, that's what you're doing...
@rolandinnamorato1953
@rolandinnamorato1953 Год назад
Wrong. He malloc'd in the next line
@itellyouforfree7238
@itellyouforfree7238 Год назад
@@rolandinnamorato1953 No, you are wrong. If you *declare* `data` to be an array of length 1, you have no right to access past index 0, even if you allocate 1TB of memory for it. The compiler is free to optimize assuming that `data` has length 1 because that's what you told him
@jean-naymar602
@jean-naymar602 4 года назад
12:15 Not a compelling argument at all in my opinion. Operator overloading mostly makes sense when it's used to define real mathematical operators. (With the exception of string concatenation i guess, and maybe other types) Operators *ARE* functions. They take data in, they spit data out. If you're smart enough to understand that "strcat" concatenate two strings together, you're smart enough to understand that '+' concatenate two strings together. Its just another notation to mean the exact same thing. Using the example of vector multiplication is dishonnest : its ambiguous because there's no clear definition of what a multiplication of vector is. Not because '*' is not explicit in and of itself. And that's why half the people say parwaise mult, and the other half say dot product : They don't know because there's no good anwser. In fact, i'd like for you to elaborate on why you think "mult_vec (&vecA, vecB, vecC)" is somewhat more explicit than "vecA = vecB*vecC". there's no sementic difference between them... they mean the *exact* same thing. They're Just written differently. Therefore if "mult_vec" is explicit, so is '*'. I suppose you *DO* use operators on primitive data types ? Why ? Why are they explicit enough ? Because you know what '+', '-', '*', '/', '%' mean on numbers. In reality, no operator is explicit. You **HAVE** to know what they do to know what to expect from them. If I'm able to know what an operator does to primitive data types, I don't see why I wouldn't be able to do the same for other data types.
@karma6746
@karma6746 4 года назад
You clearly missed the point. What an operator does to primitive data-types is clearly and unambiguously defined by the standard. It is guaranteed to remain the same forever, irrespective of the compiler and much less of the person writing the code. With overloading, it is up to whims and fancies of whoever implemented it. mult_vec (&vecA, vecB, vecC) clearly advertises itself to be a function call, the documentation of which can be looked up. B*C looks like a standard operation when it could be, sans any type info, literally anything. To make matters worse there could be 100 different overloads of the same '*' operator even for the same type for different second arguments types. My biggest pain when debugging C++ code is that there is no quick way of finding the correct overload or template specialization that is being invoked.
@QckSGaming
@QckSGaming 4 года назад
@@karma6746 Also, mult_vec shows that you are _modifying_ an existing object (pass by ref) while a = b * c might return a _new_ object
@0xCAFEF00D
@0xCAFEF00D 4 года назад
I agree mostly. It's really a problem of having a feature that risks ambiguity. In C you'll know what uint + uint is assuming basic algebra knowledge (and overflow knowledge). For many it may be unintuitive what uint* + uint does. But the reason that isn't a problem is because it's well known to someone who knows the rules of the language. People can agree that someone who doesn't know the fundamental rules of the language don't count and I think most do. You wouldn't criticize a language because a newbie doesn't get it. They're taken out of the legitimate confusion set. And you need that boundary somewhere. For operator overloading it's not going to be consistent everywhere. I can't hold you to a standard where you have to intuit what every library author chose their vec*vec to mean. It's a risk averse approach. Not trying to absolutely eliminate confusion. I'm not personally all that opposed operator overloading. If that's the only interface for types I don't approve of I wrap it. I use it for vector types sometimes. You really just have to check that you know what the operators do before you use them.
@lupsik1
@lupsik1 4 года назад
I think theres an even better argument IMHO. You can create your own operators to avoid ambiguity. They're not exactly operators but the resulting code will look as if they were. stackoverflow.com/a/41780190/7322371 Im guessing the author of the video would hate that solution but in that way we can have both multiplications : vecA vecB , and vecA*vecB, and at this point its obvious which operation we're performing.
@karma6746
@karma6746 4 года назад
@@lupsik1 That is not creating a new operator. It is simply using a (very ugly) hack that overloads the '' operators to make something that looks like a new operator while relying on not one by two operator overloads in the background, not to mention the additional overhead due to the template being used. But that is not even the real problem. There is a reason why C++ only allows existing operators to be overloaded. If a program is filled with multiple such custom 'operators' does it decrease ambiguity or increase it? Imagine trying to debug someone else's code where he has gone wild with those! Your link serves as an even better example of what is wrong with operator overloading. This is the kind of horror that sub-standard programmers create using the features that C++ provides. This is exactly what Linus was talking about in his famous anti-C++ rant. He wasn't against C++, he was against the large number of C++ programmers who don't understand how to write simple, performant, readable, debugable code. The worst part is that these guys don't even understand what they are doing wrong - they think it is cool!
@playerguy2
@playerguy2 4 года назад
Is your approach that because C++ has features that are easy to misuse you should just not use *any* of the features provided? the add() example would, for example, be an amazing candidate for templates, notice how that would be better, not worse. With regard to the multiplication example in C++, write better code! Someone writing ambiguous code is not a good argument for not using an entire language, it's an argument for better education. I don't think we should use C over C++ just because it has less features. C has it's place, but I don't think it's the same place as C++'s.
@konstantinrebrov675
@konstantinrebrov675 4 года назад
Just use selected features of C++ in your C code, and use a C++ compiler. You don't have to use all the features of C++, only use the ones that you want. Any good C++ compiler will accept valid C code.
@JNelson_
@JNelson_ 4 года назад
It's quite frustrating how fan boyish people get. There are useful features to both languages and both features can be abused easily enough. *cough* macros *cough*
@alextrotta796
@alextrotta796 4 года назад
I was thinking the same thing. I've heard the "easy to abuse" argument for operator overloading many times, but the problem is that people make intentionally misleading examples. I've written enough Java that I hate writing .add(...) when I really just want a +. That's exactly the time to use operator overloading, not to confuse things.
@gvcallen
@gvcallen 4 года назад
I as a C++ programmer kind of disagree with you and agree with his perspective. While I personally think using a C++ compiler with select features is the way to go, his overall argument seems to be that writing C code *forces* you to write good, rigorous, "non-clouded" code. Yes, with good programming practices and standards you will theoretically will never misuse any of the features provided, but to me it seems that isn't how it often happens in practice, with many libraries going down a completely unmanageable path because C++ made it easy for them. Again this is just how I see it, but I am a C++ programmer and love the language, so I don't really have a bias in the C direction when it comes to this
@homelessrobot
@homelessrobot 4 года назад
this is all fine and dandy until you actually have to cooperate with someone in c++ and you disagree about what's the good minimum subset. Now you don't even know the same programming language as other c++ programmers, and cannot cooperate. Well you can cooperate; just not in c++, but rather in the subset of c++ nearly everybody who programs in it knows/uses: c.
@amitjosh79
@amitjosh79 4 года назад
In your Javascript example - 'x' will not be ZERO, but 'undefined'.
@fredg8328
@fredg8328 2 года назад
Nobody overloads the multiplication with vectors. Every math lib I saw uses explicit names: dot, cross, scale. The * operator is sometimes used to multiply a vector by a scalar (uniform scale) but that's all. C++ programmers are less dumb that you think.
@h.cazador
@h.cazador Месяц назад
if i program in C, will my wife come back?
@EvasHookGame
@EvasHookGame 10 месяцев назад
Started my journey of learning C++ 6 months ago from 0 experience in programming, just watched 16 minutes of your video for the moment but you're already saying "philosophical approach" stuffs I instantly felt during my very young journey. Very glad to hear my noob "feelings" are not that "heretic" : "why overloading if I could just type few more lines ? why hiding me some details of the code and optimize things I could do myself , getting me bad habits ?" ( especially when learning the roots of how everything work, it's hard to connect the dots lol ) Thanks from a rookie, to help me open my mind in this world :)
@jtw-r
@jtw-r 10 месяцев назад
“if you’re gonna be a good programmer, you’re gonna want to learn how to do things” ugh exactly!!!!!! there’s so many phenomenal points in this presentation - Although there was a LOT of typos in it 😂 no judgement though
@anonnon2278
@anonnon2278 3 месяца назад
Some where in Nietzsche there is the line - don't think about all the stuff you must know, think about what you must DO.
@gnif
@gnif 9 месяцев назад
What what? You are saying that `realloc` causes page remapping using the MMU? Sorry but this seems incorrect. 1) Even if this is true, it should not be relied upon, it's not part of the C standard and is dangerous to even infer that one could rely on this. 2) glibc uses pools to allocate memory that is < 128kb in size. If the realloc size exceeds the size of the pool the memory was allocated from, it will allocate a brand new pointer and perform a memcpy 3) For allocations that are >= 128kb glibc will use `mmap` to create an anonymous mapping as this can be released back to the OS unlike memory obtained via sbrk. If you realloc to a size that exceeds the size of the `mmap` this will allocate a brand new pointer and perform a memcpy. 4) Getting the kernel to adjust the memory mappings via the MMU would be expensive both due to additional syscalls, and it would not be worth doing unless it hit 2 or more pages. 5) `realloc` is implemented in user space as part of libc, and has no notion of or even view of how memory is mapped by the kernel. This is why implementing buffer objects that never "realloc" but rather just allocate another buffer and provide an interface to read/write contiguous memory in the buffers is usually done. Or implementing memory pools for specific fixed size structs that grow by again, allocating additional buffers. Also your realloc example at 1:38:11 doesn't allow for the fact that `realloc` may fail, which if it does not only will you crash because `array` will become `NULL`, but even if you check for failure here, you will have leaked memory because you just overwrote your pointer with NULL and now you can't free it. As for your "faster" backwards remove, it depends on the size of each array element, you're literally copying around memory to do this. If you must do this, it is much faster to do a forward search (which is a far faster memory access pattern) for the index of the element you wish to remove, and then use `memmove` as it will take advantage of intrinsic operations to accelerate the copy. If the linked list struct is large, or your linked list is a huge data set, it's enormously faster to remove from a linked list as you only have to update a couple of pointers. You can also maintain cache coherency to a large extent with a linked list if you allocate your items from a memory pool (but that's subject to fragmentation depending on your usage patterns). Iterating backwards through the array can also cause cache latency issues because CPUs (especially older generation ones) expect to read ahead to fill the cache line, not read backwards.
@bernardomk
@bernardomk 4 года назад
Awesome, people can dislike, trash all they want but, how many videos like this you see out here? You wanna watch a video on how pointers work? Linked lists? This is real life code and it's awesome that someone took the time to do a video like this. Congrats, man!
@rickthatch3556
@rickthatch3556 8 месяцев назад
Interesting idea.... I found there were better ideas in books on C.
@douglaseleveld2707
@douglaseleveld2707 7 лет назад
There is a bug at 1:50, not enough memory is allocated
@eskilsteenberg
@eskilsteenberg 7 лет назад
You are right! Obviusly it should be: sizeof(MyStructA) + sizeof(MyStructB) . Thanks for spotting it!
@jjinux
@jjinux 7 лет назад
Best comment ever.
@qwerasdfhjkio
@qwerasdfhjkio 4 года назад
1:50:00, not 1:50 lmao I was confused
@andrew9800
@andrew9800 3 года назад
I come back to this presentation from time to time. It's given me some good ideas for my own work. Thanks!
@StarContract
@StarContract 10 месяцев назад
I think C++ has become the opposite of C, at least when it comes to syntax. It is absolutely bloated with features, many of which exist solely to write 5 less lines of code. Goes against the simplicity, elegance and "what you read is what you get" syntax of C.
@winrg1234
@winrg1234 Год назад
i would be interested to hear your opinions on Rust, as i think it makes a good effort to mitigate and even solve many of the problems you reference in non-c languages, while providing the cushy high-level interface many love.
@indycinema
@indycinema 4 года назад
This is insanely useful. Lots of idioms that a JS dev getting into C needs to hear.
@QckSGaming
@QckSGaming 4 года назад
Take it with a huge grain of salt. There's a reason why many "new" features have been built to newer versions. This code you are looking at is very outdated. Like, why name something module_object_action when you could use namespaces which is made exactly for that cause (module::object.action). I'd look elsewhere. He also advocates monster functions which is just horrible and completely unmaintainable and unscalable way to code.
@uziboozy4540
@uziboozy4540 4 года назад
Using C in 2020? Come on.. you should be using Rust instead 😂
@zakarouf
@zakarouf 4 года назад
@@QckSGaming problem with namespace comes when you're in a shared project with multiple programmers. It gets confusing real fast. In standard libraries yeah it's fine nobody will confuse 'cout', but other than that yeah.....
@zakarouf
@zakarouf 4 года назад
@@uziboozy4540 old stuff != bad and vice versa, plus everyone have their preference. If you like rust more power to you. People need to try out new stuff especially in tech field. But disregarding something just due to its age is bad mindset.
@uziboozy4540
@uziboozy4540 4 года назад
@CooCooWizard overrated? Whether or not you think the syntax is garbage, is just your own sensitive opinion. To me it just sounds like you're either too stupid or too lazy to learn the language. If you don't like it, don't use it. Rust is still better than C or C++ without doubt. Please, elaborate on anything that is better in C/C++ as opposed to in Rust. I'm not a fan of the way implementation works in Rust, so that's a win for C++ there with classes. Other than that.. nothing
@tianned
@tianned 3 месяца назад
There is some sexy code. I suppose the guide really reveals the philosophy of c. That’s so satisfying
@me_12-vw1vi
@me_12-vw1vi Месяц назад
sexy code
Далее
Let's Create a Compiler (Pt.1)
1:11:03
Просмотров 524 тыс.
Qalpoq - Amakivachcha (hajviy ko'rsatuv)
41:44
Просмотров 303 тыс.
2 Years Of Learning C | Prime Reacts
22:24
Просмотров 289 тыс.
31 nooby C++ habits you need to ditch
16:18
Просмотров 788 тыс.
Why I Use C | Prime Reacts
13:00
Просмотров 159 тыс.
Programming Languages I used at Google (C++ rant)
6:14
zig will change programming forever
9:34
Просмотров 306 тыс.
Writing a game the hard way - from scratch using C. #1
34:20
Arenas, strings and Scuffed Templates in C
12:28
Просмотров 87 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08