"Python generators in C" > looks inside > assembly
@jonaslamprecht91698 сағат бұрын
>looks inside further >machine code
@hoyoreverse7 сағат бұрын
@@jonaslamprecht9169 but "machine code" is literally "same" thing as assembly. These instructions but encoded in binary form instead of "readable" text. (if we throw away all the ELF/PE stuff, but still it's just a binary format)
@monkqp7 сағат бұрын
@@hoyoreverseeh, technically correct, but assembly has a bunch of nice features straight machine code doesn't have, like labelling the shit you use
@hoyoreverse7 сағат бұрын
@@monkqp well yea, this "labelling" will be then converted to a relative jmp
@Capewearer7 сағат бұрын
@@hoyoreverse many assembly languages allow you to define macros. So there's still a difference.
@Apoque35 минут бұрын
This is so cool. This is really reminding me of when Rust was putting together the pieces for async/await. Effectively in Rust their async blocks/functions get turned into generators that return a sequence of "wakers" and then when the generator is done it yields the result at the end.
@amedeoalf11 сағат бұрын
Feels good to arrive just in time for mista zozin upload
@eckhardt0927 сағат бұрын
Yesu yesu yesu
@AirBender-s2p7 сағат бұрын
fire lord sozin ?
@lorenzo42p4 сағат бұрын
when I was in highschool, I took every computer class that was available. I took a typing class, got good at solitaire in that class. there was a small html class available, only maybe 8 of us in the class. after learning the tag in school I was going home and learning perl.
@RobertFletcherOBE9 сағат бұрын
StopIteration is used for control flow in most loops. Python Exceptions are not C++ exceptions and they don't have the same impact on speed. From what I understand StopIteration is also not a full fat exception, its a special case which is very efficient to raise. I agree it seems odd, and I don't know why they chose to use it, but it isn't as slow as folks expect when they see 'exception'
@khuntasaurus888 сағат бұрын
@@RobertFletcherOBE yes, most python exceptions derive from "Exception" class except some special cases like StopIteration and KeyboardInterrupt which detive from "BaseException" meaning they can't be caught with a regular "except Exception as e" since (maybe confusingly) Exception doesnt implement BaseException
@Daniel_Zhu_a6f7 сағат бұрын
i've ran a simple test and it does a stack unwind, which is the main cause of exceptions being slow: ```python def b(x): if x>= 3: raise StopIteration; class G: def __init__(self): self.x = 0 def __iter__(self): return self def __next__(self): b(self.x) self.x += 1 return self.x def main(): for x in G(): print(x, end=', ') # should print `1, 2, 3,` main() ``` but dis.dis(main) shows that it uses special bytecode instruction to catch the StopIteration. apart from being slow, it's also very confusing, compared to breaking the loop on a sentinel value. with all the optimizations it will apparently still go through the completely necessary stack unwind, albeit a short one, which is much slower than a normal return.
@cheebadigga40926 сағат бұрын
@@Daniel_Zhu_a6f you can also use for/else to "catch" that the for-block wasn't iterated at all. Different use case but sometimes it's easy to confuse the two and accidentally go the slower route (whichever that is for your use case)
@rogo73306 сағат бұрын
@@Daniel_Zhu_a6f breaking loops on "special values" sucks - you're populating code with lots of 'if'-s that essentially just mean "go up". Even JS has something better - lables, which you can put after 'break' keyword and just break out of any block upwards, and they even namespace shadowed.
@thesenamesaretaken5 сағат бұрын
@@khuntasaurus88 >Exception doesn't implement BaseException Good old OOP
@danielchicoelamo10 сағат бұрын
It is not where u study, it is how u think and solve problems, thanks for ur examples
@avhd1875 сағат бұрын
C and Python goes together. There is no feud.
@ABaumstumpf4 сағат бұрын
C does the work, Python dictates what works needs to be done.
@k1ngjulien_3 сағат бұрын
they are not enemies. in fact they're kissing, sloppy style
@chillydill47037 сағат бұрын
Mega off topic but the network series (websockets and stuff) was very interesting. Then at work today, I had to troubleshoot some network stuff with wireshark and thought to myself "what app would Tsoding create if he made an enterprise ready, sort of wireshark or proxyman app." . I guess it's just probably me, but that would be a cool series and very challenging for him as well :)
@rogo73306 сағат бұрын
Returning value from the function is, essentially, the same as saving something to some "global", non-local variable. You're contracted by the C function convention that you either return nothing (void), or you return something that _can_ be returned through 'rax'. Idk, maybe not having a syntax that mandates you to put something after 'return' is actually better, because you can just pre-set 'rax', and function can just not touch it, and still you will have a benefit of having type checking of this value in your language.
@000dr0g9 сағат бұрын
Bravo! You are on a roll. What next for your context restoration plumbing? As I was writing this comment, you mentioned "God" versus the "Universe" in a philosophical moment musing over your channel's success. I recently found the philosophy that I like the best - Absurdism! Albert Camus' observation that life is absurd; it is best just to get on with enjoying the moment the best we can.
@mmilerngruppe43 минут бұрын
lovely cocroutine for pison
@psteven54 сағат бұрын
C would be peak if it had short shorts, long shorts, and short longs
@Capewearer7 сағат бұрын
3:50 it's slow by design. The variables can have different precision, but not fixed width or at least machine word width. Each time you change the value you actually create the object. For loops are wrappers upon iterators, that's why they're slower than pure iterators. And so on!
@DuskyDaily11 сағат бұрын
Hi Mr. Zozin 😁. Hehe Lazy evaluation, sounds a good next steo after exoloring cooperative async stuff.
@pan-gloowl11 сағат бұрын
Mr. Azozin
@bartlomiejodachowski7 сағат бұрын
my peasant generator would be a function using static variables xD
@cheebadigga40926 сағат бұрын
Zozin, you do know that for loops are far worse than throwing and catching exceptions (specifically StopIteration) in Python when it comes to performance? StopIteration is great if you use it more. By the way, when you start to write a py file, you already know its gonna be slow, so I don't see a problem with it in that regard at all.
@at-29747 сағат бұрын
I swear the like counter went brrr the moment he created main.py file
@chri-k6 сағат бұрын
4:12 it is reminiscent enough that that in C++ it is called a coroutine ( C++ coroutines are quite... uhh... pls don't )
@purpasmart_4831Сағат бұрын
C++ is just a disaster in general.
@bernardcrnkovic37696 сағат бұрын
29:40 same problem as "you need to wipe 4 times in order to know you only needed 3" 🤣
@Mirgeee7 сағат бұрын
I am a simple man. I see zozin video, I click.
@atduyar11 сағат бұрын
Great session btw.
@theodorealenas317110 сағат бұрын
I actually didn't expect that to be possible without changing the language parser.
@matthartley65372 сағат бұрын
Do you have a source on C being faster than Python? Seems hard for me to believe
@azharalibhutto12093 сағат бұрын
Great 👍
@WarmNiceCozy9 сағат бұрын
I’m so excited. He programmed in python. 🎉
@iglobrothers64510 сағат бұрын
Are we ever going to see ZozinOS?
@GesteromTV6 сағат бұрын
Jai will be GOAT when it came out
@k4r4m310.8 сағат бұрын
@y00t00b3r11 сағат бұрын
lol, I guess Mr. Azozin hasn't ever tried using generators in ECMAScript ?
@LeaoMartelo10 сағат бұрын
Emacs script runs in the browser
@y00t00b3r9 сағат бұрын
@@LeaoMartelo read my post again
@LeaoMartelo9 сағат бұрын
@y00t00b3r its a joke
@y00t00b3r6 сағат бұрын
@@LeaoMartelo YOU GOT ME !!! 😀
@bizarrecentral603211 сағат бұрын
What development environment is this ? Looks very efficient.
@ReyLamurin11 сағат бұрын
Emacs
@hamiltonianpathondodecahed523611 сағат бұрын
VSCode
@augustrum135811 сағат бұрын
man...
@GegoXaren11 сағат бұрын
ed
@EnDeRBeaT11 сағат бұрын
pen and paper
@vilhola21879 сағат бұрын
how do you get gruber darker theme for terminal
@ferdynandkiepski502610 сағат бұрын
Somewhat similar to std::generate in C++23.
@neraid8 сағат бұрын
$x can do this too and it's faster than Python
@alexmalinin23876 сағат бұрын
Showing generators via example in python and not in JS PepeHands
@ViniciusMiguel19888 сағат бұрын
Oh no python no no
@elgalas10 сағат бұрын
EmacsScript (JavaScript) has this too
@davinelulinvega9 сағат бұрын
It would be better for educational purposes to show generators in python console, "live mode", so to speak, since it's interpreted language
@ttt694204 сағат бұрын
Isn't python just like a giant C wrapper
@mbarrio3 сағат бұрын
Isn't C just a big Microcode wrapper?
@ttt694202 сағат бұрын
@@mbarrio I wasn't be abstract. Python is literally written in C.
@bagofmanytricks8 сағат бұрын
This guy keeps jumping to the wrong premature conclusions like all the time
@namefreenargrom56946 сағат бұрын
Do "defer" next. Is it even doable?
@Daniel_Zhu_a6fСағат бұрын
@@namefreenargrom5694 you can emulate it with labels. but no, you can't emulate defer without a powerful macro system, since it inserts code into many places.
@gsestream10 сағат бұрын
actual usefulness? or just fun and games. asterisk simple jail.
@Heater-v1.0.09 сағат бұрын
Python? No. I hate snakes.
@TheCommunistRabbit8 сағат бұрын
We'll that's one way to say you're not gay
@rasulseidagul7 сағат бұрын
So much complexity while a “generator” is just a struct and a switch case 😂
@User948Z7Z-w7n9 сағат бұрын
JavaScript can do this too
@TheCommunistRabbit8 сағат бұрын
EmacsScript*
@AndrewTiger11 сағат бұрын
bliah
@Sitris-h7q11 сағат бұрын
"Programming" in Python. Its called scripting brooo!! python is not language for real ROGRAMMERS
@Drudge.Miller11 сағат бұрын
Yehar Bro, real PROGRAMMERS only program in real PROGRAMMING LANGUAGES!!!
@GegoXaren11 сағат бұрын
Oooooooo!
@alejandroioio67847 сағат бұрын
Yes!!! Real programmers only use machine language!!!! Anything else is just frontend
@ABaumstumpf4 сағат бұрын
@@alejandroioio6784 Real programmers just use butterflies.
@alejandroioio67843 сағат бұрын
@ABaumstumpf xd
@porknite9 сағат бұрын
I think everybody knows that C can do everything Python can do but better lmao
@Opharg2 сағат бұрын
Define better. Someone who knows python at an equivalent level is gonna have it set up and running in less time than the C programmer. Different tools, for different goals.