I have been programming in java for around 3 to 4 years now…but the frequent feedback am getting is that am not using methods effectively.People above me are stating that good coders do keep the lines of code within a method within 25 lines.But how much ever i struggle or try to implement more methods …i keep writing more lines of code in my methods say 50 to 100.
Any suggestions on whether my coding style is wrong or can continue the way am coding..
I’ve tried reading books like Effective java , Thinking in Java…but when it comes to actual code i tend to elaborate..
Suggestions to improve myself will be highly helpful for me!!!
This suggests to me that your methods are doing too much. You should start by narrowing their focus so they do one thing well.
As for those longer methods, look for opportunities to decompose them into smaller methods that they can call. Keep a sharp eye out for repeated code. The moment you find yourself cutting and pasting, an alarm bell ought to go off in your head that says “What’s common between these two blocks? Can I refactor that into a parameter that’s passed into a method that I can simply call in both places?”
Eliminating code duplication will get you 90% of the way there.