Re:Spectro: Adventures in Go
by pbnjay on Saturday November 21, 2015 @11:46PM
(#10609119)
There's an odd, big complaint about numeric casts that culminates in this line of code:
Which could be improved greatly, and made a lot more readable with:
In my experience with Go over the last few years, any time I have this "ugh" moments it pays to take a step back. It's usually a code smell that there's a better way.
[ Parent
| on HN ]
You can do better -- fmt provides a way to give a dynamic width or precision as an int argument.
fmt.Fprintf(os.Stderr, "%*s %s\r", paddingWidth, "", legend)
I'd further wonder whether a separate padding calculation is needed at all (too lazy to go read the source on Github at the moment).I started with that, but there's no reason to use the formatting specifiers when the padding string is already blank. With the dynamic width Fprintf still needs to waste time parsing the format string.
Re:Spectro: Adventures in Go
by markcrossfield on Sunday November 22, 2015 @03:28PM
(#10611360)
Thanks pbnjay… I agree that’s much more readable and have improved the code.