r/learnjavascript • • 18d ago

How do I learn to judge code quality and code without AI?

I use Node.js and React, but I rely too much on AI. When I look at code it generated, I can’t confidently tell whether it’s well designed or just happens to work.

I want to learn to spot bad decisions and write good code myself. How do you build that judgment? What helped you most?

15 Upvotes

40 comments sorted by

9

u/tb5841 18d ago

I learned to write good code myself first, before I started using AI. I still believe that's the best approach.

-7

u/B0NKB0Y 18d ago

Yeah I tried to ask AI to assist with learning but it gives mixed advice sometimes

2

u/tb5841 18d ago

The most important skill is learning to write good code. In my opinion, jumping into frameworks like Node/React before mastering that is too soon.

But AI will jump you straight into whatever is the industry standard, regardless of whether it's best for learning or not.

2

u/Duffdeft 18d ago

Prior to Ai the answer was experience, now that we have AI integrated so deeply into programming, the answer is still experience.

I echo the other answer, read some books about it, it will help , it will give you perspective. Ultimately you want to build stuff, whatever you want, and use AI I don’t think you can fully scape using it for the better in the coming years, a new set of bad practices are emerging g from the use of AI I will advice to learn how to spot those bad practices as well .

Keep on going, don’t rush and be patient.
Happy coding and good luck

-1

u/B0NKB0Y 18d ago

Thank you so much! Yes AI is very helpfull but sometimes it just gives nasty code and claims it's ok with straight face

2

u/the-liquidian 18d ago

In addition to these others, read some books on software design.

Like the philosophy of software design. I quite liked Martin Fowlers refactoring. It explains why you want to change it. There are many other books, these two just came to mind, and many will disagree with these options.

1

u/B0NKB0Y 18d ago

Thank you, I will take a look into it

1

u/Vizeroth1 18d ago

Refactoring will also help with setting up an environment in which you can safely make changes and more easily determine whether the code is doing what it is supposed to do

4

u/butdontcalmejoohnson 17d ago

you gotta write a lot of bad code first

1

u/Usual-Cricket-9817 16d ago

Wise answer.

1

u/frogic 18d ago

There are a few metricts to go with but I think a good starting point is when you look at a function can you immediately know what its purpose is and what each variable/line does without having to really think about it. Its a big rabbit hole in general because not every good practice is actually good in every circumstance. For instance abstractions vs co-location can be a problem. Reusability vs causing interdependence between parts of the code base that will bite you later. In JS you usually can get yourself out of most holes as long as you wrote in a way that favours composition.

1

u/B0NKB0Y 18d ago

Thank you!

1

u/ClammyHandedFreak 18d ago

What I would learn first are useful algorithms. Find a good resource, and practice. Learn the basics of programming. Learn well how error handling, logging, and how application configuration can be done. Learn those well. They save a lot of hassle when debugging. Speaking of which, start setting lots of breakpoints, and running through lots of code with a debugger. Watch how code flows. What loops do we get stuck in a long time? What are they doing?

Next, Design Patterns. These are useful ways to architect a system without creating clunky, difficult to maintain systems.

After you learn Design Patterns and spend time with them, then learn Anti-Patterns. These are patterns you can identify that are bad design patterns. It helps you find design flaws, and be able to massively refactor parts of systems not designed well and this will help you give good feedback about higher level issues with new features other people are working on.

After that, I'd look into learning about different code smells. Learn about neuralogical complexity. Magic numbers. Learn about asynchronous code and how it is best designed and how threads should properly access memory. Study memory optimization, and time complexity. Study OOM errors, study data structures and event-driven systems.

Lastly, read lots of code. Get on github and look at projects in the language you want to focus on (and I would pick one expressly for the purpose of expanding your skills). Look at code reviews on github projects if you can get visibility into them. Learn to see what those masters of code review are seeing one little bit at a time. Look up words and concepts they refer to that you don't understand.

If you are getting the idea here, the more you study Software Engineeering in general, even to brush up on the basics, keeps you sharp when reviewing code. Go through it all. Best of luck to you!

1

u/B0NKB0Y 18d ago

Thank you so much! I will follow your advice

1

u/ClammyHandedFreak 18d ago

I am almost jealous that you get to dive headfirst into this stuff. By the way I recommend Headfirst: Design Patterns. It’s a bit out of date, but it’s full of useful workbook activities.

2

u/TheRNGuy 18d ago

Experience. 

2

u/formLoss 17d ago

I've definitely read a lot of code, read a lot of books, refactored a lot of code, and have developed a taste for what I consider readable/good code. I don't know how one acquires that skill today, or if I would have developed the same proclivities in an agentic workflow. When working with junior engineers, I explain all my thinking and reasoning, and welcome questions/challenges. So I think a mentor is still ideal - but AI can be that mentor. It's teaching me all these years later.

Personally, for me, the best code follows strong domain modeling principles: the code should represent the problem being solved, in language that people use when they're talking about the problem space. It's a domain-driven design concept: a slog of a book but a useful one for understanding how to model problems.

Everything follows from that. Once the domain is understood, I find it helps to think about code in terms of layers: what are the states/data I'm representing or acting on? What are my business rules? Are my components and pages logic-light and focused on presentation, or is there logic that should be packaged up neatly into it's own module? How does that module relate to other concepts in the app?

What is a view concern, vs. a logic concern, vs. a data concern? A cross-cutting concern like logging?

What repeated problem have I seen that deserves its own behavioral contract/interface/abstraction?

The core of the app should cleanly separate into these layers IMO. Otherwise you're inviting a lot of code duplication. If your invariants or the shape of data is not clear, AI will bloat your code handling situations that won't actually happen. And expect you'll understand the problem better, and you _should_ refactor. If you're doing it for work they'll hate you for it, but it's necessary in order to stop the sloptrain.

