Java the Right Way


For over 3 years, I've been writing code in Java, and have worked on several projects which have grown to a moderately large number of classes. Apart from learning the syntax from a book in Grade 11/12, I've never formally learned how to write quality readable and maintainable code. 

The current project I am working on spans in all directions; it's an event based system, there is a lot of input coming from simultaneously running threads, there's Java-C interaction, there are multiple communication channels over different network mediums, there's an entire high-speed display rendering mechanism, and a lot more. The size of the project is sky rocketing and without a structured architecture, the code will not be maintainable in the foreseeable future.

So, just as any other engineer would do, I've bought myself a copy of trusty Effective Java to formally learn how to write code that scales. 

Before I read this book, here's as much my 3 years of experience in Java could gather :
  • Good nomenclature and variable scoping are important.
  • Reuse, never copy-paste.
    If at all you're selecting a region and hitting CTRL-C, you're doing something wrong.
  • Each part/module of your code should as independent of each other as possible.
  • Each module in your code should perform a set of tasks and takes in a set of inputs it requires to work. Each module should aim at solely doing its own job, and not interfere in other's business. In other words, ideally, every part of the code you write should be reusable for future projects - things that can be imported as libraries and reused.
  • The above two ensure testable code - you can't write test cases for code that is highly intertwined.
  • Don't use/pass nulls. They're a terrible flaw and a huge pain to debug.
  • Create your own exceptions and throw them instead of nulls. Be specific in the exceptions you throw.
  • And lastly, well-written code takes care of itself.
    It's hard to screw up a well-written code - the code itself won't let you.
I hope this book serves my purpose, and post this, I'm able to think and write better in OOP based languages.

Comments

Post a Comment

Popular posts from this blog

[Breaking News] AI takes over universe to calculate Pi

Firebase Auth | The Debug vs Release Signature Problem

Cold Showers