Good practices in object-oriented programming - # 1

in #java7 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.24
TRX 0.25
JST 0.039
BTC 93785.26
ETH 3367.35
USDT 1.00
SBD 3.26