DEV Community

Discussion on: What are your personal stories/examples of "naming things"?

Collapse
 
r0f1 profile image
Florian Rohrer

I am annoyed when variable names seem correct at first glance, but turn out to be not exactly what the name says. I was working on a project, where the was a variable called n_items, and you would assume, that it stored the number of items. However, it was calculated like this:

n_items = item_ids.max()

where the array of item_ids goes from 0 to the number of items minus one. So actually, n_items was the number of items minus one. Super confusing, super dangerous. I encountered that discrepancy, because I saw these kinds of loops, further below:

for elem in range(n_items + 1):
    ...
Collapse
 
developerscode profile image
Ka Wai Cheung • Edited

Yuck. Thanks for sharing :)