Bad names make you open the box

submited by
Style Pass
2021-06-09 15:30:08

But I probably didn’t need to explain that to you, did I? Why not? Well, because getPromotedPosts is self-explanatory. Because getPromotedPosts is named well.

Now what if instead of getPromotedPosts, it was named something like getThePosts? Well, that name isn’t self-explanatory. You know it’s getting some posts, but it’s not clear which ones. The most recent posts? Posts from a certain author? Posts from this week?

You realize that getThePosts must be getting some posts, but you don’t know which ones. So you have to scroll to line 174 where getThePosts is defined.

On line 174 you start reading through getThePosts. Once you reach line 210, you realize that it is getting promoted posts. Cool!

Now you scroll back up to line 30. You realize that getThePosts is giving you promoted posts, but you forgot what was happening before line 30. Damn. So now you have to go back to line 10 or 15 to remind yourself what was going on in the first place.

Maybe I was being dramatic. Is it really such a big deal to have to scroll to the definition of getThePosts on line 174? Will it really take that much effort to read lines 174-210 and figure out that it’s returning promoted posts? It’s only 36 lines of code, including whitespace + brackets, and you could probably glance over parts of it. And then what about returning to line 30? Are you really going to have forgotten what was going on so quickly? Are you really going to have to scroll back up to line 10 or 15 to remind yourself?

Leave a Comment