DEV Community

Josh Soref
Josh Soref

Posted on

Words and their meaning

Words have meaning and developers often get things wrong in their first drafts (but which they rarely fix)

Colbert Late Show: Flirt Graphs

A common case is an application developer who creates a message:

ℹ️ You haven’t hidden anyone yet.

The logic they use for it is:

if (hidden_users.count == 0) {
  show_message("You haven’t hidden anyone yet")
} else {
  show_list(hidden_users)
}
Enter fullscreen mode Exit fullscreen mode

What goes wrong

A user uses the hide feature and then uses the unhide feature and then goes to the view which shows:

ℹ️ You haven’t hidden anyone yet.

But, that's wrong. The user has in fact exercised the feature twice.

What to do instead

Instead of treating the state as a boolean:

count message
0 you haven't message (never used)
1+ show list

Treat it as a tristate:

count message
-1 you haven't message (never used)
0 you don't have message (you've used but aren't currently using)
1+ show list

How precisely you manage this will depend on your application's specific persistence structure.

Ideally, for the case I'm picking on, the message could have said something like:

ℹ️ You aren't currently hiding anyone.

Note that if you really don't want to store the extra -1 (uninitialized) state, you could just use this message to handle both -1 and 0. There's nothing wrong with showing this message to users in either category. Whereas showing the -1 message (You haven’t hidden anyone yet.) to users in the 0 state (who have hidden someone) is definitely wrong.


This is a plea to the average developer: Be better than the average developer at big companies. I regularly see this mistake from NYSE top 25 companies.

Top comments (0)