Skip to main content
2 of 2
added 15 characters in body
Bob Horn
  • 2.3k
  • 3
  • 21
  • 26

Are vague variable names more maintainable?

I'm looking for some advice about which line of code is more appropriate, readable, and maintainable.

#1:

var result = mediator.Send(query).Result; 

#2:

var accountDetails = mediator.Send(accountFilter).Result; 

The above code was taken from a Web API controller. The pros for each:

#1:

  • If the query needs to change and return a different type, we don't have to remember to rename the result variable.
  • That also means code reviews won't be polluted with a bunch of files that have changed due to the renaming.
  • The job of a Web API controller isn't to know the details about what business logic is going on; it's just to invoke something and return it.
  • If you really want to know what the line of code is doing, you can look at the context surrounding it.

#2:

  • It's easier to look at the line of code and understand what the line of code is doing.
Bob Horn
  • 2.3k
  • 3
  • 21
  • 26