Exceptions should be preferred over error codes as returning error codes will force you to have an “if” statement to check for error code, which may be confusing to some readers and there is also a chance that the caller may forget to check for error codes. If you use error codes, you will also need to have some class that defines all error codes. [node:read-more:link]
Is formatting your code important? Formatting your code properly is as important as working code. Proper formatting increases readability and hence maintainability, and also give readers the impression that the code was written by professionals. Let us quickly see some of the formatting issues from vertical as well as horizontal perspectives.
Are comments needed in your programs? If your code is very clear and expressive, then you won’t ideally need comments.By naming your identifiers correctly you can avoid the need for comments in lot of places within your code. So why learn about writing good comments? Due to reasons including the limitations in expressiveness of a programming language, we may have to still use comments, and for these use cases we will need to learn to write good comments.
Below simple list of principles and practices can help you write cleaner methods in your program:
Methods should be as small as possible and should have descriptive names that explain its purpose without the need of any extra comments. Bigger methods should be refactored to move contents that can be grouped together, into other methods with descriptive names that reflect the task done by that method and then invoke those methods from the original method.
This is a personal technical blog where we share our understanding on various concepts and is neither an official page or documentation for the products described here, nor the official views of the companies we work with.
Keywords used in this website are trademarks of their respective owners. This website is not affiliated with Oracle™ and/or any of the JEE frameworks like Spring™, Struts™, Hibernate™ and JSF™.
All contents and materials are provided freely without any warranty or liability and nothing within the site should be considered as professional advice. In any doubt, please ask, and we will try to help you based on our knowledge. Please let us know if you feel anything is not right here (including any copyright violation) and we will act upon it as fast as we can.