4 ms·
> However, I think the more common mistake is using names that are overly long. But the most productivity-sapping mistake is names that are too vague. The ide
by crazygringo 3y ago
> However, I think the more common mistake is using names that are overly long.
But the most productivity-sapping mistake is names that are too vague.
The idea that "names should be as short as possible while still being clear" is a truism I don't think anyone disagrees with. But it's a balance that nobody ever perfectly gets right.
So if you're going to err, it's better to err on the side of clarity rather than shortness. E.g. lines like:
fetcher = repolib.IndexFetcher(args.arch)
counts = collections.Counter()
for file in repo.files:
Would be better as:
repo_fetcher = repolib.IndexFetcher(args.arch)
file_counts = collections.Counter()
for repo_file in repo.files:
It's far more helpful when a line of code tells you what it's doing not just in terms of programming logic but in terms of the purpose of the code, the contextual nouns and verbs. It saves a lot of mental effort when reading and debugging.
- contravariant 3y agoIf we're debating style anyway I'd argue using agent nouns as a class name is a worse offence. Compare index = RepositoryIndex(args.architecture) statistics = RepositoryStatistics() for repository in index.retrieve_repositories(): for repository_file in repository.files: statistics.increment_file_count(repository_file.name) This is still mostly equivalent to the original, but a lot easier to read and pretty much every word removed from the name can be inferred from the type. It can be made even less verbose but at this point there's no real need.
- jimmaswell 3y agoNo one was ever hurt by a noun in a variable. Longer and more descriptive is fine.
- classified 3y agoThere are two hard things in software development: Cache ivalidation, naming things, and off-by-one errors.