Skip to content

A Cool Practice; make everything ‘final’ in your Java code!

June 22, 2008

There are various well-known practices in programming to write better and modular code. For me, the best one I’d found (and I always try to consider) is to make e-v-e-r-y variable in my code as final. This is a great practice and I really recommend this to anyone even junior programmers.

Although Java is not functional, but making every object immutable and stateless (using finals, CDI, and messaging), reduces side-effects to a great extend and can prevent many hidden bugs esp. in concurrent programming.

Unfortunately this practice have some exceptions in Java, where there is almost no way to have a variable as final (for example in making a JDBC connection where you are going to close statement in finally block).

Hopefully it seems that in Java 7 most of these issues are fixed and we will be able to write better(more finlialized) codes there :)

From → java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: