Write Better GO Code: Composition

Поделиться
HTML-код
  • Опубликовано: 29 дек 2024
  • In Golang what is composition and how to use it to write better code?

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

  • @sidreddy7030
    @sidreddy7030 6 месяцев назад +4

    This is so elegant. Can’t wait to see more go content in this channel

  • @sadhakbj
    @sadhakbj 6 месяцев назад +4

    More premium go contents please.

  • @ahmethatipoglu8306
    @ahmethatipoglu8306 6 месяцев назад +1

    Nice video. I have a one nit here though to raise
    in 100 go mistakes there is a section about embedding saying the following:
    > What can we say about type embedding? First, let’s note that it’s rarely a necessity,
    > and it means that whatever the use case, we can probably solve it as well without type embedding.
    > Type embedding is mainly used for convenience: in most cases, to promote behaviors.
    and then it also says
    > Using type embedding consciously by keeping these constraints in mind can help avoid
    > boilerplate code with additional forwarding methods. However, let’s make sure we don’t do it
    > solely for cosmetics and not promote elements that should remain hidden
    given the above, what would you do differently? (I still haven't decided which is better yet tbh)
    Another question I have is I see you using `database.GetGuestFeatures()` which makes me believe you have a function `GetGuestFeatures()` under a `database` package. My question is how would you unit test HasFeature function here?

    • @mr_mux408
      @mr_mux408  6 месяцев назад +1

      The book gives an example where embeddings work well, ie where you want to avoid method forwarding, which is the case for us here.
      As for testing, you can mock out the database, see: github.com/stretchr/testify

  • @katungiyassin9947
    @katungiyassin9947 6 месяцев назад +1

    Good work Mux. Which Vs code theme is close to what you're using

  • @yuxiang4218
    @yuxiang4218 6 месяцев назад +1

    great example! Thanks for sharing

  • @norayrsargsyan2402
    @norayrsargsyan2402 6 месяцев назад +2

    Thank you so much for the content! What app do you use for code animations?

    • @mr_mux408
      @mr_mux408  6 месяцев назад

      I edit in Final Cut Pro and got a script I wrote for Neovim to type out the code.

    • @norayrsargsyan2402
      @norayrsargsyan2402 6 месяцев назад

      @@mr_mux408 Thank you so much, animation looks cool!

  • @nabinsaud4688
    @nabinsaud4688 6 месяцев назад +1

    Can you share the github code for this ?

  • @serajal-dinhaqiqi6292
    @serajal-dinhaqiqi6292 Месяц назад

    Great