3 ms·
This touches on one of my least favorite things when reviewing code: "stutter". A common example is what happens when you have an object that should just be a
by joshuamorton 7y ago
This touches on one of my least favorite things when reviewing code: "stutter".
A common example is what happens when you have an object that should just be a function (or static in javaland):
from io import reader
reader = reader.Reader()
reader.read(file)
Oof. Just
import io
io.read(file)
Similarly when you have method names that share information with the class and arguments.
BufferedReader bufferedReader = new BufferedReader()
bufferedReader.readBuffer(buffer)
Now languages support stuff to reduce this, like `val`, but still! When designing apis/interfaces, consider what they'll look like to a user and don't force your end users to stutter.
- adzm 7y agoI've referred to an aspect of this before with repeated prefixes within a scope as Smurfing, where you have SmurfLib::SmurfPtr<SmurfObj> pSmurf = new SmurfLib::SmurfObj::CreateSmurf();
- YeGoblynQueenne 7y agofrom io import reader reader = reader.Reader() reader.read(file) Isn't this why you can say: from io import reader as r And then: reader = r.Reader() reader.read(file) ?
- joshuamorton 7y agoSure but you still have `read` 4 times (down from 6), while I have it only once. And that comes at the cost of forcing your users to alias a variable which can be a maintenance burden long term.
- YeGoblynQueenne 7y agoFair enough. Though two of the "read" are "reader" and "Reader" and you can tell them apart easily from the capitalisation. But I don't completely disagree with your point.
- hliyan 7y agoMy least favorite would be putting the name of the pattern in the class name. E.g. "FooService", "BarRepository", "XInterface". Code is most readable when names describe business and not implementation detail.
- lainga 7y agoeither `golint` or `go vet` will complain about stutter of this kind