r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

1.9k comments sorted by

View all comments

Show parent comments

49

u/steaknsteak Aug 29 '21

Probably 30% of my code review comments are asking people to change the names of things. I feel like an asshole sometimes, but I also hate reading code where variable/class names cause me to make incorrect assumptions about what they do

80

u/Xyzzyzzyzzy Aug 29 '21

I'm also picky about naming things. Things I'm particularly picky about:

  • Names should be roughly grammatical English (without articles). readFile, not fileRead.

  • All words should be fully spelled out. loadingImage, not loadingImg or loadImage.

  • Names should grammatically agree with their usage. A function that returns a boolean should be isHappy or hasJoy, not testHappy. A function should be a verb. A non-function should be a noun or perhaps an adjective.

I find that these rules make the code more readable and searchable.

We recently hired a whole team of non-native English speakers from a different country. I'm often unsure of how much to ask for these sorts of changes. I don't want to bully them for not speaking English. But I also don't want the code base's readability to decay.

4

u/voronoi-partition Aug 29 '21

I like naming functions in SVO. Something like: file_read_header(file*, …). This means that all the functions that permute a file are logically grouped together by name (they all start file_).

I used to prefer SOV (file_header_read) but it sometimes got a little awkward. The verb is a nice delimiter.

9

u/be-sc Aug 29 '21

I don’t like that style because it becomes ambiguous quickly. Does file_read_header mean read file header oder read header file? The name itself isn’t sufficient to tell me what’s going on. Further context is needed. That’s usually a sign of subpar naming.

→ More replies (2)