Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (12 sloc) 1.97 KB

Would be good to log variable changes in debugging mode - Golang

Problem(what I wanted to do)

Golang is capable of doing a lot of stuff very efficiently, but as someone who just started out with it there's a lot of struggle comes with it. I've been thinking of ways to improve developers' experience with using it until coming across this python project recently called PySnooper.

What I actually did

I was hoping golang would have something similar to PySnooper(https://github.com/cool-RR/PySnooper) basically provide developers an easy way/instrumentation to clearly log every variable changes as the program runs. The original implementation of PySnooper relies largely on the fact that Python provides the ability to trace a program as it runs via method sys.settrace(callback) which allows developers to set callback function for tracing every line execution.

For golang, it has this module runtime/trace which lets developers do similar things, but only via manually emitting. Everytime if I need to check out some intermediate values produced I will have to manually emit the value and have it shown in context. e.g trace.Log(ctx, "orderID", orderID) This is somewhat useful but seems a bit overhead to instrument.

Why that wasn't great

Golang is different from Python as it's a compile language instead of script language. It also provides this ability to trace via runtime/trace package but in order to use that:

1. Developer has to manually emit variable by doing something like `trace.Log(...)`, this could easily get boring and tiresome.

2. They also have to know a lot of concepts like context to get instrument the trace correctly and it's not friendly experience.

Note

I think ability to log every change with simple instrumentation would encourge people to use the language and understand it more. But I think to support this feature, golang has to at least provide some kind of callback when tracing happens. Just like how sys.settrace does for Python.

You can’t perform that action at this time.