dotGo 2014 - Dave Cheney - Functional options for friendly APIs

Поділитися
Вставка
  • Опубліковано 31 січ 2025

КОМЕНТАРІ • 10

  • @JasonStillwell
    @JasonStillwell 7 років тому +8

    He's not suggesting you do:
    timeout := func(srv *Server) {
    ...
    }]
    NewServer("localhost", timeout)
    Rather, he's suggesting that you do:
    NewServer("localhost", Timeout(60))
    Meaning that your package provides the various 2nd order function generators, as convenience configuration options.
    So a complex configured server might be created thusly
    NewServer("localhost",Timout(60),Speed(3600),Tls(certFile),Retry(3),LocallAddr("192.168.0.0.1"))

  • @doktoren99
    @doktoren99 4 роки тому +1

    Excellent talk :)

  • @peterarnt
    @peterarnt 10 років тому

    Dave, regarding the Speed() function: Did you intend to have the user call Speed() first creating a closure value, then calling Open()?
    -Pete

  • @pamad05
    @pamad05 10 років тому +3

    This is actually a pretty nifty..

  • @SankarP
    @SankarP 10 років тому +3

    The talk was interesting. I wish he had shown the code for looping through the Term options as well. Also, if he has looked less on the screen and more on the camera/audience, it would have been even better due to better eyecontact. Nevertheless, the talk was excellent.

  • @slavagurmanov2846
    @slavagurmanov2846 3 роки тому +2

    Great talk, but horrible filming. What the point to constantly show presenter instead of presentation, especially when he explains the code??

  • @kalekold
    @kalekold 2 роки тому +1

    Terrible advice. Whats wrong with:
    svr, _ := NewMyServer("localhost")
    svr.SetTimeout(60)
    svr.EnableTLS(cert)
    svr.SetRetry(3)
    or:
    opts := TermOptions{Speed: 115200, RawMode: true}
    t, _ := NewTerm("/dev/tty", opts)
    You don't need all these random disconnected functions. Clear is better than clever!!!

    • @nakaimcaddis5531
      @nakaimcaddis5531 Рік тому

      He addressed why he thought your second example wasn't to be preferred. As to the first example, having exported setters means that your type could not be immutable.
      Clear is better than clever, But if that concept is only ever applied to individual lines of code, it may force the higher level constructs those lines are part of into being more clever/complex overall.

    • @kalekold
      @kalekold Рік тому

      @@nakaimcaddis5531 His is the more 'clever' solution. Mine is much more simple.