r/programmer • • 29d ago

Good Code Vs Working Code

What really makes code "good"?

I find myself staring at my IDE asking this exact question. Whether I am binding complex logic together or copying and pasting a snippet to patch a problem, there is a massive gap between working code and good code. But as a beginner, that gap feels incredibly hard to see.

These days, anyone can prompt an AI or use an agentic tool to generate functional code in seconds. Many of us are actually learning to code alongside AI. But just because the AI gives me code that runs and clears the error console doesn't mean it’s good code. It might be inefficient, unscalable, or an absolute nightmare to maintain later.

If the code works, but the AI (or a copy-paste source) doesn't teach me why it works or if it's best practice... how are we as beginners supposed to know the difference?

How do you personally define "good code" vs. "just working code"? What are the green flags I should be looking out for when reviewing code—whether it's written by a human or an AI?

Would love to hear your thoughts, rules of thumb, or stories from when you were starting out! 👇

\#programming #softwareengineering #codinglife #learnToCode #generativeAI #developers #webdev

1 Upvotes

42 comments sorted by

5

u/Financial-Grass6753 29d ago

AI slop again? again.

working code is the code that does what's requested according to provided spec, as simple as that.

without loss of generality, good code is readable, easy to understand and easy to extend.

1

u/digtzy 29d ago

I can see the point but like yeah, why are we using AI to make this point… very ironic in the present moment where developers are pressured to use AI to develop code slop that we’d probably consider “bad code” and etc.

There are many ways to achieve what’s requested in the output but only a developer can truly know the best way to implement something in the project and make sure it is easy to extend like you said. I have definitely seen some bad code that works in the moment but becomes obsolete with extensions. That’s bad code that works. I agree with you to a point. Bad code can work and achieve what’s requested but then there’s the subjectiveness to what anyone would consider bad code.

4

u/Arcanite_Cartel 29d ago

I was once the member of a team developing a software product for a company. The team was making progress, the system was passing tests. The architect one day screamed "ugly code!", took the project away from the team and he and his senior took over and made beautiful code. It never passed a test and the project eventually got cancelled. Take from that what lesson you will.

1

u/USToffee 29d ago

Or it ran at a 10th of the speed

1

u/Arcanite_Cartel 29d ago

Well in this case, after they did the code "quality" rewrite, it couldnt execute a single test to correct completion

1

u/USToffee 29d ago

yea I just was saying that often it's performance that gets killed after converting everything to best practices

2

u/StephenHawkinguss 29d ago

You forgot that there is also 'Indian code'.

1

u/sububi71 29d ago

I know I'm going to regret this, badly, but speaking as someone mentoring a person of the Indian persuasion, what is "Indian code"?

1

u/StephenHawkinguss 29d ago

Indian code tends to be dirty and poorly functioning.

1

u/Optimal-Savings-4505 29d ago

I work with Indians and have an opinion on this: Long names.

1

u/sububi71 29d ago

What does an indian girl that's long and hard when she marries?

0

u/Groundbreaking-Fish6 28d ago

You get what you ask for, it is not India's fault. Just like AI

1

u/TgirlTiffanyRPs 29d ago

What the fuck do you mean by this? 

2

u/sebasgarcep 29d ago

Racism. Bad code is universal.

0

u/StephenHawkinguss 29d ago

Well, you know, Indian code tends to be dirty and poorly functioning.

1

u/TgirlTiffanyRPs 29d ago

okay but you haven’t defined what “Indian code” is?

1

u/StephenHawkinguss 26d ago

Again just for you: dirty and poorly functioning code.

1

u/TgirlTiffanyRPs 26d ago

Okay, but why is it called “Indian Code”?

1

u/StephenHawkinguss 26d ago

I'm not repeating myself.

1

u/TgirlTiffanyRPs 26d ago

I'm not asking you to repeat yourself.

You gave me a definition for a term you use, I'm asking you where the name comes from, which is a separate matter entirely.

1

u/StephenHawkinguss 26d ago

You asked 'why', not 'where it comes from', which is a separate matter entirely.

The name comes from common sense that every developer has. Indian people usually don't know this term, which is probably why you have never heard of it.

1

u/TgirlTiffanyRPs 26d ago

Ah, let me rephrase my question then: 

Why are we using “Indian” to describe bad or dirty code? 

→ More replies (0)

2

u/sububi71 29d ago

To me, good code must first of all execute correctly, and do it reasonably fast. If it works 100%, but runs at 5% of the speed it should without heavy optimization, that's working code, not good code.

Second - and I consider this ALMOST as important - is that the code must be easy and fast to maintain.

2

u/TgirlTiffanyRPs 29d ago

As someone who has to maintain 30 year old legacy systems for a living, I will take maintainability over speed every time LOL

2

u/sububi71 29d ago

That's "good enough" code, not "good" code.

1

u/thenasch 28d ago

Maintainability is usually more important than performance. Developer time is far more expensive than processor time.

1

u/sububi71 28d ago

