7 common mistakes in Go and when to avoid them by Steve Francia (Docker)

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • Steve Francia talks about most common mistakes in Go #golang and how to avoid them.
    ABOUT DATA COUNCIL:
    Data Council (www.datacouncil.ai/) is a community and conference series that provides data professionals with the learning and networking opportunities they need to grow their careers. Make sure to subscribe to our channel for more videos, including DC_THURS, our series of live online interviews with leading data professionals from top open source projects and startups.
    FOLLOW DATA COUNCIL:
    Twitter: / datacouncilai
    LinkedIn: / datacouncil-ai
    Facebook: / datacouncilai
    Eventbrite: www.eventbrite.com/o/data-cou...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 86

  • @hz8711
    @hz8711 2 ปีที่แล้ว +6

    These kinds of talks where the presenter is a true expert in his field.

  • @marioskrlec6595
    @marioskrlec6595 4 ปีที่แล้ว +85

    I'm on a Go youtube lectures spree and every time a finish one of them, I wanna refactor all the code I've done so far :)

    • @prakashsharma-uv4pj
      @prakashsharma-uv4pj 4 ปีที่แล้ว

      Please share the channel url

    • @moriumbegum4180
      @moriumbegum4180 3 ปีที่แล้ว

      P

    • @shiskeyoffles
      @shiskeyoffles 3 ปีที่แล้ว

      @@prakashsharma-uv4pj ??

    • @graysonelias8334
      @graysonelias8334 2 ปีที่แล้ว

      You probably dont care but does someone know a tool to log back into an Instagram account??
      I was dumb forgot my password. I appreciate any tips you can offer me!

    • @MrSkinkarde
      @MrSkinkarde 2 ปีที่แล้ว

      Why don’t you make actual code ?

  • @bryanenglish7841
    @bryanenglish7841 3 ปีที่แล้ว +6

    Still easily one of the best Go "best practices" video on youtube

  • @chmod0644
    @chmod0644 9 ปีที่แล้ว +16

    Good talk. Hugo powers my blog, and I love it!

  • @jengo1
    @jengo1 7 ปีที่แล้ว +7

    Fantastic talk! I am new to go and had no idea on the proper way to handle errors. I am off to fix my code :D

  • @malcolmgdavis
    @malcolmgdavis 3 หลายเดือนก่อน +1

    Pointer vs. Value discussion:
    Based on the Method vs. Function discussion, ADT should be strictly adhered to. Operations that modify the ADT are modeled as functions that take the old state as an argument and return the new state as part of the result. In other words, a function should enforce immutability.
    The ADT approach helps with concurrency, making the code cleaner and easier to read. As an API user, I shouldn't worry about the state changing when I pass a structure.
    Of course, the pure ADT model's problem is memory consumption. That's why ADT models are generally implemented in VMs that can routinely find old structures without references and remove them from memory.

  • @guitaripod
    @guitaripod 2 ปีที่แล้ว

    Good talk. It's cool to watch this in 2022, as it can be considered ancient relative to Go's lifetime

  • @impaque
    @impaque 6 ปีที่แล้ว +2

    Great stuff, thanks for the lecture!

  • @naikrovek
    @naikrovek 6 ปีที่แล้ว +45

    There needs to be a book on these. He's racing through concepts that could use a lot more detail.

  • @CheyneWallace
    @CheyneWallace 5 ปีที่แล้ว +1

    Really great talk. Thanks for this

  • @xmlviking
    @xmlviking 8 ปีที่แล้ว +11

    Excellent talk I really appreciated the code examples :) Nicely done sir.

  • @brucewang2072
    @brucewang2072 5 ปีที่แล้ว +1

    Very helpful, Steve!

  • @castmetal
    @castmetal 2 ปีที่แล้ว

    Thank you very much! Great presentation to us!

  • @kkmingming
    @kkmingming 5 ปีที่แล้ว +1

    You are a rock star!!!

  • @skylvid
    @skylvid 6 ปีที่แล้ว

    Awesome talk. Good sound too.

  • @DenisG631
    @DenisG631 5 ปีที่แล้ว +8

    Methods not necessary imply mutation, therefore generating shortcodes (13:00) can be a method as well, maybe even a lazy var which is instantiated only once.
    Languages like C++/Swift have const/mutating keywords for indicating a method mutating or not mutating its fields

    • @WesRoberts42
      @WesRoberts42 5 ปีที่แล้ว +2

      I agree, the method vs function idea smells like a false dichotomy

    • @youtux2
      @youtux2 4 ปีที่แล้ว

      Yeah I remember the "const" keyword in C++ to declare methods that would not write to the object state...
      Thanks for mentioning :)

    • @daniellee3987
      @daniellee3987 ปีที่แล้ว

      Agreed. Say if there are bunch of functions that always reference the same data type to perform some computation, naturally I would feel its more cohesive if those functions and the data belongs together, the data being the state and functions being the methods.

  • @mikei4min
    @mikei4min 7 ปีที่แล้ว

    Great!

  • @nano_sweet
    @nano_sweet 4 ปีที่แล้ว +31

    I sincerely believe that io.Reader and io.Writer are the two most powerful interfaces in the language. They're so underrated that it kind of makes me sad.

    • @BRUHItsABunny
      @BRUHItsABunny 4 ปีที่แล้ว +1

      i used to dislike them until i finally understood Go polymorphism

    • @richardchaven
      @richardchaven 4 ปีที่แล้ว

      ahhh. it makes me remember my younger days with TStrings ...

    • @mateoleoncamacho3222
      @mateoleoncamacho3222 2 ปีที่แล้ว

      Agreed. And nice pfp btw.

  • @malinyamato2291
    @malinyamato2291 7 ปีที่แล้ว

    great sensei .... got me up to speed on docker.

  • @shahmiBro1
    @shahmiBro1 5 ปีที่แล้ว

    great talk;

  • @AndreiDinTheHouse
    @AndreiDinTheHouse 3 ปีที่แล้ว +2

    Pointers vs values - it's not just about usage. "If you want to share it, use a pointer" is a pretty contextless way to describe an issue that can easily become sensitive. Don't share unless you absolutely need to is a better way because otherwise a good starter is: I'll share because it's more flexible and I'll see about it later. But memory allocation is an important point as overusing pointers is a sure way to shoot yourself in the foot sooner rather than later.

  • @toofracing7104
    @toofracing7104 2 ปีที่แล้ว

    Really good stuff!

  • @yotubecreators47
    @yotubecreators47 5 ปีที่แล้ว +1

    Thaaaaank you, some one should collect all these pull request reviews and upload it in one website with git diff + comments :D

  • @pengdu7751
    @pengdu7751 4 ปีที่แล้ว

    great talk

  • @classicguy7813
    @classicguy7813 2 ปีที่แล้ว

    Sirrrr, it is great 👍

  • @omonkerman
    @omonkerman 6 ปีที่แล้ว +2

    COOL. GOT IT!!! 😆

  • @watcher8582
    @watcher8582 5 ปีที่แล้ว

    Thanks

  • @MaximeFRYSOU
    @MaximeFRYSOU 4 ปีที่แล้ว +1

    If a method is supposed to modify the state (vs functions), how come you wouldn't use a pointer in a receiver...?

  • @sanketg10
    @sanketg10 6 ปีที่แล้ว +1

    Really good talk! I learnt a lot. Am coming from Python!

    • @a0um
      @a0um ปีที่แล้ว

      Hey, if I may ask: how many years of Python coding have you done? What made you want to try Go? Are you still doing Go?

  • @saimonshaplygin7867
    @saimonshaplygin7867 3 ปีที่แล้ว +34

    My video tags and descriptions:
    1) Don't user interfaces 3:19
    2) Don't use io.Reader & io.Writer 6:24
    3) Requiring brod interface 8:44
    4) Method vs function 10:41
    5) Pointer Vs Value 14:58
    6) Error is does not a string 16:56
    7) To be safe or not to be 22:14
    P.S. Top secret skill: 24:56

  • @jeeplin6529
    @jeeplin6529 7 ปีที่แล้ว +28

    i am from china. and learn a lot from this video. tkx

    • @notangryjustdismayed
      @notangryjustdismayed 7 ปีที่แล้ว +3

      i am from canada, and i also learned a lot from this video.

    • @XYZ-ee8fl
      @XYZ-ee8fl 6 ปีที่แล้ว +10

      I am a Chinese living in Canada, I learned two tons from this video.

    • @ngocha5354
      @ngocha5354 6 ปีที่แล้ว

      I thought China banned TH-cam?

    • @Harry-qh5rt
      @Harry-qh5rt 6 ปีที่แล้ว

      I'm Canadian living in Canada and dereferencing a pointer is faster than resolving a variable name to value (symbols table lookup, making a copy of the data, etc). If you have the need for speed, then grab a dog and make it a pointer! Equally important is that reference by value is making a copy of the data, and then you get into the deep copy versus shallow copy issues (not sure yet how GO handles this). Major pain in the ass.
      I am new to GO, but not to C and other object oriented languages (e.g. smalltalk, C#, etc.). The trade off always has been speed versus code manageability.
      So you have to ask yourself, do you feel lucky? Well, do ya punk?

    • @arnold6644
      @arnold6644 6 ปีที่แล้ว +2

      im from china too, and learn now. by the way , we blocked youtube, but we never block knowledge

  • @pavelerokhin1512
    @pavelerokhin1512 ปีที่แล้ว

    nice!

  • @PetrGladkikh
    @PetrGladkikh 4 ปีที่แล้ว +3

    Almost all of them are not actually Go-specific mistakes. In particular those are the same for most JVM languages.

  • @alexanderzhang3972
    @alexanderzhang3972 4 ปีที่แล้ว

    受益匪浅。

  • @romand1979
    @romand1979 6 ปีที่แล้ว +1

    In the example for using functions over methods when no side effects are intended I'd argue that *Page should be Page instead - its a clearer argument for expressing no side-effects when you have a value receiver where side effects are not possible.

    • @xleelxz
      @xleelxz 6 ปีที่แล้ว +2

      TL;DR - Big Page cost twice the memory if passed by value.
      The readability is a bonus, but for large Pages, passing a pointer, even without modifying it, tends to be faster and more memory-efficient than passing by value and inevitably having the whole Page copied.

    • @romand1979
      @romand1979 6 ปีที่แล้ว +1

      Thanks. I'm just learning Golang but I love the idea of immutability.

  • @JacquesBoscq
    @JacquesBoscq 4 ปีที่แล้ว

    *gling* *gling* *gling* :}

  • @danaadalaide5648
    @danaadalaide5648 4 ปีที่แล้ว +2

    Just to be clear, maps are the only issue with concurrent access. A quick fix is to use sync.Map, but in a lot of cases using a drop-in replacement using a slice of struct{k,v string m Mutex} is slightly faster as you only need to lock on write with a high load of concurrent access.

  • @danaadalaide5648
    @danaadalaide5648 4 ปีที่แล้ว

    Also, internally.. Channels use mutexes anyway, so its not necessarily a bad thing to use..

  • @causeno1048
    @causeno1048 7 ปีที่แล้ว +1

    9:49: I would argue that this design principle applies to OO interfaces just as well.

    • @MrTripi
      @MrTripi 6 ปีที่แล้ว

      interface segregation.

    • @mister-ace
      @mister-ace 2 ปีที่แล้ว

      @@MrTripi yep

  • @robfielding8566
    @robfielding8566 8 ปีที่แล้ว +5

    the real problem with not using a reader is that the buffers might be really large.

  • @MariusKavaliauskas
    @MariusKavaliauskas 8 ปีที่แล้ว

    why are p.BaseFileName() and p.lineNumRawContentStart() not functions but methods? (at 13:04)

  • @johnnybravo4045
    @johnnybravo4045 2 ปีที่แล้ว

    The 8:30 slides shows that the code is not correct. Marshalling in a computer science is the process of transforming the memory representation of an object into a data format suitable for storage or transmission. In above slide the logic is actually doing the opposite. It transforms data coming from storage or transmission (in Reader) into memory representation v.config (out). The function in Viper should be called unmarshalConfig.

  • @aisi0o0taisi
    @aisi0o0taisi 4 ปีที่แล้ว +1

    Am I a complete noob or did you forgot to explain why those patterns are mistakes?

  • @user-th3th7no9s
    @user-th3th7no9s 5 ปีที่แล้ว +2

    how should i understand "time is ticking"?

    • @gemini_537
      @gemini_537 4 ปีที่แล้ว

      It is about concurrency, if it uses pointer instead of value, another goroutine might modify the value while this one is running.

    • @TV20
      @TV20 4 ปีที่แล้ว

      If you use time as pointer, some milisecond may elapsed untill t.sec and t.nsec call and that will cause function never works as expected. thats why you must use as value to copy current value and compare it in function

  • @goat5249
    @goat5249 3 ปีที่แล้ว +1

    Alright, you convinced me. I'm going to stop watching videos and go fail now!

  • @doufuwang
    @doufuwang 5 ปีที่แล้ว +1

    After reading some pieces of Go code of Ethereum I finally land here.

  • @dabbopabblo
    @dabbopabblo ปีที่แล้ว

    I don’t know if I’d say go is a new language anymore

  • @brians7100
    @brians7100 ปีที่แล้ว

    In Java, almost everything is a pointer.. things are passed by reference by default with the exception of primitive unboxed numerics

  • @ailuros_
    @ailuros_ 4 ปีที่แล้ว

    Except the fastest static site generator is not "Hugo" anymore but "Zola" (written in Rust). Good talk btw

  • @levani7851
    @levani7851 3 ปีที่แล้ว

    wild Francesc appears at the end

  • @9ShivamSharma
    @9ShivamSharma 4 ปีที่แล้ว

    12:53
    NO

  • @bukhorimuslim3412
    @bukhorimuslim3412 4 ปีที่แล้ว

    Biggest Mistake; Not Makimg Mistakes

  • @malcolmgdavis
    @malcolmgdavis 3 หลายเดือนก่อน

    The method vs. function debate is absurd. The presenter needs to learn or spend time with OO programming. Class methods don't have to be logically connected to states.
    I developed in C during the 80s. The problem with structs is that the data is the point of coupling. The class hides data. In OO, the focus is on behavior and not the state. The OO state can be anywhere and can change. The strategy allows the implementation of the module to be changed without disturbing the client programs.

  • @moneyluser5711
    @moneyluser5711 7 ปีที่แล้ว +3

    too slow and fluffy to be useful