The unused variable thing (particularly with local variables) has caught many bugs quickly for me. If there's a package that I find myself always adding and removing, it's easy to write a function that freezes it. For instance, for the debugging print example:
func printf(f string, args ...interface{}) {
log.Printf(f, args...)
}
(I tend to use log for debugging prints rather than fmt, because it's guaranteed thread-safe, and it's easier to separate debugging prints from necessary prints at a later stage).On the few occasions that I've really felt I lacked a ternary operator, I've just coded one up for the occasion:
func either(cond bool, a, b string) string {
if cond {
return a
}
return b
}
No big deal. I do find myself writing little functions as building blocks quite a lot, but I think this works well. Functions are a great building block, and Go is great for assembling blocks.