On Thu, Mar 13, 2014 at 10:13:25PM +0100, Markus Teich wrote:
> Silvan Jegen wrote:
> > When scanning the code I saw several cases where you declared and
> > initialized variables on the same line like this
> >
> > var void = 0 // target for unused values
> > var dev, rx, tx, rxNow, txNow = "", 0, 0, 0, 0
> > var scanner = bufio.NewScanner(file)
> >
> > if you do not want to bother with type declarations I would just eliminate
> > 'var' completely by using the ':=' operator.
> >
> > void := 0 // target for unused values
> > dev, rx, tx, rxNow, txNow := "", 0, 0, 0, 0
> > ...
>
> This is also intended. I wanted all variables (apart from the short lived ones
> declared in for and if headers) to be easily findable with grep var. Anything
> wrong with that?
Not that I am aware of.
> I struggled a bit between the different kinds of variable declarations and tried
> to keep it as consistent as possible with this rule:
> In control structure headers, ":=" is allowed, everywhere else use "var".
I think that the var keyword used without a type declaration is redundant
(so the following may be my rule if you will).
If you are not going to write something like
var scanner bufio.Scanner
scanner = bufio.NewScanner(file)
which lets you easily see what the type of 'scanner' is you can just
write
scanner := bufio.NewScanner(file)
and get rid of the 'var'.
As was said before, these things are highly subjective though.
- application/pgp-signature attachment: stored
Received on Thu Mar 13 2014 - 22:49:10 CET