4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Good practices in object-oriented programming - # 1

  • 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.

4 upvotes $0.00

Replies (0)

Conversation

No replies yet

Replies will appear here as people join the conversation.

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: