[Branch ~go-bot/juju-core/trunk] Rev 1666
Nate Finch
nate.finch at canonical.com
Mon Aug 19 23:35:16 UTC 2013
I have two guiding principles when coding:
Write the code that is idiomatic to the language it is written in.
Write code that is easy to read by someone new to the codebase, but
comfortable with the language.
If we're telling war stories, at my last job we had an architect level
developer who was new to python but very experienced in Perl. He wrote
entire modules in Python just so he could write Python code that read more
like Perl. Needless to say, his Python code was nearly incomprehensible to
the devs familiar with Python.
Henning said the single letter variable names surprised him, but they would
not surprise a developer who is comfortable with Go. It is standard
practice in Go to use single letter variable names when the meaning is
clear. This nearly always the case for the receiver for methods on types,
and often the case for parameters to functions. This is shown in pretty
much the entire Go standard library. For example:
http://golang.org/src/pkg/image/geom.go?s=2380:2421#L98
That being said, I think some of the std lib in Go is a little unreadable
because of their choice of variable names, but I am also not as experienced
in Go programming as the people writing the standard library :)
On Mon, Aug 19, 2013 at 5:42 PM, Tim Penhey <tim.penhey at canonical.com>
wrote:
> On 19/08/13 20:52, Henning Eggers wrote:
>> On 16.08.2013 13:11, Nate Finch wrote:
>>> Personally, I prefer variables in the 1-4 character range, because they
are
>>> less prone to typos and I find them easier to read when embedded in
complex
>>> expressions.
>>
>> That is something I was surprised to see in many places when browsing
the juju
>> go source. Abbreviations or even single letters for variable names are
against
>> what I have been taught and practiced as good software engineering over
the
>> last twenty years or so. The rule may be emphasized differently in
different
>> software projects but it really struck me as very lax in the juju source.
>
> I do have to say I agree with Henning here.
>
> It is my *strong* preference to have full pronounceable, meaningful
> names. IMO "information" is not meaningful (neither is "state")
>
> As mentioned on our weekly call, all core developers please buy a copy
> of "Clean Code" by Robert C. Martin, and expense it if you don't already
> have a copy.
>
> We are going to start doing a chapter by chapter review.
>
>> Is there a coding style guide for go juju?
>
> Not really.
>
> Code should be written to be read by *humans*, not compilers.
>
> Code will be read so much more than it will be written, and often by
> people who aren't as familiar with the details or intricacies.
> Meaningful variable names are a key component of good readable code.
>
> Tim
>
>
> --
> Juju-dev mailing list
> Juju-dev at lists.ubuntu.com
> Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/juju-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20130819/c0066fd3/attachment.html>
More information about the Juju-dev
mailing list