DEV Community


Discussion on: Back to basics: Naming

alainvanhout profile image
Alain Van Hout

As with most things, it depends:

  • if the function is supposed to return a boolean (i.e. false or true), then isValidEmail seems like the most expressive, in that it leaves the least room for doubt regarding what the method requires as input and what it will return as output
  • if the function is supposed to throw an exception when the string isn't a valid email address and do nothing if it is a valid email address, then validateEmail seems like the most expressive choice

My thoughts on the other options:

  • isEmailValid: this one seems more at home in e.g. user.isEmailValid(), so as a plain function this name adds more ambiguity than is necessary
  • emailIsValid: the same, with the additional concern that it could just as well be the name of a variable/field than a method to be called/queried, so even more unnecessary ambiguity
  • isEmail: very, very vague. Does this refer to a valid email address, a known email address, an object of the type Email, the route via which the user prefers to be contacted ... ?