@@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)
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.
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.
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'
@@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
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.
@@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)
@@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.
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 :)
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.
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.
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!
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.
@@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.
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.
"Python generators in C"
> looks inside
> assembly
>looks inside further
>machine code
@@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)
@@hoyoreverseeh, technically correct, but assembly has a bunch of nice features straight machine code doesn't have, like labelling the shit you use
@@monkqp well yea, this "labelling" will be then converted to a relative jmp
@@hoyoreverse many assembly languages allow you to define macros. So there's still a difference.
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.
Feels good to arrive just in time for mista zozin upload
Yesu yesu yesu
fire lord sozin ?
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.
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'
@@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
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.
@@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)
@@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.
@@khuntasaurus88 >Exception doesn't implement BaseException
Good old OOP
It is not where u study, it is how u think and solve problems, thanks for ur examples
C and Python goes together. There is no feud.
C does the work, Python dictates what works needs to be done.
they are not enemies. in fact they're kissing, sloppy style
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 :)
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.
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.
lovely cocroutine for pison
C would be peak if it had short shorts, long shorts, and short longs
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!
Hi Mr. Zozin 😁. Hehe Lazy evaluation, sounds a good next steo after exoloring cooperative async stuff.
Mr. Azozin
my peasant generator would be a function using static variables xD
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.
I swear the like counter went brrr the moment he created main.py file
4:12 it is reminiscent enough that that in C++ it is called a coroutine
( C++ coroutines are quite... uhh... pls don't )
C++ is just a disaster in general.
29:40 same problem as "you need to wipe 4 times in order to know you only needed 3" 🤣
I am a simple man. I see zozin video, I click.
Great session btw.
I actually didn't expect that to be possible without changing the language parser.
Great 👍
I’m so excited. He programmed in python. 🎉
Are we ever going to see ZozinOS?
Jai will be GOAT when it came out
Do you have a source on C being faster than Python? Seems hard for me to believe
😂
lol, I guess Mr. Azozin hasn't ever tried using generators in ECMAScript ?
Emacs script runs in the browser
@@LeaoMartelo read my post again
@y00t00b3r its a joke
@@LeaoMartelo YOU GOT ME !!! 😀
What development environment is this ? Looks very efficient.
Emacs
VSCode
man...
ed
pen and paper
how do you get gruber darker theme for terminal
Somewhat similar to std::generate in C++23.
$x can do this too and it's faster than Python
Showing generators via example in python and not in JS PepeHands
Oh no python no no
EmacsScript (JavaScript) has this too
It would be better for educational purposes to show generators in python console, "live mode", so to speak, since it's interpreted language
Isn't python just like a giant C wrapper
Isn't C just a big Microcode wrapper?
@@mbarrio I wasn't be abstract. Python is literally written in C.
This guy keeps jumping to the wrong premature conclusions like all the time
Do "defer" next. Is it even doable?
@@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.
actual usefulness? or just fun and games. asterisk simple jail.
Python? No. I hate snakes.
We'll that's one way to say you're not gay
So much complexity while a “generator” is just a struct and a switch case 😂
JavaScript can do this too
EmacsScript*
bliah
"Programming" in Python. Its called scripting brooo!! python is not language for real ROGRAMMERS
Yehar Bro, real PROGRAMMERS only program in real PROGRAMMING LANGUAGES!!!
Oooooooo!
Yes!!! Real programmers only use machine language!!!! Anything else is just frontend
@@alejandroioio6784 Real programmers just use butterflies.
@ABaumstumpf xd
I think everybody knows that C can do everything Python can do but better lmao
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.
a real nobhead.
Thumb up if you prefer python than c
Hell nah