Idiomatic way of naming Getters in Go

CuriousMind

The Effective go has following advice on naming of getters:

Go doesn't provide automatic support for getters and setters. There's nothing wrong with providing getters and setters yourself, and it's often appropriate to do so, but it's neither idiomatic nor necessary to put Get into the getter's name. If you have a field called owner (lower case, unexported), the getter method should be called Owner (upper case, exported), not GetOwner. The use of upper-case names for export provides the hook to discriminate the field from the method. A setter function, if needed, will likely be called SetOwner. Both names read well in practice:

Source: https://golang.org/doc/effective_go.html#Getters

Now, this advice doesn't seem to consistent as the stdlib itself violates this multiple times. enter image description here

As you can see in above screenshot, there are multiple methods which use GetX naming convention which is advised against in the effective go guide.

So the question is is the advice given in guide wrong or these methods are named wrongly & would be fixed in future versions?

peterSO

[go-nuts] FunctionName caseinconsistencies

A lot of the all lowercase names were chosen before we had really figured out what the naming conventions should be. The rule we adopted, which might be worth revisiting later, was that entry points in package os or syscall, which are named after equivalents in C, just had a single capital at the beginning, to avoid needing to decide where the internal capitalizations are in abbreviations like geteuid or getwd or chdir. Names like Readdirnames, which are actual words, might be worth revisiting at some point.

Russ


os: inconsistent casing in names #1187

Is there any sort of rule about the casing of functions used in the "os" package? Looking through, it doesn't sound like it's very easy to recall whether a given function should be called LikeThat or Likethat.

For instance:

Mkdir
MkdirAll
TempDir
Getenv
ForkExec
Readlink
ReadAt
Readdir

It feels very ad-hoc, and hard to recall.

It's a known issue. It's unplanned.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Go-idiomatic naming of slice types

From Dev

What is an idiomatic way to enumerate the alphabet in go?

From Java

What is an idiomatic way of representing enums in Go?

From Dev

What's an idiomatic way to reconnect to Redis subscription in Go?

From Dev

What's an idiomatic way to implement a red-black tree in Go?

From Dev

What is the idiomatic way in Go to create a complex hierarchy of structs?

From Dev

Is there standard idiomatic Go for "constructors"?

From Dev

Idiomatic Go Code Organization

From Dev

Using C preprocessor macros for function naming idiomatic?

From Java

Idiomatic way of logging in Kotlin

From Java

Idiomatic way to prevent slicing?

From Dev

Idiomatic way to remove child

From Dev

Idiomatic way to validate structs

From Dev

Idiomatic way to validate structs

From Dev

Idiomatic way of modifying NSFont

From Dev

What's the most idiomatic way to pick a value from a slice based on a condition in Go?

From Java

Go naming conventions for const

From Dev

Go JSON Naming strategy

From Dev

Minimum value of set in idiomatic Go

From Dev

Is this an idiomatic worker thread pool in Go?

From Dev

Idiomatic way to initialize a Ruby class

From Dev

Idiomatic way to check for parameter initialization

From Dev

Idiomatic way to test Swift Optionals

From Dev

Idiomatic way to execute an array of blocks

From Dev

Idiomatic Way To Merge Trait Functionality

From Dev

Idiomatic way of merging arrays in Ruby?

From Dev

Idiomatic way of returning nil in Ruby

From Dev

Idiomatic way of If none return false?

From Dev

Idiomatic way to write firstRightOrLefts in Haskell?