justforfunc #26: why are there nil channels in Go?

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

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

  • @ethangarnier8416
    @ethangarnier8416 7 лет назад +28

    I love this format, short but teaches a valuable lesson.

  • @zhengchaodeng4107
    @zhengchaodeng4107 7 лет назад +1

    The background music at 11:24, and all the facial and body gesture from Francesc is so cute.

  • @aareooon2964
    @aareooon2964 7 лет назад +10

    That is incredibly informative. Thank you!

  • @kesuskim6072
    @kesuskim6072 7 лет назад +1

    channel concept is quite hard to get used to, but once get used to it, it is really awesome!
    and now I learn more about channel, it feels always learning new thing ;( I doubt I can say I know channel at all... maybe this time...!

  • @brianscott5335
    @brianscott5335 7 лет назад

    Great episode, really enjoyed the tips I learned from this short but very useful lesson

  • @MrGreen-kq4ds
    @MrGreen-kq4ds 4 года назад +1

    this is just perfect, thank you!
    I demand more tutorials like this!

  • @milossimicsimo
    @milossimicsimo 7 лет назад +1

    this is actually really great video! Good job man :D!

  • @ThisGuyRocksLikeCrazy
    @ThisGuyRocksLikeCrazy 7 лет назад

    Loved this episode. Please share more neat tricks with us.

  • @zerbitx
    @zerbitx 5 лет назад

    One little clarification. Around 6:24 he says that ok will be true/false if the channel is open or closed. It stays true if the channel is closed and still has values to consume. Here's a useless example, where the channel is filled to 2/3's capacity, then closed before we ever begin reading, but it can read all the values that were present when checking "ok" play.golang.org/p/8Q8zR1o5Mjz

    • @JustForFunc
      @JustForFunc  5 лет назад +1

      It's false only once there's no more values in the channel and it has been closed already.

  • @djthorpe
    @djthorpe 7 лет назад +1

    I was interested in how you merge a variable number of channels in the "merge" function. It turns out you could solve this by using "reflect.SelectCase" and then replace the "select" statement with "reflect.Select" - maybe less efficient than when you know the number of channels beforehand, but useful where you want to add/remove channels whilst your program is running.

    • @NicDade
      @NicDade 7 лет назад

      Benchmark reflect.Select before you do that to your code.

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      reflect: no no no no no no no
      there's much better ways of doing this ... and I've added this idea to my episode list!

    • @djthorpe
      @djthorpe 7 лет назад

      I'm not convinced it's a terrible approach but as Nic says, worth benchmarking. The other way of doing this I can think of is to fire off a go routine for every new channel you add and want to merge. Go routine ends when the incoming channel is closed, I guess?

  • @HerbertFischer
    @HerbertFischer 7 лет назад

    @Fransesc Could you please link to the episode about the Runtime Tracer that you mentioned at #8:32 in the video description?

    • @HerbertFischer
      @HerbertFischer 7 лет назад

      Found it: ruclips.net/video/ySy3sR1LFCQ/видео.html

  • @edwardrf
    @edwardrf 7 лет назад

    Greate video! Love the short format. More code reviews please!

  • @paulyeoh4266
    @paulyeoh4266 6 лет назад

    Awesome, very valuable as always, thank you for the excellent episode.

  • @rajendragosavi2233
    @rajendragosavi2233 3 года назад

    Thanks for sharing this. It is very helpful.

  • @tunedmystic1
    @tunedmystic1 7 лет назад

    Learned something new today. Thanks Francesc! 👍

  • @integrii
    @integrii 7 лет назад +9

    Fransec for president

    • @JustForFunc
      @JustForFunc  7 лет назад +3

      Francesc ... and no thanks, I'm good. Really 😅

    • @joonasfi
      @joonasfi 6 лет назад

      @@JustForFunc if you were working in the field of InfoSec, FranSec would be a pretty badass company name for you

  • @paracha3
    @paracha3 7 лет назад

    Very nice, short and informative.

  • @mhausenblas
    @mhausenblas 7 лет назад

    Awesome as usual! What's that epic audio towards the end, around 11:23? :)

    • @bboyfaja
      @bboyfaja 7 лет назад

      super mario:)

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      +Michael Hausenblas it's a secret! but I'm sure most people recognize

  • @madoksback
    @madoksback 6 лет назад

    I see lots of post about using channels and goroutines to create pipelines but nobody ever talks about testing such pipelines

  • @EnricoCandino
    @EnricoCandino 7 лет назад

    This was so simple and useful! Kudos!

  • @musale2277
    @musale2277 7 лет назад

    I enjoyed this episode. It was short and well explained.

  • @Goodvvine
    @Goodvvine 7 лет назад +1

    Hey, I've always wondered how is dependency injection handled in Go. Can you talk about that next or point me to other material?
    I've only used Java (So.. Spring/Guice and some other obscure library) which make things "simple" with annotations, but how does this work in Go?
    I guess it's not that comparable to Java because there are no things like classes, but on a large system how are objects created and passed around?

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Goodwine Carlos what are you trying to solve with dependency injection exactly?

    • @joecarter4512
      @joecarter4512 7 лет назад

      Facebook have a nice little dependency injection library on github I've used before. It's a little rough around the edges but it works.

    • @Goodvvine
      @Goodvvine 7 лет назад

      +JustForFunc, I'm just trying to figure out if Go has anything like Guice for Java or how should I be thinking about that. Joe Carter talked about github.com/facebookgo/inject which is close to what I'm looking for

    • @vladimirbauer6604
      @vladimirbauer6604 7 лет назад +3

      Stop thinking in terms of java when dealing with Go!

  • @lovekeys1908
    @lovekeys1908 6 лет назад

    Thanks, great format!

  • @LlamaPlaysZ
    @LlamaPlaysZ 6 лет назад

    what happens if the caller tries to recveive from the channel once its set to nil?

  • @mrvil
    @mrvil 3 года назад

    Thanks for explaining nil channel use case 😀

  • @Marlem80
    @Marlem80 2 года назад

    you took it from "100 mistakes and how to avoid them book", right? :)

  • @falko4499
    @falko4499 7 лет назад

    Does anybody know the rationale behind the decision to always return a pair of zero and false from a closed chan? Is it to recognize closed channels or are there other use cases?

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      false allows you to recognize a channel is closed vs someone sent a 0 through the channel
      the fact that the zero is returned it's because it needs to return something, and the zero value for ints is zero
      if your channel was of bools it would return false, false
      if it was pointers it would be nil, false
      etc

    • @falko4499
      @falko4499 7 лет назад

      Thanks! The more I learn about go, the more I value its design.

    • @celiazhen
      @celiazhen 7 лет назад

      Why "it needs to return something" after all? Why can't Go just makes it block the select case similar as nil channel once a channel is closed?

    • @falko4499
      @falko4499 7 лет назад

      Reading from a infinite blocking channel _outside_ of a select{}-Statement would cause the reading goroutine to stop working, since there is no timeout for a read from a chan. This would also be the case, when _all_ channels used in a select{}-Statement are closed&blocking. By assigning nil to a chan, you're basically saying "Yes, I know that this will block forever and can therefor be dangerous, but I know what I am doing: there still is another chan I intend to read from in the selectt{}-Statement"

  • @kalekold
    @kalekold 7 лет назад

    Read more about these kind of patterns here: nomad.uk.net/articles/interesting-ways-of-using-go-channels.html

  • @AlbertoRestifo
    @AlbertoRestifo 7 лет назад

    Owww yeah, a new just for func video!

  • @theyruinedyoutubeagain
    @theyruinedyoutubeagain 7 лет назад

    Great episode!

  • @ajzaff2
    @ajzaff2 6 лет назад

    Thanks for the func!

  • @RakeshWaghela
    @RakeshWaghela 6 лет назад

    THANK YOU
    THANK YOU
    THANK YOU !!!!!!!!!!!!

  • @youssefkhaya3331
    @youssefkhaya3331 3 года назад

    Thanks! I like this non nil channel ;)

  • @nexdev09
    @nexdev09 7 лет назад

    great video

  • @TimothyPeters
    @TimothyPeters 5 лет назад

    Good Job! Started yesterday, Now I think I'm getting addicted to the channel. xd.

  • @EssaAlshammri
    @EssaAlshammri 7 лет назад

    👍👍👍👍👍

  • @wayneashleyberry
    @wayneashleyberry 7 лет назад

    🎶 👍 👍 🎶

  • @gabrielparadiso2399
    @gabrielparadiso2399 5 лет назад

    Fucking awesome!

  • @while-loop
    @while-loop 7 лет назад

    Mind = blown

  • @invzhi4426
    @invzhi4426 7 лет назад

    awesome

  • @nicolasparada
    @nicolasparada 7 лет назад

    wow

  • @kinositajona
    @kinositajona 7 лет назад

    Very nice channel!
    I am currently learning go so that I can work on a repo I am following closely.
    github.com/lightningnetwork/lnd
    I would love if you could find something in there that you think is an interesting use of golang, or something you don’t like (and could be a good start of a pull request for golang beginners) for this repository.