Good practices in object-oriented programming - # 1

in #java6 years ago (edited)
  • Always limit the scope of a local variable

The local variables are great, they make life easier for us. But sometimes they can insert more bugs during the recycling of old code. Minimizing the scope of a local variable makes the code more readable, less prone to errors and more maintainable.

Therefore, we must declare variables just before they are used.

Try to initialize a variable from its declaration. If that is not possible, assign it the null value and initialize the empty objects when necessary, in Java it is one of the most expensive operations in terms of memory use and impact on performance is the creation of objects, this is avoidable by initializing the objects only when they are required in the code.

Coin Marketplace

STEEM 0.17
TRX 0.12
JST 0.027
BTC 61023.73
ETH 2948.98
USDT 1.00
SBD 2.51