I use Node.js and React, and I can usually tell whether my code works, but not whether it's well designed. How do I learn to judge readability, responsibilities, and unnecessary complexity?
How do you get better at judging code quality?
Answers
Try following one behavior through the code. Can you tell what happens without constantly jumping between files or holding a bunch of details in your head? Clear names, predictable file locations, and code that keeps related ideas together all help.
Confusion is a clue, not a verdict. Some code feels difficult because the underlying problem is difficult, or because you're still learning the language and framework. Note exactly where you got lost, then see if a different name or structure would make that part easier to follow.
Reply to this answer
Give the design a change test. Pick a small feature to add to an older project and trace what needs to change. If one simple change sends you to lots of unrelated places, that's worth investigating.
It's not a hard rule that fewer edits always means better code. The useful question is whether the places you have to edit make sense for the change, and whether the existing structure makes the change easy to reason about.
Reply to this answer
For responsibilities, try explaining what a function does in one sentence. If the explanation turns into a long chain of unrelated tasks, it may be doing too much. Splitting it can help when the resulting pieces have clear purposes, though a short function isn't automatically a good one.
Look at nesting too. Deeply nested conditions and loops can make the flow hard to track. Sometimes simplifying a condition or returning early helps more than adding another layer of abstraction.
Reply to this answer
Read a few small public projects in your stack, not just tutorials. Pick one feature and find where its UI and server logic live. Notice what made the route easy or hard to follow, then compare that with your own code.
Don't assume every pattern in a public project is the right one. Treat it as material to study, and keep practicing the fundamentals alongside it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
8c~grommetladle_347:
This works as a reading exercise too. Before changing anything, predict which files should be involved, then compare that with what you actually find.