Skip to main content
2 of 2
added 6 characters in body
Falcon
  • 19.4k
  • 4
  • 82
  • 93

It depends. Sometimes it's better to encapsulate an expression in a function/method, even if it's only one line. If it's complicated to read or you need it in multiple places, then I consider it a good practice. In the long term it's easier to maintain, as you've introduced a single point of change and better readability.

However, sometimes it's just something you don't need. When the expression is easy to read anyway and/or just appears in one place, then don't wrap it.

Falcon
  • 19.4k
  • 4
  • 82
  • 93