bytes.NewBuffer() should only be used to prepare a buffer for reading
from or to make the buffer a specific size.
bytes.NewBuffer(nil) is exactly the same as &bytes.Buffer{} so it's weird that
this appears in the stdlib.
> Or does the go compiler optimize that away?
The compiler would, but it's still kind of silly.
- jessta
--
=====================
http://jessta.id.au
I noticed that bytes.NewBuffer(nil) is used a lot in Go's standard
packages.
Quite right too. Optimizing compilers look very sternly on
silly behaviour in their innards.
just being silly with your spelling mistake... :-)
It is still best to write the simplest, clearest code you can.
Writing unnecessarily complex or inefficient code and leaving
it for the compiler to clean up is not a winning strategy.
http://prog21.dadgum.com/40.html
Russ