Naming functions that do one or more things

by Ethan Fischer   Last Updated September 29, 2017 17:05 PM

I recently picked up 'Clean Code' by Robert Martin and have taken to refactoring my recent project. I'm realizing how important it is to name variables and functions in a way that clearly expresses their intent.

One of my functions is called addEvent(). But the problem is, this function sometimes adds 1 event and sometimes adds multiple events, depending on the arguments it's given.

I'm trying to come up with a suitable name for this function but nothing really sounds right to me:

addEventOrEvents() ?

addEvents() ?

addOneOrMoreEvents() ?

I'm also aware that a function is only supposed to do one thing. So maybe I need to break this up into more than one function? But in that case, I can't think of what the function that determines how many events to add would be called!



Related Questions



Class names with Verbs

Updated May 04, 2017 21:05 PM


Refactoring Atrocious Java Code

Updated February 21, 2017 22:05 PM