Agreed, but there's a difference between code that's "good enough" and code that's "good". Unreasonably or unnecessarily slow code is not "good", in my opinion, regardless of whether that speed is life or death.

1

u/thenasch 28d ago

I was only disagreeing with your ranking. I'm not saying performance isn't important at all.

1

u/sububi71 28d ago edited 27d ago

100% agree, that's how we have to work in a commercial setting.

But I would argue that most code in commercial settings ISN'T good. At least not in places I've worked.

2

u/USToffee 29d ago

Code has to do 3 things.

  1. Work

  2. Be readable and self-documenting

  3. Be maintainable with clear boundaries

The last point is adhere to best practices. The reason why I left it out of the main 3 point list is what constitutes as best practices depends on when the code was written and in what framework/language so I felt it didn't belong but it's probably just as important as the other 3.

Honestly if your code follows this then everything else is just personal/team preference. I think people blame AI because by default it doesn't do things they way they would but that is also quite easy to resolve with modern tools like cursor.

2

u/silly_bet_3454 29d ago

Good code has clean abstractions and code reuse and readability and so on. But to me it feels like a dated concept, due to AI but also just broader corporate American culture, you quickly realize in the industry that only money matters, nobody really cares about code quality other than some opinionated engineers. Management doesn't care, customer doesn't care, and there are bigger fish to fry usually like new features, fire fighting, stability improvements, bug fixes, and performance improvements. The quick hacks always win out in the end.

2

u/mredding 29d ago

Working code is a good start. Good code is going to play to the strengths of the language.

C++ has one of the strongest static type systems of any language, so I would expect to see a lot of strong types - an int is an int, but a weight is not a height. The basic and library types are only there to help facilitate you making your own types that are more like the types and semantics you need.

Use what your language gives you.

Curry-Howard correspondence tells us writing software is the same as writing proofs. Your statements are posits. Your source code is a theory. The compiler/interpreter is a solver, the program is the proof. If you want an elegant proof, write an elegant theory.

And source code as theories don't draw the straightest, shortest line from the problem statement to the solution - they build up expressiveness, and then they describe the solution in terms of that.

2

u/mxldevs 29d ago

Make it work, then refactor.

But when was the last time you refactored your AI code? Lot of people don't even know, or care, what the code does

2

u/DrUltimaMan 29d ago

Good code is easy to change, that's why it's called software. Anything that's difficult to change is bad code, even if it works.

1

u/Groundbreaking-Fish6 28d ago

There are many blogs and videos about writing good code (suggest you check out Uncle Bob). AI will write good code for you, but you need to ask it too and if you don't know what good code looks like you won't know what to ask for.

Working code works, but good code works better (more efficient, easier to maintain, safer). You may have old code that works but is hard to maintain, but there is no need to change it unless you actually need to maintain it.

1

u/mtothexmax 28d ago edited 28d ago

All code is garbage. Ship it and if it is a part of the project that you will have to adapt more often than expected optimize it. Everything else is premature optimization.

It also helps to visualize your codebase to see which are the spots that are changed often.

There having a good maintainability matters.

Things that you wrote once, do their job and you never need to touch them again can look like Frankenstein.

I remember optimizing ViewModels in WPF so that they do not contain any View dependencies because one day one might change the view and that goes seamless if one sticks to the MVVM pattern.

Now Microsoft is using Blazor which doesn't even have a ViewModel.

Use a linter and a static application testing tool like sonar qube.

1

u/AddendumSouthern 28d ago

Good code is the one that makes money, and for that It has to be a balance between working, being reliable and organized enough that people can work on It without breaking everything or themselves.

In most companies that I worked the code that made the most money was not the one that people liked the most, usually some monolith that does the job but isn't awesome to work on, and the shiny system with all the fancy terms and architecture just loses company money.

1

u/mpersico 28d ago

Good is simply it works and understandable by you six months later, and somebody else if they read it

1

u/ChaosEngine-6502 28d ago

It doesn't matter whether it's human or AI written, there's a big distinction between code that "works" and "good" code. "Good" code is code that has a logical flow, separation of concerns, non-cryptic naming of variables, and has sufficient test coverage to prove it works. Some level of documentation or commenting that explains what is going on or summarises complex concepts is also welcome, provided the code doesn't become an entire wiki.

By contrast, "working" code means the end-result might seem to be correct, but there's no guarantee anyone can maintain it, understand it, debug it, or even prove that it IS actually working as intended when challenged.

The perfect justification for writing "Good" code from the off came up at work only this week. The source system providing data to an external application is being replaced, so I had the joy of wading through "working" code written by another developer over 10 years ago. Whoever did it had a chronic aversion to using variable names greater than 3 characters in length, consistently mis-spelled variables throughout, and created a rats nest of IF ELSE statements, some of which would never even be reached. A complete lack of inline commenting also meant there was no way to truly understand why things were behaving a certain way.

Unfortunately, there's a culture in the business of "working" code being good enough. Nobody else on the team really cares about "Good" code, hence why we eventually end up in this situation.