Re:Why I Don't Like Golang (2016)
by blablabla123 on Thursday June 13, 2019 @02:59PM
(#20177665)
I must admit it's not perfect. What I usually do is add
_ = unusedVar
and then do the debugging stuff. Not sure why, but over time I ran into this procedure far less often but I do very pedantic error checking like
return fmt.Errorf("foo(%v): %v", fn, err)
and putting in checks sometimes that can return custom errors. So in my log I often end up with messages like "bar: baz: foo(/data.txt): open: file not found". Debugging usually means for me replacing
return err
with a more verbose
return fmt.Errorf("...: %v", err)
and adding mentioned checks and/or additional log messages. Either with the log package or logrus. (And possibly adding unit tests/factoring out code into separate functions.) This gives me information content like in a full Java stack trace but in one line.
But YMMV, probably it also depends what kind of software one writes.
But YMMV, probably it also depends what kind of software one writes.