Settings

Theme

Go Debugging with Delve, or No More Fmt.Printfs

tpaschalis.github.io

91 points by tpaschalis 6 years ago · 22 comments

Reader

sn_master 6 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 6 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 6 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 6 years ago

    Delve works just fine.

zaphar 6 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 6 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 6 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`.

  • tpaschalisOP 6 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 6 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.

  • tpaschalisOP 6 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 6 years ago

    > which is just print debugging automatically for every line of your program

    Like... a REPL?

    • macrael 6 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 6 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!

d0100 6 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 6 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 6 years ago

    Are you looking for the log module, but with a UI on top of it (something like splunk, but for local development)?

btashton 6 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.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection