DEV Community

Julia Torrejón
Julia Torrejón

Posted on

How would you define high quality code?

What would be the main attributes of good code?

Latest comments (58)

Collapse
 
capsule profile image
Thibaut Allender

Well, if your answer is as undocumented as your code, I hope I never have to read any of your code...

Linux code follows Linus Torvalds principles, and they are notoriously harsh:
infoworld.com/article/3000564/linu...

So, no, it's not just about accomplishing the task.

Collapse
 
lmbarr profile image
Luis Miguel

Once I heard..."It is a good code if the cost to change the code is minimum" or something like that.

Collapse
 
mkenzo_8 profile image
mkenzo_8

-Well executed
-Clean Code
-Documentation

(optional hehehe)
-Open source

Collapse
 
piotroxp profile image
Piotr Słupski • Edited

My opinion is that high quality code has the following characteristics:

  • takes at max a week or two to merge your first PR due to verbosity and good architecture
  • is enjoyable to read and modify even if written in a language that is not your primary one, allowing you to introduce changes quickly
  • uses good abstractions and is kept solid and dry

I think those three makings translate to ease of introducing change, quick developer onboarding, rapid prototyping and pattern-first programming, greatly increasing productivity.

Very nice question @julia !

Collapse
 
skkeeper profile image
Fábio André Damas

But it does matter. If you ever had to do any sort of code maintenance or expanding of existing code this is obvious. Code that is "clean"/"good" is easier to work with. "Does the code work?" is very important, but it doesn't even begin to be good code.

These books you mention, I would love to hear your arguments against their actual point instead of dismissing them by mentioning Linux or any other project, since that's not really the point.

Collapse
 
ghost profile image
Ghost

Cheap and easy to maintain!

Collapse
 
karthikchintala profile image
Karthik Chintala
  • Fewer lines of code in methods.
  • Code following SOLID Principles.
  • Code should be understandable easily when you look at it.
Collapse
 
juliatorrejon profile image
Julia Torrejón

Uncle Bob says:

The answer to clean code is craftsmanship.

There are two parts to learning craftsmanship: knowledge and work. You must gain the knowledge of principles, patterns, practices and heuristics that a craftsman knows, and you must also grind that knowledge into your eyes and gut by working hard and practicing.

Learning to write clean code is hard work. It requires more than just the knowledge of principles and patterns. You must sweat over it. You must practice it yourself, and watch yourself fail. You must watch others practice it and fail, You must see them stumble and retrace their steps.

That is good advice for a beginner!

Collapse
 
xdefrag profile image
Stanislaw Mnizhek

Well, there is a lot of books, articles and talks for that matter, but all of them lead to two things: low coupling and tests.

If it's feature, it must be connected to codebase through interfaces and properly tested (mocks, benchmarks for critical parts etc).

If it's refactoring, tests must remain untouched.

Looks pretty simple, but it's not.

Collapse
 
r0f1 profile image
Florian Rohrer

My personal definition is very subjective: A code is of high quality if

  • someone other than the author can read and understand it, without investing too much time and coginitive effort
  • it follows the conventions of your field (using familiar variable names, familiar abbreviations, familiar unit systems), whatever they might be.
  • and one thing (source file / class / package) solves one task.
Collapse
 
codevault profile image
Sergiu Mureşan • Edited

Ideally it should have all these properties:

  • Readable
  • Maintainable
  • Robust
  • Flexible
Collapse
 
zeddotes profile image
zeddotes

That's not necessarily true in all cases.

You write code as language for a computer. When you speak to another person, whether it's functional or an expression, you can say it in multiple ways -- all accomplishing the same task, in bad, good, great, and best ways. "Accomplishes the task" is ambiguous, as is the task's definition. For example, a task to display an RSS feed on a page is different for a junior dev vs an intermediate, or even another junior dev. It's very well different for different types of people, roles, cultures, etc.

Code quality measurement is like checking someone's health. If your life purpose was defined with 100% accuracy and our biotech was 100% accurate could one accurately determine a person's health exactly. Because we're far from that point, we make estimations based on multiple dimensions like weight, height, sugar levels, etc; similarly, we have test coverage, penetration/smoke testing, analytics, user group sessions, etc.

Collapse
 
n0ob__ profile image
anta

Professionally I do not even have an experience to use for reference, but as a student I would say this:
-> Quick run
-> Quick reading
-> easy to understand

Collapse
 
joshualjohnson profile image
Joshua Johnson

Quality code is stable and easily maintained.

Collapse
 
nestedsoftware profile image
Nested Software • Edited

I’ll chime in with some characteristics I try to impart to my code:

  • simple: keep the code as simple as possible. Avoid over-engineering.
  • readable: make the intent of the code as clear as possible.
  • orthogonal: give modules of code clear and independent responsibilities. Ideally modules that work together should be composable in any combination.
  • tested: code should have automated tests by default.
  • graceful with errors: modules should have well thought out considerations for edge cases and error conditions.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.