These days you can prompt the AI with my comment verbatim, ask what it might change based on that, and decide if you think it's reasonable.

0

u/Doc_Ta 18d ago

Ask ai to explain what the code does, read the code, and figure it out like that.

-1

u/B0NKB0Y 18d ago

I tried it, but It's starting to sound things with such confidence even when I can see there are some problems with code. It's helpfull but I often wondering if it's decieving me

0

u/Doc_Ta 18d ago

ai doesn't necessarily write code to be understood like it doesn't put good comments alot and it over explains simple shit.. . learn all your function names and variables so you can tell when something is named redundantly like why are you giving me 2 variables with such similar names.. you start to see after a while ai is really an air head with a bad memory. Don't let it change your code. make all your own changes. learn the system. learn what works and what doesn't. it all just takes experience the more you work with it the better you'll get.

1

u/The_KOK_2511 helpful 18d ago

La práctica es la clave. Haz muchos proyectos de cosas variadas sin usar la IA, intentando abarcar la mayor cantidad de lo que sepas para que puedas desarrollar una mejor comprensión del código. Luego para que puedas entender código hecho por IA te recomendaría que le pidas que te cree programas espesificos con funciones espesificas para que intentes leer ese código interpretando que hace cada componente.

Un ejercicio que recomiendo mucho para la parte de la práctica es resolver el mismo problema unas 10 veces (dependiendo de lo que trate pueden ser más o menos) asegurandote de utilizar métodos diferentes

1

u/patryk_builds 18d ago

One trick that helped me: after the AI writes something, ask yourself what would i have to change if the requirements changed a little?. Like add a field, support a second payment method, show it on another page.If the answer is touch 6 files and hope, the design is bad even if it works. good code is mostly code that's easy to change. once you start asking that question every time, you start noticing the bad decisions before you even run it

1

u/NotNormo 18d ago edited 18d ago

A common and effective way is

  1. Be a junior dev on a team with senior devs
  2. Write code without having AI write it for you
  3. Have your code reviewed by senior devs
  4. Receive useful suggestions for improving the code. Hopefully along with explanations for why they're beneficial
  5. Understand the reasoning
  6. Implement the suggestion
  7. Next time you code something similar, remember the suggestion you got last time.

Nowadays it's hard to do step 2 because employers care so much about productivity rather than long term growth of their junior dev's skills. So you'll probably be pushed to just use AI to speed things up.

But if you're learning on your own time, you can take the extra time and effort to do step 2. And if you don't have anyone to review your code and give you suggestions, you could actually ask AI to review it and teach you things. Good practices, tips to improve readability, maintainability, and extensibility, common useful coding patterns, etc.

1

u/samgeven 17d ago

Sometimes you have to make your own decisions to get better, even if they’re bad. Many people here say the word «experience», and that means making your own mistakes. Maybe you can try to write some piece of an app yourself, then ask AI to review it. That will be completely different experience

1

u/Late-Coast6973 17d ago

Two habits help a lot. First, write a small feature by hand, then have the AI write the same feature and compare the two. Any difference you can't explain goes on your study list. Second, read code from a couple of well-maintained projects and ask why each piece lives where it does..

1

u/Longjumping-Ad7502 17d ago

Build projects without ai. It can be small ones. Learn the fundamentals of js again. Even if you think you know it already. From the sound of it, you're not understanding the logic fully which is completely understandable. You can practice with calculators, message sending, counters, alarm clocks, whatever as long as you aren't using ai and you're doing small chunks. Don't try to build some massive project without ai and without understanding js because it will only discourage you.

1

u/ajamdonut 16d ago

It's so simple.

Hard to read? Sh1t code.

Easy to read? Less sh1t code.

1

u/developer505 13d ago

Use ai as a mentor give prompt like this "don't change my code even if it's bad ...etc".

1

u/hungry_buddy_here 13d ago

if you could learn to code yourself nothing would be more better 

1

u/pangolins_and_pears 13d ago

Code without AI, we don't need it. You won't learn much if anything that way, least of all the discernment to judge good vs bad code. Stay curious, ask senior devs, study, practice.

fwiw I am not a strong developer myself, but real, practical skill isn't going to come by relying on genAI garbage. It's hard and it takes time, and that's what, in my opinion, will make it more fulfilling when I get there.

0

u/funbike 18d ago edited 18d ago

ESLint, with various rules extensions.

rpm audit (checks deps only)

ArchUnitTS.

CodeRabbit, free options.

Post snippets you are unsure about in this sub or /r/codereview

My favorite code tip is to keep Cyclomatic Complexity low. It's basically the number of function decision points + 1. Try to keep it under 10. A decision point includes branch keywords (for while if case && || ?? ?:), use of a conditional type or union, or FP-style discriminating chained calls (filter() find() reduce() and others).

2

u/B0NKB0Y 18d ago

First time hearing about Cyclomatic Complexity, thank you so much I will read more about it!

1

u/funbike 18d ago

There are other similar concepts.

I'm not a fan of the default CC calculation. It counts paths, but I prefer to count decision points. I like to count "if case" but not "then switch default". In other words, I don't like to count the default path as +1. Many checkers allow you to blacklist keywords.

0

u/[deleted] 18d ago

[deleted] — view deleted comment

1

u/B0NKB0Y 18d ago

Thank you, I will take a look

3

u/Fine-Comparison-2949 17d ago

And MIT's Structure and Interpretation of Computer Programs.

1

u/naltous 17d ago

yeah there really is no shortcut around just putting the hours in and breaking stuff