best way to improve your coding skill
It's likely that The Next Big Thing will be concurrency. Concurrency is tough to pull off in a purely object-oriented language, and one could argue that Java is nearly the archetype of a pure object-oriented language. Scala and Clojure, both of which run on the JVM, approach concurrency by shifting away from object orientation and towards functional programming.
Here are a few rules that I follow:
1. "Do not reinvent the wheel". If you are asked to write some code check whether a good open-source project already has it. This code will already be thoroughly tested and the probability of bugs will be less.
2. Do not use the "new" keyword. Use a static factory or a builder pattern.
3. Always create immutable objects. It will help when your code is being used in a multi-threaded scenario.
4. Separate code into "Service" and "Repository" layers. Do not write any business logic(not even an if condition) in repository layers.
5. Learn some basic unit testing. Ask yourself whether your service layer code can be easily unit tested. If it cannot be easily unit tested then you have written bad code.
6. Learn and start using a DI module like Guice or Spring. Use utility functions from libraries like Guava instead of writing your own.
7. Please do yourself a favor and learn functional programming. It will change the way you think and also help you write lesser code.
8. Finally, the most important thing which my ex-head of engineering told me once: “The best line of code is the one which is never written”. Just imagine the lesser code you write and more code you reuse, less is the effort and the bugs.
Related blog:
Comments
Post a Comment