r/learnjava • u/porcoolpines • Mar 31 '21
Advice for improving code quality
Hi guys, would like to apologise in advance if this is the wrong thread to post to. I was hoping to hear from your experiences on how did you all improve in coding in your own ways.
I just started my first back-end dev job and prior to that, I only had about 4 months of intensive Java training for this role. As a result, I would think that my experience with Java is not as much as most of my peers, and I quickly came to realise how actually WORKING with Java was a whole new experience and learning curve for me, as compared to just practicing it at home. Initially, I was quite proud of my work as they could all run as per requirements. After a while though, my code reviews kept leaving me really discouraged, with the many change requests from my supervisor in order to optimise my code. Recently, one of my managers also told me that I ‘really have to improve faster on my coding skills’. I later realised he was referring to how my code could adopt more best practices and be more efficient (e.g less calls to database, usage of String.join in 1 line rather than using StringJoiner, handling exceptions only when appropriate etc.)
I understand that such improvements usually come with experience, but are there also any other ways or practices that you guys had to speed up this learning curve to produce high quality code in your work?
EDIT: thanks so much for the tips and detailed reading recommendations! Would definitely look into those books, as well as to make the conscious effort to turn those tips into good coding habits as soon as possible.
29
u/_Atomfinger_ Mar 31 '21
What might be a good use for your time is:
Understand the SOLID principles.
Writing tests often reveal how clunky your code is.
Make sure that your code matches the general look and feel of the application. If your code differs significantly, then you should pay extra attention to why.
When developing, look at similar examples that might already exist in the codebase.
As you say though, much of it is experience-based, but it is all about readability, maintainability and performance. If you hit a sweet spot between those 3 factors then your code is most likely pretty good.
When new code reviews can feel a bit rough, but over time the number of comments will decrease. Just make sure that people don't need to leave comments about the same things multiple times :)