Naming conventions in go?

148 views
Skip to first unread message

Lenny

unread,
Mar 4, 2023, 8:49:46 PM3/4/23
to golang-nuts
The effective go documentation doesn't really go into detail of whether or not I should try to name my variables as short as possible even though that is discouraged because of readability

peterGo

unread,
Mar 4, 2023, 8:53:58 PM3/4/23
to golang-nuts

Kurtis Rader

unread,
Mar 4, 2023, 8:58:14 PM3/4/23
to Lenny, golang-nuts
On Sat, Mar 4, 2023 at 5:49 PM Lenny <develope...@gmail.com> wrote:
The effective go documentation doesn't really go into detail of whether or not I should try to name my variables as short as possible even though that is discouraged because of readability 

Lookup "bike shedding". Whether a very short variable name (e.g., "i") or very long name (e.g., "CurrentIndex") is appropriate depends on context. And that context is not just a particular language feature (e.g., a "range" loop in Go) but also the idioms employed by a particular project. Whether a particular name maximizes readability depends on the context -- not the number of characters in the name.

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages