C can do this too and it's faster than Python

  Рет қаралды 18,188

Tsoding Daily

Tsoding Daily

Күн бұрын

Пікірлер: 108
@stephaneduhamel7706
@stephaneduhamel7706 9 сағат бұрын
"Python generators in C" > looks inside > assembly
@jonaslamprecht9169
@jonaslamprecht9169 8 сағат бұрын
>looks inside further >machine code
@hoyoreverse
@hoyoreverse 7 сағат бұрын
​@@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)
@monkqp
@monkqp 7 сағат бұрын
​@@hoyoreverseeh, technically correct, but assembly has a bunch of nice features straight machine code doesn't have, like labelling the shit you use
@hoyoreverse
@hoyoreverse 7 сағат бұрын
@@monkqp well yea, this "labelling" will be then converted to a relative jmp
@Capewearer
@Capewearer 7 сағат бұрын
@@hoyoreverse many assembly languages allow you to define macros. So there's still a difference.
@Apoque
@Apoque 41 минут бұрын
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.
@amedeoalf
@amedeoalf 11 сағат бұрын
Feels good to arrive just in time for mista zozin upload
@eckhardt092
@eckhardt092 8 сағат бұрын
Yesu yesu yesu
@AirBender-s2p
@AirBender-s2p 7 сағат бұрын
fire lord sozin ?
@lorenzo42p
@lorenzo42p 4 сағат бұрын
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.
@RobertFletcherOBE
@RobertFletcherOBE 9 сағат бұрын
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'
@khuntasaurus88
@khuntasaurus88 8 сағат бұрын
@@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_a6f
@Daniel_Zhu_a6f 8 сағат бұрын
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.
@cheebadigga4092
@cheebadigga4092 6 сағат бұрын
@@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)
@rogo7330
@rogo7330 6 сағат бұрын
@@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.
@thesenamesaretaken
@thesenamesaretaken 5 сағат бұрын
​@@khuntasaurus88 >Exception doesn't implement BaseException Good old OOP
@danielchicoelamo
@danielchicoelamo 10 сағат бұрын
It is not where u study, it is how u think and solve problems, thanks for ur examples
@avhd187
@avhd187 6 сағат бұрын
C and Python goes together. There is no feud.
@ABaumstumpf
@ABaumstumpf 4 сағат бұрын
C does the work, Python dictates what works needs to be done.
@k1ngjulien_
@k1ngjulien_ 3 сағат бұрын
they are not enemies. in fact they're kissing, sloppy style
@chillydill4703
@chillydill4703 8 сағат бұрын
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 :)
@rogo7330
@rogo7330 6 сағат бұрын
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.
@000dr0g
@000dr0g 9 сағат бұрын
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.
@mmilerngruppe
@mmilerngruppe 49 минут бұрын
lovely cocroutine for pison
@psteven5
@psteven5 4 сағат бұрын
C would be peak if it had short shorts, long shorts, and short longs
@Capewearer
@Capewearer 7 сағат бұрын
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!
@DuskyDaily
@DuskyDaily 11 сағат бұрын
Hi Mr. Zozin 😁. Hehe Lazy evaluation, sounds a good next steo after exoloring cooperative async stuff.
@pan-gloowl
@pan-gloowl 11 сағат бұрын
Mr. Azozin
@bartlomiejodachowski
@bartlomiejodachowski 7 сағат бұрын
my peasant generator would be a function using static variables xD
@cheebadigga4092
@cheebadigga4092 7 сағат бұрын
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-2974
@at-2974 7 сағат бұрын
I swear the like counter went brrr the moment he created main.py file
@chri-k
@chri-k 6 сағат бұрын
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
@purpasmart_4831 Сағат бұрын
C++ is just a disaster in general.
@bernardcrnkovic3769
@bernardcrnkovic3769 6 сағат бұрын
29:40 same problem as "you need to wipe 4 times in order to know you only needed 3" 🤣
@Mirgeee
@Mirgeee 7 сағат бұрын
I am a simple man. I see zozin video, I click.
@atduyar
@atduyar 11 сағат бұрын
Great session btw.
@theodorealenas3171
@theodorealenas3171 11 сағат бұрын
I actually didn't expect that to be possible without changing the language parser.
@azharalibhutto1209
@azharalibhutto1209 3 сағат бұрын
Great 👍
@WarmNiceCozy
@WarmNiceCozy 9 сағат бұрын
I’m so excited. He programmed in python. 🎉
@iglobrothers645
@iglobrothers645 10 сағат бұрын
Are we ever going to see ZozinOS?
@GesteromTV
@GesteromTV 7 сағат бұрын
Jai will be GOAT when it came out
@matthartley6537
@matthartley6537 2 сағат бұрын
Do you have a source on C being faster than Python? Seems hard for me to believe
@joseoncrack
@joseoncrack Минут бұрын
😂
@k4r4m310.
@k4r4m310. 8 сағат бұрын
@y00t00b3r
@y00t00b3r 11 сағат бұрын
lol, I guess Mr. Azozin hasn't ever tried using generators in ECMAScript ?
@LeaoMartelo
@LeaoMartelo 10 сағат бұрын
Emacs script runs in the browser
@y00t00b3r
@y00t00b3r 9 сағат бұрын
@@LeaoMartelo read my post again
@LeaoMartelo
@LeaoMartelo 9 сағат бұрын
@y00t00b3r its a joke
@y00t00b3r
@y00t00b3r 6 сағат бұрын
@@LeaoMartelo YOU GOT ME !!! 😀
@bizarrecentral6032
@bizarrecentral6032 11 сағат бұрын
What development environment is this ? Looks very efficient.
@ReyLamurin
@ReyLamurin 11 сағат бұрын
Emacs
@hamiltonianpathondodecahed5236
@hamiltonianpathondodecahed5236 11 сағат бұрын
VSCode
@augustrum1358
@augustrum1358 11 сағат бұрын
man...
@GegoXaren
@GegoXaren 11 сағат бұрын
ed
@EnDeRBeaT
@EnDeRBeaT 11 сағат бұрын
pen and paper
@vilhola2187
@vilhola2187 9 сағат бұрын
how do you get gruber darker theme for terminal
@ferdynandkiepski5026
@ferdynandkiepski5026 10 сағат бұрын
Somewhat similar to std::generate in C++23.
@neraid
@neraid 8 сағат бұрын
$x can do this too and it's faster than Python
@alexmalinin2387
@alexmalinin2387 6 сағат бұрын
Showing generators via example in python and not in JS PepeHands
@ViniciusMiguel1988
@ViniciusMiguel1988 8 сағат бұрын
Oh no python no no
@elgalas
@elgalas 10 сағат бұрын
EmacsScript (JavaScript) has this too
@davinelulinvega
@davinelulinvega 9 сағат бұрын
It would be better for educational purposes to show generators in python console, "live mode", so to speak, since it's interpreted language
@ttt69420
@ttt69420 4 сағат бұрын
Isn't python just like a giant C wrapper
@mbarrio
@mbarrio 3 сағат бұрын
Isn't C just a big Microcode wrapper?
@ttt69420
@ttt69420 2 сағат бұрын
@@mbarrio I wasn't be abstract. Python is literally written in C.
@bagofmanytricks
@bagofmanytricks 8 сағат бұрын
This guy keeps jumping to the wrong premature conclusions like all the time
@namefreenargrom5694
@namefreenargrom5694 6 сағат бұрын
Do "defer" next. Is it even doable?
@Daniel_Zhu_a6f
@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.
@gsestream
@gsestream 10 сағат бұрын
actual usefulness? or just fun and games. asterisk simple jail.
@Heater-v1.0.0
@Heater-v1.0.0 9 сағат бұрын
Python? No. I hate snakes.
@TheCommunistRabbit
@TheCommunistRabbit 8 сағат бұрын
We'll that's one way to say you're not gay
@rasulseidagul
@rasulseidagul 7 сағат бұрын
So much complexity while a “generator” is just a struct and a switch case 😂
@User948Z7Z-w7n
@User948Z7Z-w7n 10 сағат бұрын
JavaScript can do this too
@TheCommunistRabbit
@TheCommunistRabbit 8 сағат бұрын
EmacsScript*
@AndrewTiger
@AndrewTiger 11 сағат бұрын
bliah
@Sitris-h7q
@Sitris-h7q 11 сағат бұрын
"Programming" in Python. Its called scripting brooo!! python is not language for real ROGRAMMERS
@Drudge.Miller
@Drudge.Miller 11 сағат бұрын
Yehar Bro, real PROGRAMMERS only program in real PROGRAMMING LANGUAGES!!!
@GegoXaren
@GegoXaren 11 сағат бұрын
Oooooooo!
@alejandroioio6784
@alejandroioio6784 8 сағат бұрын
Yes!!! Real programmers only use machine language!!!! Anything else is just frontend
@ABaumstumpf
@ABaumstumpf 4 сағат бұрын
@@alejandroioio6784 Real programmers just use butterflies.
@alejandroioio6784
@alejandroioio6784 3 сағат бұрын
@ABaumstumpf xd
@porknite
@porknite 9 сағат бұрын
I think everybody knows that C can do everything Python can do but better lmao
@Opharg
@Opharg 2 сағат бұрын
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.
@minirop
@minirop 10 сағат бұрын
a real nobhead.
@paca3107
@paca3107 7 сағат бұрын
Thumb up if you prefer python than c
@AndiPandi-yj7rc
@AndiPandi-yj7rc 5 сағат бұрын
Hell nah
What if all the world's biggest problems have the same solution?
24:52
They Made a Sequel to C
1:53:24
Tsoding Daily
Рет қаралды 118 М.
Reinforcement Learning Course - Full Machine Learning Tutorial
3:55:27
freeCodeCamp.org
Рет қаралды 1 МЛН
This Library Turns C into Go
1:39:43
Tsoding Daily
Рет қаралды 40 М.
Should you learn C or Fortran in 2024?
3:32
Coding Pepper
Рет қаралды 631
how does this keep happening?
6:32
Low Level
Рет қаралды 95 М.
What do you need select/poll/epoll for
2:11:21
Tsoding Daily
Рет қаралды 31 М.
I made Coroutines from scratch
2:09:30
Tsoding Daily
Рет қаралды 38 М.
You Don't Know Network Programming
2:20:44
Tsoding Daily
Рет қаралды 76 М.
Quiet Night: Deep Sleep Music with Black Screen - Fall Asleep with Ambient Music
3:05:46
The Stanley Parable: Ultra Deluxe | FULL GAME
3:38:29
Markiplier
Рет қаралды 45 МЛН