OOP in Pure C

  Рет қаралды 47,324

Tsoding Daily

Tsoding Daily

12 күн бұрын

Streamed Live on Twitch: / tsoding
Enable CC for Twitch Chat
Panim Playlist: • Panim
Support:
- BTC: bc1qj820dmeazpeq5pjn89mlh9lhws7ghs9v34x9v9
- Pay for my VPS: zap-hosting.com/en/shop/donat...

Пікірлер: 161
@demolazer
@demolazer 11 күн бұрын
I read the book clean Architecture. It has a great section near the beginning about programming paradigms where the author shows how you can implement all the OOP behavior in C. Very fascinating
@JoseDaviCorreiaPassos
@JoseDaviCorreiaPassos 11 күн бұрын
​​@@user-ji6ip7ou8djust read again and you Will find the nome of the book
@cslearn3044
@cslearn3044 10 күн бұрын
Bruh ​@@user-ji6ip7ou8d
@lowlevelcodingch
@lowlevelcodingch 10 күн бұрын
@@user-ji6ip7ou8d He literally said it
@AbdessamadBelm
@AbdessamadBelm 10 күн бұрын
Can u please provide the full title of the book
@skeleton_craftGaming
@skeleton_craftGaming 10 күн бұрын
People think this is some sort of Revelation, all of your OOLs compilers/interpreters are written in C [or c++ which's compiler was written in C originally]
@tripplefives1402
@tripplefives1402 10 күн бұрын
@30:36 I started learning C from reading the manual for LCC-win32 IDE as a PDF on an Palm PDA while on night shift. It even explained how to do win32 api stuff from scratch.
@Jack_in_the
@Jack_in_the 11 күн бұрын
are the captions the live chat?? that's cool af
@user-pm2ru6ir6n
@user-pm2ru6ir6n 10 күн бұрын
Why do I need a chat if I came to watch/listen to the streamer. The streamer is interested in this, but the audience is not...
@nothappyz
@nothappyz 10 күн бұрын
​@@user-pm2ru6ir6n yeah this doesn't really make sense. Perhaps it's just a proof of concept
@adokce
@adokce 10 күн бұрын
@@user-pm2ru6ir6n exactly why it's great. if anyone cares, they can turn on the captions. they are not hard-embedded in video
@lolcat69
@lolcat69 9 күн бұрын
​@@user-pm2ru6ir6n Maybe, just maybe, it us because in a stream, the streamer talks with the chat, and reads it, and people recommend him to do X or Y and he tells why yes or why not to do it that way, and if you can't read that then it makes no sense? Just saying
@miroaja1951
@miroaja1951 10 күн бұрын
BREAKING NEWS: c programmer discovers dynamic dispatch in the lord's year 2024
@juanmamani2110
@juanmamani2110 10 күн бұрын
absolutely agree with your phrase "you can do anything in C"
@garryiglesias4074
@garryiglesias4074 9 күн бұрын
No, you can't do "generics" (meta programming).
@filip14528
@filip14528 9 күн бұрын
@@garryiglesias4074 You could write a c program that inputs c code with generics and outputs c code
@gumz4183
@gumz4183 8 күн бұрын
@@garryiglesias4074 the video is literally about implementing oop in C. You think the same can’t be done for generics?
@garryiglesias4074
@garryiglesias4074 8 күн бұрын
@@gumz4183 Show me. Make some template, please. (Some context: I program in C for more than 30 years, and I've done full GUI in OOP/C for video games in 1997... So you won't be taken by surprise...)
@RandomGeometryDashStuff
@RandomGeometryDashStuff 8 күн бұрын
@@garryiglesias4074macro like arena_da_append?
@user-uf4rx5ih3v
@user-uf4rx5ih3v 10 күн бұрын
A very interesting idea and quite elegant implementation! It's rather amazing that hot reloading can work so well in a typed and compiled language like C that doesn't have much features. I wish modern languages put some thought on making this a feature because it is so convenient for creating web servers, gui's and other highly interactive and visual applications.
@GaryChike
@GaryChike 8 күн бұрын
Very nice! Reminds me of an article on Quora on "Object-Oriented Programming in C: A Deep Dive" by Khanno Mikhail: "...there are actually THREE ways to accomplish OOP in C (aptly named): Open style. Pointer style. and GTK style (GObject style). There are also three ways to apply function/method polymorphism in C as well: Struct style. Disjoint style. and Interface style ..."
@user-hk3ej4hk7m
@user-hk3ej4hk7m 10 күн бұрын
Wouldn't be a C video without a segfault 10 minutes in
@Brad_Script
@Brad_Script 6 күн бұрын
you wouldn't be coding anything significant if you never get segfaults
@user-hk3ej4hk7m
@user-hk3ej4hk7m 6 күн бұрын
​@@Brad_Script Yes, in C you wouldn't. Anything remotely useful is segfault galore.
@araarathisyomama787
@araarathisyomama787 5 күн бұрын
​@@user-hk3ej4hk7m Is your OS a segfault galore?
@user-hk3ej4hk7m
@user-hk3ej4hk7m 5 күн бұрын
​@@araarathisyomama787 You must be confused, I don't develop OS'. Running production ready software is not the same as developing it.
@neshkeev
@neshkeev 11 күн бұрын
It only makes sense to define the Task struct's function members to accept Task itself so it looks similar to `self` in Python and besides you can call other task's functions from a Task's function
@Do_It_Stupidly
@Do_It_Stupidly 11 күн бұрын
I've been waiting for this for a loooong time😭
@garryiglesias4074
@garryiglesias4074 9 күн бұрын
But it's a well known knowledge since the 70's...
@DVRC
@DVRC 3 күн бұрын
Looking at old codebases I've seen many cases of OOP in C: - Sun Pixrect is a low level library for drawing on the framebuffer, and for each framebuffer there is a different implementation. At the creation of a Pixrect object, it is dispatched with the function table to manipulate it - Still from Sun, X/NeWS has a graphics library called Shapes, that replaced the CScript (the PostScript graphic layer) + Pixrect combo, and it has plenty of macros to declare classes in C and dispatch all the methods. This package handles shapes, paths and framebuffers - At CMU, a preprocessor called "Class" was made for the Andrew project. It enriched C with Object-Oriented specific syntax (similar but different from both C++ and Objective C). I guess this was used for the Andrew Toolkit and other applications of the suite
@bbq1423
@bbq1423 10 күн бұрын
The boilerplate in C for the animal example could have been a bit smaller if you would have stuck to what C++ does a bit closer. In C++ it would inline the dog and cat data into the same allocation as for animal, meaning Animal effectively becomes a "Animal_Methods**" with some extra data to the right of it. Dog and Cat would also need the vtable pointer in the struct definitions, but this could be mitigated via the use of the butterfly technique in the utility methods. Initialization code for the tags could also be simplified if you used the C++ approach.
@zetroks
@zetroks 10 күн бұрын
Это замечательно! С удовольствием посмотрел на всю эту дичь. На удивление это крайне просто работает. Никогда не пытался имплементить что-то такое в своей жизни, максимум все заканчивалось указателями на функции, по причине ненадобности. Но какой же классный видос
@blastygamez
@blastygamez 11 күн бұрын
Nice, see all you need is C and a Tsoding
@OCTAGRAM
@OCTAGRAM 6 күн бұрын
When Tsoding does C, it's not C but Ts
@shakkar23
@shakkar23 10 күн бұрын
For the tag implementation, you can make the tag an enum, as well as make the data a union of pointers to the types that inherit it, this allows the vtable to be off of the heap as you now know the size in compile time, as well as you can use designated initializers to have a more well defined offset of all of the pointers for your vtable.
@Adoblem
@Adoblem 6 күн бұрын
😊😊😊😊😊😊
@john.darksoul
@john.darksoul 10 күн бұрын
Where is the book, Zozin? Where is it? You'd never give it to an ordinary citizen!
@martinparrish5392
@martinparrish5392 9 күн бұрын
There is no book, only Zuul!
@Mentox2
@Mentox2 11 күн бұрын
Unfathomably cool.
@SaidMetiche-qy9hb
@SaidMetiche-qy9hb 10 күн бұрын
Now your bottleneck is the compiler being slow lol
@asakhar
@asakhar 9 күн бұрын
Tsoding, you don't actually need a dynamic array for vtable, or even register it at runtime, just store it in global library plain array variable and define it inplace. This way "dynamicness" is achieved through loading the lib itself, you just recompile the lib itself and vtable gets reloaded, then you just resolve it like you already do with function symbols. This way you can add vtable entries, but can't reorder or delete stuff from that just like in your implementation. I can provide an example via PR but unfortunately can't find public repo of panim, please consider making it public so people like me can f around with it)
@velikanskaglava2087
@velikanskaglava2087 11 күн бұрын
Thank you!
@kibels894
@kibels894 10 күн бұрын
Nice that turned out really clean.
@StevenMartinGuitar
@StevenMartinGuitar 7 күн бұрын
Honestly seeing classes and virtual methods implemented in C was really freaking cool
@kibels894
@kibels894 10 күн бұрын
Could you also solve it by getting the arena from the main executable's memory space? Or does that only ensure the pointers aren't unreachable, but they will still be garbage after reloading?
@satyajeetjena6758
@satyajeetjena6758 11 күн бұрын
2 uploads in one day😮😮😮😮
@hubstrangers3450
@hubstrangers3450 3 күн бұрын
Thank you....
@MohammedShuayb
@MohammedShuayb 10 күн бұрын
I like this guy irl like this guy ! Keep it up bro
@pedrokalil4410
@pedrokalil4410 8 күн бұрын
Oh my god, you launched this video right as i am making async oop in C. Tho i am making it more as an general purpose language (i think i will create my lang and transpile to this subset of c i created)
@tripplefives1402
@tripplefives1402 10 күн бұрын
What do we do if the toilet code has a stack overflow?
@ahmadzaklouta
@ahmadzaklouta 12 сағат бұрын
Do you have any videos explaining OOP in C and desing pattern from the beginning
@ThatGuy-fq8cn
@ThatGuy-fq8cn 9 күн бұрын
Congrats you invented GObject
@kikawet
@kikawet 9 күн бұрын
Is there any source code access so far? I am struggling a bit following all these concepts about virtual tables and wanted to take a look into it directly
@bbq1423
@bbq1423 10 күн бұрын
Now that you have a way to run tasks in parallel.. Time for multicore support in nob?
@kaotiskhund
@kaotiskhund 10 күн бұрын
Thank you! For inspiration and laughs! Proposal: maybe animals poop in various places. Abstract the toilet?
@matthijshebly
@matthijshebly 10 күн бұрын
Professor Dr Tsoding, lead researcher in the field of Scatology
@snowcrash-
@snowcrash- 10 күн бұрын
I love your content dude it's just so good.
@drdca8263
@drdca8263 10 күн бұрын
56:06 : I don’t understand why registering task wait wasn’t just added to the task_vtable_rebuild procedure?
@jannemyllyla1223
@jannemyllyla1223 10 күн бұрын
This kind of code not only exists, it is being standarized (there is upcoming ble smart toilet profile).
@leshommesdupilly
@leshommesdupilly 10 күн бұрын
Man, I can't wait to see c adding classes
@SeishukuS12
@SeishukuS12 10 күн бұрын
I played around with something similar a number of years ago, it's kinda fun... Not *super* practical, but fun. Though these days, I do still kind of lay out my data and functions in a similar manner, just without the "virtual functions"/function pointers... So if I ever become unlazy, I can just toss everything into classes and be with the hipsters and use C++. :D
@RandomGeometryDashStuff
@RandomGeometryDashStuff 7 күн бұрын
59:15 by "no code" do you mean Node_graph_architecture (wikipedia)?
@tandeepdas9211
@tandeepdas9211 6 күн бұрын
The best reply from the Gate_Keeper👍
@delicious_seabass
@delicious_seabass 10 күн бұрын
Heresy!
@kenneth_romero
@kenneth_romero 10 күн бұрын
i tried doing this with specialized types with Odin but for a game framework. couldn't get it working though, probably misunderstood something.
@ddruganov
@ddruganov 9 күн бұрын
it seems as though you do not use any kind of lsp, is that intentional?
@skeleton_craftGaming
@skeleton_craftGaming 10 күн бұрын
C++ is not an object oriented language, you can do oop like things in c++ but when you strip away the abstractions you just get C [which is why it is so fast; I say in regards to objects specifically] A C++ programmer... Thats who wrote the Vtable wiki page...
@jiraibozo
@jiraibozo 9 күн бұрын
0:08 The APNIM
@CoderDBF
@CoderDBF 7 күн бұрын
Dude, seriously, I would buy your book.
@OCTAGRAM
@OCTAGRAM 6 күн бұрын
The most advanced OOP in C was in IBM System Object Model
@SeasonalMike1
@SeasonalMike1 10 күн бұрын
Why did i click this video. Obviously i'm not gonna watch a 2 hour video at 12:57pm, also i have to wake up at 7am for school.
@aemogie
@aemogie 10 күн бұрын
am?
@sortof3337
@sortof3337 10 күн бұрын
@@aemogie its literally 1 am. his brain is clearly borked. :)
@aidennwitz
@aidennwitz 10 күн бұрын
how did not watching the video go?
@Maverick56912
@Maverick56912 10 күн бұрын
you're so lucky. I've to wake up at 6am 😢
@SeasonalMike1
@SeasonalMike1 9 күн бұрын
@@aidennwitz pretty cool, decided to watch a minecraft creepypasta at 2am instead :)
@user-di9jq1oe3i
@user-di9jq1oe3i 11 күн бұрын
Как ты зумишь экран?
@apenaswellignton
@apenaswellignton 11 күн бұрын
Pog
@theevilcottonball
@theevilcottonball 7 күн бұрын
I just discovered that Chat is in the subtitles. Make of that what you will.
@tianned
@tianned 10 күн бұрын
That’s so cool omg
@zeno7905
@zeno7905 5 күн бұрын
GATEKEEPER!! Give me the book NOW!!!
@AloisMahdal
@AloisMahdal 9 күн бұрын
A huge problem with OOP is that virtually all basic tutorials go right away into stuff like inheritance and abstract classes, but in reality you should avoid that as much as possible (use interfaces and composition in 99% of cases). Then there's a ton of stuff such as composition, solid and "OOP design patterns" and *some* part of Clean Code... Lot of it is actually useful and applicable to most languages, OOP or not.
@_ami_dad_3289
@_ami_dad_3289 9 күн бұрын
using enum for indexs and naming of methods seems to be easier for me
@error-4518
@error-4518 11 күн бұрын
zozin should write a book about how to google, name it "art of googling" or something.
@patchy-oss
@patchy-oss 11 күн бұрын
no
@skittle72
@skittle72 11 күн бұрын
hell nah💀
@senbonzakura662
@senbonzakura662 10 күн бұрын
What a waste of time lol
@johnsonogbu8697
@johnsonogbu8697 9 күн бұрын
I left python to be here. I want to know and learn how it all started. Thank you tsoding.
@ddruganov
@ddruganov 10 күн бұрын
1:14:33 bruh that caught me off guard
@TheBusttheboss
@TheBusttheboss 5 күн бұрын
Based Emacs user.
@xarax7950
@xarax7950 10 күн бұрын
How did you make constructor and destructor in C ??? video is long ...
@IgneousGorilla
@IgneousGorilla 10 күн бұрын
Probably malloc and free? Lol
@xarax7950
@xarax7950 10 күн бұрын
​@@IgneousGorillamalloc free MANUALY it's not a constructor and destructor !
@tripplefives1402
@tripplefives1402 10 күн бұрын
@@xarax7950 You have to allocate the struct first then invoke an init function, which can be placed inside of a create function so you invoke one function which performs the task of being a constructor.
@javierflores09
@javierflores09 10 күн бұрын
@@xarax7950 how are constructor and destructors not manual, there's nothing automatic about them
@newbiex11
@newbiex11 2 күн бұрын
it's not easy to just use c++?
@xProsek
@xProsek 10 күн бұрын
13:18 ofc we know vtable ;P 26:33 maybe 2d and 4d to make it obv for newbies Thx
@walkertest7503
@walkertest7503 10 күн бұрын
Wait it's all struct...
@brambasieldev
@brambasieldev 11 күн бұрын
1:31:27 out of context zozin when?
@FrankTinsley
@FrankTinsley 10 күн бұрын
Wait so… OOP is good afterall??
@BugbountyPOCs41
@BugbountyPOCs41 10 күн бұрын
i see arch with dwm
@vkatasonov
@vkatasonov 9 күн бұрын
Не буду спрашивать почем и откуда «стимуляторы», но программируя на Си всего полгодика чистого времени, понимаю, что с Си и сознание расширять не надо;)
@JoshuaF.
@JoshuaF. 11 күн бұрын
what a da fu
@nil0bject
@nil0bject 10 күн бұрын
i hate that vtable thing. just use generic objects instead of reinventing the wheel for everything
@Protoex
@Protoex 8 күн бұрын
Why do some people dislike OOP ? I'm aware of the problems related to performance, but other than that, I don't know.
@twitchy9948
@twitchy9948 11 күн бұрын
I lost it at 1:50:50 XD
@levvayner4509
@levvayner4509 10 күн бұрын
I have full control of what languages I use, what paradigms I use, etc. And OOP is not click-bait; it is a very logical way to program, creating analogies from the real world of objects that have properties and actions or methods. I didn't watch the whole podcast, but if you wanted to write your squares as OOP, The squares would contain their own position on the screen, and expose methods like Move(x,y) Color(color) and whatever else you'd want to do with them.
@GiammarcoAgazzotti
@GiammarcoAgazzotti 10 күн бұрын
very cool C stuff and a very good programming exercise as long as you just want to fiddle around and have fun. for any real world need c++ has you covered in a safer way already (and I'm sure we all know this)
@mashroom_
@mashroom_ 10 күн бұрын
just use Vala bruv
@VictorPK100
@VictorPK100 10 күн бұрын
Do not try and read the book. That's impossible. Instead... only try to realize the truth. There is no book.
@leshommesdupilly
@leshommesdupilly 10 күн бұрын
You should call it "c = c + 1"
@valshaped
@valshaped 11 күн бұрын
Nice object oriented shitposting
@Kyoz
@Kyoz 10 күн бұрын
🤍
@pemrograman-cepat3393
@pemrograman-cepat3393 9 күн бұрын
OOP in C?? Cool 😮😮😮
@OneMilian
@OneMilian 10 күн бұрын
I don't need as much specific programming paradigm's as i need good filenames and a clean order. Edit: specific
@babenoff
@babenoff 10 күн бұрын
Покажи нам лучше Хороший Язык Программирования
@user-zp9su9lf6q
@user-zp9su9lf6q 10 күн бұрын
Хороший Учебный Язык
@babenoff
@babenoff 10 күн бұрын
@@user-zp9su9lf6q извините, перепутал, точняк.
@Randy_McShandy
@Randy_McShandy 9 күн бұрын
Hot reloading AKA Shared Object Oriented Programming, we love SOOP
@sabitkondakc9147
@sabitkondakc9147 10 күн бұрын
I love C, however freedom has consequences.
@ahmedbogaterov9775
@ahmedbogaterov9775 11 күн бұрын
FIRST
@elirannissani914
@elirannissani914 11 күн бұрын
First
11 күн бұрын
🫡
@pemrograman-cepat3393
@pemrograman-cepat3393 9 күн бұрын
Bro, can you make chess engine in C? Chess is happening right now 😅
@OlivierDALET
@OlivierDALET 9 күн бұрын
This cactoos thing looks far more like functional programming than oop... Remove all then useless 'new' and you have classic lazy evaluated functions composition. Similar to .net's linq as well.
@sanalyny2807
@sanalyny2807 10 күн бұрын
Я ахуел, когда он недавно на русском заговорил.
This is better than TempleOS
1:55:21
Tsoding Daily
Рет қаралды 29 М.
Is C++ better than C?
1:46:10
Tsoding Daily
Рет қаралды 31 М.
The Noodle Stamp Secret 😱 #shorts
00:30
Mr DegrEE
Рет қаралды 64 МЛН
it takes two to tango 💃🏻🕺🏻
00:18
Zach King
Рет қаралды 20 МЛН
Когда на улице Маябрь 😈 #марьяна #шортс
00:17
Root Cause Analysis - Feature Showcase
3:56
GitLab Unfiltered
Рет қаралды 3
the new PS4 jailbreak is sort of hilarious
12:21
Low Level Learning
Рет қаралды 475 М.
Can C actually do Perfect Bézier Curves?
2:17:22
Tsoding Daily
Рет қаралды 15 М.
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 935 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 879 М.
Newton's Method in C
1:33:17
Tsoding Daily
Рет қаралды 14 М.
Is John Carmack Right about UI?!
1:52:02
Tsoding Daily
Рет қаралды 31 М.
Coding Adventure: Rendering Text
1:10:54
Sebastian Lague
Рет қаралды 547 М.
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
Готовый миниПК от Intel (но от китайцев)
36:25
Ремонтяш
Рет қаралды 438 М.
Nokia 3310 versus Red Hot Ball
0:37
PressTube
Рет қаралды 1,8 МЛН