Go Debugging with Delve, or No More Fmt.Printfs

91 points by tpaschalis 5 years ago | 21 comments
  • sn_master 5 years ago
    Coming to Go from C#, I was shocked at how poor the debugging experience was, even inside Google itself (I worked at GCP for less than a year).

    I don't get the mentality of people who don't feel the importance and satisfaction of being able to step through their code line-by-line and see everything coming to life in a debugger window, even if its for sake of watching it, not for finding a code bug. Some people seem to never have used one for years and they take it as a sign of weakness if someone says they need one to find a bug rather than looking at the code.

    I haven't and if its up to me, I would never use Go again, just because of the piss poor debugging experience in a language that's so new. Google engineer's mentality is very old school and anyone who enjoyed the beauty of conditional breakpoints and step-through debugging in modern IDEs will know exactly what I am talking about. Go is so new yet built with incredibly ancient mentality.

    • buffrr 5 years ago
      You should try Jetbrains Goland if you're looking for a modern IDE with a great debugging experience [0]. If you're talking about visual studio being modern, i don't think that's true. I have used it recently and i was surprised by how outdated it is (maybe i'm not used to it). Also, I can't seem to do any changes while the code is running. That's very annoying.

      [0]https://www.jetbrains.com/go/

      • pjmlp 5 years ago
        You should have a try at Android NDK's, it is exactly that kind of experience, they only started changing it due to the backslash of game developers.

        Not even game consoles are as bad.

        Nowadays it has gotten much better versus the Android 2.1 days, and after 10 years it still isn't where Apple, Microsoft, Sony, Nintendo platforms are today.

        • Thaxll 5 years ago
          Delve works just fine.
        • zaphar 5 years ago
          I occasionally feel the need to use a debugger. But nothing beats the ease and power of the humble printf in all it's forms in all languages. Sometimes you need a debugger. But you can get really far with just a printf.
          • leetrout 5 years ago
            Delve is great and debuggers in general are some of the best tools but to take the title at face value diminishes the value of the unassuming print facilities in every language.

            There’s a time and place for proper debuggers and (more?) time and place for a simple print statement in my humble opinion.

            • mkchoi212 5 years ago
              I remember trying out Delve about a year ago while it was still in its infancy and don't remember there being commands like `goroutines`; I may be wrong. The overall experience wasn't all that good to be honest.

              My initial impressions of delve was "Oh it's basically GDB for Go". But seems like the debugger has become more stable and more mature over the years by shipping language specific commands; like `goroutines`.

              • tpaschalis 5 years ago
                Yes, the project has gone a long way, as it's being used by what may be the two most prominent development environments for Go (VSCode and Jetbrains Goland).

                GDB still has a lot of value if you're working with a non-amd64 architecture or want to dive into cgo parts of a codebase, but Delve is a great addition to your toolbelt!

              • macrael 5 years ago
                The only thing I've seen that seems genuinely better than print debugging most of the time is the Playground concept, which is just print debugging automatically for every line of your program. Debuggers seem like they are useful sometimes, especially if it takes a lot to get into the state you want to debug, but focusing on making small rapid tests and printing lines that are interesting to you seems to keep me from ever actually bothering to setup delve.
                • tpaschalis 5 years ago
                  I was initially on the same side. But setting things up is a simple `go get`, and when you want to dive into more complex scenarios, such as concurrency-related bugs, a debugger can save the day!

                  I'd urge you to give it a spin next time you come across a weird bug ^^

                  • outworlder 5 years ago
                    > which is just print debugging automatically for every line of your program

                    Like... a REPL?

                    • macrael 5 years ago
                      Playgrounds are like a REPL but they are constantly reevaluating your code from the beginning, so you can edit code anywhere in the file and see how it changes everything.
                  • tech_dreamer 5 years ago
                    Go plugin for VS Code has first class support for delve (as well as Emacs) - I have been using it for more than a year!
                    • pizza234 5 years ago
                      It has support, but definitely not first class - I just tried a short time ago, and it wasn't possible to invoke functions while debugging; GitHub issue here: https://github.com/microsoft/vscode-go/issues/2655.
                      • sn_master 5 years ago
                        Its a problem with the Go compiler. Even IntelliJ doesn't support that, and its annoying AF.
                    • d0100 5 years ago
                      As a lifelong printf debugger in many languages, what I'd prefer is to be able to send my printf's into different streams and have a scrollable, filterable and searchable console for each stream

                      Kinda like the console in web developer tools (F12)

                      • manfredo 5 years ago
                        Print a known prefix every time you log. Or slap together a simple logging module that adds said prefix. Then to browse, use `tail -f log_file.txt | grep "PREFIX - "`. Console tabs makes it easy enough so that doing this with a bash script and opening tabs for each log prefix has fulfilled my need for such a tool.
                        • merlinsbrain 5 years ago
                          Are you looking for the log module, but with a UI on top of it (something like splunk, but for local development)?
                          • bubersson 5 years ago
                            I think we all ultimately want Chrome DevTools features for Go :)
                        • btashton 5 years ago
                          Does anyone have a good workflow for spanning go->cgo. I have found it very hard to code and debug in the space. I end up using gdb, but that lacks a lot of the go context and you cannot go into the c code with delve.
                          • jonathanoliver 5 years ago
                            This is where I typically resorted to printf statements in pure C.
                          • 5 years ago