Prefer to read instead of watching? Check out the article version of this video: aaronfrancis.com/2024/clean-up-after-yourself-618236cb
@haradalucas
Ай бұрын
Genuinely a very refreshing format!
@pixtweaks393
Ай бұрын
Thnaks for "Sleep: : for(1)->seconds ;"! I can't imagine a better example to demontarate overuse of OOP :)
@ISKLEMMI
Ай бұрын
There's that intro! As someone who just recently started learning Laravel, I like this series idea.
@ahmad-murery
Ай бұрын
I'll go with the stack concept as it gives us a better control on when to cleanup. BTW, PHP isn't bad, it's just the way we write our code, although I agree with everything else. Thanks Aaron!
@depafrom5277
Ай бұрын
unset($foo) the GC will remove $foo when its no longer needed, and $foo = null immediately releases the memory, maybe also look at PHP weakmaps and lazy objects
@razt3757
Ай бұрын
I gotta give it to you, that's a smart way of advertising and not be annoying for the viewer. Always looking out for more videos of yours. Also php is kinda cool imo, we've got a lot of useful syntax other languages don't even bother with, like falsy-safe operator, traits, arrow functions (I actually love the `fn` part), we'll probably even get structs so OOP haters can deal away with classes completely (thank god!). We just need those native generics to land sometime and it will be a breeze!
@LenWoodward
Ай бұрын
I've been dabbling in some C recently, because I've had this idea gnawing at me for months: "what would it look like if PHP had a `defer` keyword" This is exactly the type of stuff that could use it.
@aarondfrancis
Ай бұрын
Oh that's interesting... I don't know what that means but it sounds excellent
@LenWoodward
Ай бұрын
@@aarondfrancis I learned about the `defer` keyword when working through `Building an Interpreter in Go`, and it basically just keeps cleanup code right next to the other stuff, and runs it last. So you can use it to close file handles, close socket connections, etc. So you'd do something like ``` $this->startNgrok(); defer $this->stopNgrok(): // ... ``` It'd take some real thought work, like, does the a deferred action still run after an exception is thrown, etc. I think exploring other languages has been super useful!
@depafrom5277
Ай бұрын
@@LenWoodward I understand Defer in an Async scenario, not quite sure what the intent is in your example? If its about freeing up memory then one can use PHP unset(...) or null assignment, with unset($foo) the GC will remove $foo when its no longer needed, and $foo = null; immediately releases the memory. But this is probably not what you meant?
@LenWoodward
Ай бұрын
@@depafrom5277 that's not quite what I meant, because you're right, freeing up memory by unsetting variables is already handled by the garbage collector. This would be a way to make sure that we can group cleanup code next to the code that makes it necessary. In this context cleanup doesn't refer to memory, it could really apply to anything. Like if we're saving a .lock file somewhere, doing some work, then deleting the .lock file. Now we could just have `defer File::delete('action.lock');` on the line after we create it. This is a poor example, but still, we could use it to close open file handles, sockets that have been left open, to kill background processes that we spawned, etc
@samldev
Ай бұрын
If you haven’t tried the pineapple spindrift, definitely add that one to the list. My favorite flavor, as a spindrift connoisseur
@RickyJohnston
Ай бұрын
This was great! Love these patterns.
@varunks9855
Ай бұрын
This is amazing, keep it going Mr Francis
@Khalyomede
Ай бұрын
Looking forward for next topics keep going cool vibes🍹
@thedailycutline278
Ай бұрын
the way you explain concepts is truly amazing, you truly understand everything about php so deep and you really are a great tutor than any other nextjs tutor out there, please start teaching us Nextjs because, unfortunately, i still hate php to the core!!
@ofmouseandman1316
Ай бұрын
Nice tips and tricks (and I'm thirsty) In php there is "register_shutdown_function" which can be useful because it execute even after a timeout In go there is something similar using the defer keyword
@stefanzweifel
Ай бұрын
What a genuinely great tutorial Learnt something new today.
@sameeeey
Ай бұрын
Love this! That intro was superb 👌
@Pekz00r
Ай бұрын
Great video as usual and an interesting topic! I like the way you declare the start and cleanup functions together, but I think the first option is a bit messy and pollutes the main method with variables and unnecessary reason to change(adding callback logic). The second method is much cleaner. The cleanup method could probably also be in a __destruct().
@UsatiyNyan
Ай бұрын
The first approach was functional and, I’d argue, the best. If only php supported defer keyword or destructors, it would have been even better.
@kirayamato6128
Ай бұрын
Love you Aaron 😍
@alcymn
Ай бұрын
Just watched the new Deadpool recently and I can't help but confuse you with Ryan Reynolds because of your profile picture haha. Anyway, keep up the good work, Aaron!
@heavenaldrico
Ай бұрын
Awesome
@kuldar
Ай бұрын
This channel is approaching MKBHD levels of polish. 👌
@cb33
Ай бұрын
Spindrift lemon rules
@aarondfrancis
Ай бұрын
Number one (so far)
@wcrb15
Ай бұрын
Spindrift is goated! I drink way too many lol
@kevinbatdorf
Ай бұрын
Any downside to processing the callback stack in __destruct()?
@aarondfrancis
Ай бұрын
Oh that's an interesting idea! Not that I can think of at the momemt
@depafrom5277
Ай бұрын
Problem is __destruct is called just before the end of code execution, and one will probably want to "clean up" during code execution - unset($foo) the GC will remove $foo when its no longer needed, and $foo = null immediately releases the memory, maybe also look at PHP weakmaps and lazy objects.
@yasdinho76
Ай бұрын
Nice video ! What color scheme are you using in your IDE please ?
@raviel498
Ай бұрын
Thanks.
@raenastra
Ай бұрын
Love it! Reminds me of the "defer" keyword in Go
@Cyber_Lanka
Ай бұрын
Awesome video as well. Do you dislike dark themes? 😂
@raybarrera9002
Ай бұрын
Spindrift #1
@valcron-1000
Ай бұрын
What about exceptions? If one of your cleanup function throws then the remaining functions will not be called
@aarondfrancis
Ай бұрын
True! Probably best to wrap the individual failable actions in a try catch, or every call in a try catch. These two should never fail because I check that the process is running and I used the @ sign to suppress the unlink errors, but still a good practice.
@AlbertCloete
Ай бұрын
Is it legal to do functional programming in PHP?
@Dragan-q1u
Ай бұрын
Will you continue with LifeOS live series?
@aarondfrancis
Ай бұрын
Yes! Just wrapping up a few things this week
@bholmesdev
Ай бұрын
Okay good tip, but using *lemon* as your Spindrift pick will really hurt the rankings. Demand a redraw with either raspberry lime or pineapple.
@aarondfrancis
Ай бұрын
Don't worry, we're doing all flavors!
@jd-lien
Ай бұрын
Are you open to sponsorships from beverage companies yet?
Пікірлер: 47