You are providing fallback values in Golang wrong!

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

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

  • @swadhikarc7858
    @swadhikarc7858 4 หลายเดือนก่อน +4

    sorting use case was just brilliant. Complex logic portrayed with simpler example!

    • @FloWoelki
      @FloWoelki  4 หลายเดือนก่อน +2

      There was just some sort of beauty in it, right? :D

    • @swadhikarc7858
      @swadhikarc7858 2 หลายเดือนก่อน

      @@FloWoelki exactly bro

  • @sheikhAbdelrahman
    @sheikhAbdelrahman 2 หลายเดือนก่อน

    Great video Flo. Greetings from Egypt!

    • @FloWoelki
      @FloWoelki  2 หลายเดือนก่อน

      Thank you for watching! :) Greetings back!

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

    Hi Flo, this is a great nugget of knowledge. The cmp package has escaped me until watching this video. One of golangs biggest mistakes in my opinion is the lack of a ternary operator resulting in either ugly code or complicated work arounds. My complicated weapon of choice up to now has been to use a third party package lo which provides functional programming features, one of which is a ternary function. However this could be replaced by using the cmp.Or that you so greatly describe in this presentation. I have hundreds of cases in my own projects that could be replaced using this technique, so thanks. (As good as the cmp.Or solution is, it is still a sub optimal solution in many cases, because all entries have to be evaluated first. If the golang team gave us a proper ternary operator then we wouldn’t have this problem 😤. I read their many foolish arguments about why they omit this feature on the grounds of simplicity, but by omitting it they greatly force us to write either crap or inefficient clumsy code. I just think now they don’t want to provide it because that would mean them having to admit they are wrong; especially when you consider the unnecessary complicated features they have given us, most recently the ability to iterate a function which I remember you describing in a recent video about the new features of golang version 1.23. I wrote my own iterators ages ago and I see no reason to replace mine with theirs)

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

    Hi again Flo, I noticed a really nice feature that you’re using in your ide (vscode?) that I’m wondering how you achieve. When writing the code to invoke a function with a complicated signature I noticed that somehow as you type, the full signature is spit out into the editor window which you type over. How do you do this? Which plugin is responsible for this? I would appreciate it if you could share this as I have been in this situation many frustrating times and the way I do it is frankly prehistoric; I F2 the function name, then manually copy the signature and paste it back into my own code into a comment, then proceed from there. I need to stop dragging my knuckles along the floor as quite frankly then are getting pretty sore! Thanks in advance

  • @CoolestPossibleName
    @CoolestPossibleName 6 หลายเดือนก่อน +1

    I don't think I'll ever use this function. What if one of the functions return additional values or error?
    usually I do this
    func getPort(defaultPort string) string {
    port := getPortFromFlag()
    if port != "" {
    return port
    }
    port = os.Getenv("PORT")
    if port != "" {
    return port
    }
    port = getPortFromWhatever()
    if port != "" {
    return port
    }
    return defaultPort
    }
    and call that function in the main function.
    The cmp.Compare() function cool I guess, but the use case is really specific

    • @FloWoelki
      @FloWoelki  6 หลายเดือนก่อน +2

      I agree; it really depends on the specific use case. But overall, it would be nice to have additional syntactical sugar for your Go code.

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

    Slice inside the function should be copied.. not just assigned pointer to the same "parameter" slice sorted := make([]employee, len(orig))
    copy(sorted, orig) right?

  • @what1heh3ck
    @what1heh3ck 6 หลายเดือนก่อน

    what’s your ide and font? btw nice usecase. I think I might going to use that in future

    • @FloWoelki
      @FloWoelki  6 หลายเดือนก่อน +1

      Awesome stuff! :)
      Generally, I do use Zed with the official GitHub theme. The GitHub theme is also available for vsc or nvim.

    • @HarmonicaTool
      @HarmonicaTool 4 หลายเดือนก่อน

      Would you consider a video on using zed with Golang?

    • @FloWoelki
      @FloWoelki  4 หลายเดือนก่อน

      @@HarmonicaTool sure. Do you have something specific in mind?

    • @HarmonicaTool
      @HarmonicaTool 4 หลายเดือนก่อน

      @FloWoelki It feels as if VSCode was the standard today and everything else needed an explanation. So, why did you choose Zed, to whom would you recommend it and what did you do for it to work so well with Golang?

    • @FloWoelki
      @FloWoelki  4 หลายเดือนก่อน +1

      @@HarmonicaTool interesting idea. Thanks I'll try to think of a possible video :)

  • @timbrockley
    @timbrockley 4 หลายเดือนก่อน

    nice explanation

    • @FloWoelki
      @FloWoelki  4 หลายเดือนก่อน

      Thank you for the feedback :)

  • @chhiethearith9525
    @chhiethearith9525 4 หลายเดือนก่อน

    nice video

    • @FloWoelki
      @FloWoelki  4 หลายเดือนก่อน

      Thank you :)