Is there such as thing as a inorrect code?

Programming Philosophy Question

I’ve completed the course up to the RPN Calculator, and currently watching the RPN walkthrough. Throughout this course, when tackling large complex codes, I find myself writing code that works and completes the Rspec, but the code during the walkthroughs tend to be slightly (or in the case of the RPN calculator largely) different. Sometimes I look at it and think “Oh hey, that’s a smart way to do this”, and in others I think “Well, mine gets the job done, I don’t see a major difference in the two different methods”.

This may sound more philosophical than anything but my question comes down to:

Is there such thing as incorrect code? Or is there only “Good” and “Bad” code?

And what would be considered bad coding vs good coding? The problem is solved in two different ways, so what is the deciding factor for which of the two would rather be used in the real world?

Very good question! I would say that incorrect code is code that doesn’t work. If code runs, then you get into the realm of “good” vs “bad” code. Deciding whether code is “bad” or “good” depends on the lens you’re using to look at your code. In some cases, memory/space is important. In others, speed is important. There will be benefits and caveats to every solution to a problem, and those are considerations you’ll have to take into account as you progress in your career.

1 Like

There definitely is such a thing as code that’s so bad it’s almost good:


There is also a symptom called “code smell”, and an empty line (in methods) also has a smell.