Code tip: clean up after yourself (and a seltzer review)

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024

Комментарии • 48

  • @aarondfrancis
    @aarondfrancis  Месяц назад

    Prefer to read instead of watching? Check out the article version of this video: aaronfrancis.com/2024/clean-up-after-yourself-618236cb

  • @haradalucas
    @haradalucas 3 месяца назад +24

    Genuinely a very refreshing format!

  • @FarazSamapoor
    @FarazSamapoor Месяц назад

    I got really excited about the article version that I can always return to! Love it!

  • @pixtweaks393
    @pixtweaks393 3 месяца назад +3

    Thnaks for "Sleep: : for(1)->seconds ;"! I can't imagine a better example to demontarate overuse of OOP :)

  • @ISKLEMMI
    @ISKLEMMI 3 месяца назад +8

    There's that intro! As someone who just recently started learning Laravel, I like this series idea.

  • @RickyJohnston
    @RickyJohnston 2 месяца назад

    This was great! Love these patterns.

  • @thedailycutline278
    @thedailycutline278 3 месяца назад

    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!!

  • @stefanzweifel
    @stefanzweifel 3 месяца назад +2

    What a genuinely great tutorial Learnt something new today.

  • @varunks9855
    @varunks9855 3 месяца назад +2

    This is amazing, keep it going Mr Francis

  • @razt3757
    @razt3757 3 месяца назад +1

    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!

  • @ahmad-murery
    @ahmad-murery 3 месяца назад +5

    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
      @depafrom5277 2 месяца назад +1

      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

  • @samldev
    @samldev 3 месяца назад

    If you haven’t tried the pineapple spindrift, definitely add that one to the list. My favorite flavor, as a spindrift connoisseur

  • @Khalyomede
    @Khalyomede 3 месяца назад +1

    Looking forward for next topics keep going cool vibes🍹

  • @LenWoodward
    @LenWoodward 3 месяца назад +3

    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
      @aarondfrancis  3 месяца назад

      Oh that's interesting... I don't know what that means but it sounds excellent

    • @LenWoodward
      @LenWoodward 3 месяца назад

      @@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
      @depafrom5277 2 месяца назад

      @@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
      @LenWoodward 2 месяца назад

      @@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

  • @sameeeey
    @sameeeey 3 месяца назад +2

    Love this!
    That intro was superb 👌

  • @ofmouseandman1316
    @ofmouseandman1316 2 месяца назад

    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

  • @UsatiyNyan
    @UsatiyNyan 3 месяца назад +1

    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
    @kirayamato6128 3 месяца назад

    Love you Aaron 😍

  • @Pekz00r
    @Pekz00r 3 месяца назад

    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().

  • @alcymn
    @alcymn 3 месяца назад

    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!

  • @yasdinho76
    @yasdinho76 3 месяца назад

    Nice video !
    What color scheme are you using in your IDE please ?

  • @cb33
    @cb33 3 месяца назад +4

    Spindrift lemon rules

  • @wcrb15
    @wcrb15 3 месяца назад +1

    Spindrift is goated! I drink way too many lol

  • @kevinbatdorf
    @kevinbatdorf 3 месяца назад +2

    Any downside to processing the callback stack in __destruct()?

    • @aarondfrancis
      @aarondfrancis  3 месяца назад

      Oh that's an interesting idea! Not that I can think of at the momemt

    • @depafrom5277
      @depafrom5277 2 месяца назад

      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.

  • @heavenaldrico
    @heavenaldrico 3 месяца назад

    Awesome

  • @raviel498
    @raviel498 3 месяца назад

    Thanks.

  • @Cyber_Lanka
    @Cyber_Lanka 3 месяца назад

    Awesome video as well. Do you dislike dark themes? 😂

  • @kuldar
    @kuldar 3 месяца назад +1

    This channel is approaching MKBHD levels of polish. 👌

  • @Dragan-q1u
    @Dragan-q1u 3 месяца назад

    Will you continue with LifeOS live series?

    • @aarondfrancis
      @aarondfrancis  3 месяца назад +1

      Yes! Just wrapping up a few things this week

  • @bholmesdev
    @bholmesdev 3 месяца назад

    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
      @aarondfrancis  3 месяца назад

      Don't worry, we're doing all flavors!

  • @raybarrera9002
    @raybarrera9002 3 месяца назад

    Spindrift #1

  • @valcron-1000
    @valcron-1000 3 месяца назад

    What about exceptions? If one of your cleanup function throws then the remaining functions will not be called

    • @aarondfrancis
      @aarondfrancis  3 месяца назад +2

      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
    @AlbertCloete 3 месяца назад

    Is it legal to do functional programming in PHP?

  • @jd-lien
    @jd-lien 3 месяца назад

    Are you open to sponsorships from beverage companies yet?

    • @aarondfrancis
      @aarondfrancis  3 месяца назад +2

      1000% my beverage integrity is for sale

  • @raenastra
    @raenastra 3 месяца назад

    Love it! Reminds me of the "defer" keyword in Go

  • @rasmic
    @rasmic 3 месяца назад

    first