DEV Community

Discussion on: Method name to explain context

Collapse
 
marcosvafilho profile image
Marcos Filho • Edited

I really like the idea (truly), but I would try to have a shorter method name and on top of that I would make use of an inoffensive (and more expressive) comment:

def resolve
  return fake_success if user.nil?
  result = CreateResetPasswordToken.new(user).call
  {success: result.success?}
end

private

# prevent malicious knowledge about which emails are registered
def fake_success
  {success: true}
end
Collapse
 
forbes profile image
Josh Forbes

I think I like this better. In my example with the long method name it still wasn't giving us the full context. It told us that we were concealing which email addresses actually exist - but why? Your example communicates the entire context by talking about "malicious knowledge" and keeps the resolve method readable. Thanks for the reply!

Collapse
 
marcosvafilho profile image
Marcos Filho

Glad I could help!