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.
11
u/Januson Mar 31 '21
I can recommend you a few books that really helped me in the past.
Effective Java: Great book that will help you write reasonable Java code.
Clean Code: Similar to the above but the advices here are general and applicable across languages.
Refactoring: Talks about common problems in code and how to fix them.
Growing OOsoftware guided by tests: One of the best books about software testing.
There are other great books but these will give you a great foundation to build upon.
6
u/Dexteroid Mar 31 '21 edited Mar 31 '21
Don't take it out on yourself. lf this is your first job you should be thankful that they give you code reviews..
Read code, then read more.
Also I have heard really great things about Effective ways to solve 55 java problems. Book is all about clean code.
3
u/GuyWithLag Mar 31 '21
Don't worry, but really listen to your manager. If possible, get some pair programming time with your peers.
Andreas. Read lots of code. Read application code, library code, framework code. Configure your ide to autodownload sources for everything, and don't be afraid to dive deeply.
Something is a real issue if it's been pointed to you twice.
2
u/GottaLoveUncleBen Mar 31 '21
Head First Design Patterns is also a book to consider looking into, the book is huge but shows in detail how the various patterns work.
In my opinion you don’t need to know all of them but there are definitely some of good use like the factory pattern, strategy, etc...
Another book i’ve read is Refactoring: improving the design of existing code, that one also showed alot of tricks how to rewrite code efficiently and makes you think about what you’ve written..
1
u/Kind-hearted76 Mar 31 '21
Thanks for posting this. I have the same questions as you do. I'm learning intermediate Java this semester. I hope you don't mind.
1
u/tassadari Mar 31 '21
Code quality is programming language independent. If you want some book advices, here you go: clean code, effective java, bad programming practices 101
1
u/FlicksandFits Mar 31 '21
I mean I don’t have a solution but I came to the same realization as well. I’m in my second semester of computer science at uni and we just talked about big O notation. Really makes me think about what I’m doing when I’m writing something
1
u/gk-therealone Mar 31 '21
My personal suggestion is to make use of all the featuers in your Ide for increasing speed and use some sort of static code analyzer to scrutnize your code.
Then just start coding... All the best
1
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 :)