What would be the main attributes of good code?
For further actions, you may consider blocking this person and/or reporting abuse
What would be the main attributes of good code?
For further actions, you may consider blocking this person and/or reporting abuse
Phil Wolstenholme -
Philipp Renoth -
Michael Di Prisco -
GrahamTheDevRel -
Once suspended, juliatorrejon will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, juliatorrejon will be able to comment and publish posts again.
Once unpublished, all posts by juliatorrejon will become hidden and only accessible to themselves.
If juliatorrejon is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Julia Torrejón.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag juliatorrejon:
Unflagging juliatorrejon will restore default visibility to their posts.
Top comments (65)
There's a really great chapter about this in "Game Programming Patterns" by Robert Nystrom:
Be sure to read the whole thing!
I like this a lot. "Accommodation to changes" accounts for readability, organization, testing, and a lot of other things bundled in.
Coding only for the problem at hand right now: Bad.
Coding for every possible future need: Bad.
Coding to solve current problems while being accommodating towards future modifications: Good.
I have seen this scenario a few times and it obviously delays the whole project because requirements keep changing and so does the code.
This. There are few things that I feel like are as satisfying as being like "Oh crap, I need to make sure it can handle ABC" or "I need to change it for this new thing" and realizing you wrote it such that sure, it does need to change somewhere, but it has that capability for change without things getting messy. The opposite of having to add more and more logic to handle cases.
A few points taken from Robert Nystrom are:
High quality code is the one that has a low wtf/hour ratio
😅
This is the one and only true metric for good code quality. It never fails.
Exactly so, although I think that per minute would be a really big number hahaha.
An interesting point from Gridshore on this:
Definition:
Attributes:
It's like art vs obscenity; I know it when I see it.
So, what would be the optimal time? Or is it somehow subjective depending on the circumstances?
It's subjective and variable depending on the circumstances:
There's an implicit assumption that you can't spend "forever" on a piece of code; at some point it's got to be "good enough" so you can move on. It's also subject to diminishing returns.
To me, high quality code means less lines of code, but has more power. That power might be a useful abstraction, or it's just a useful algorithm to solve repeatable problems.
And if you want more quality of your code, make it easy to test, the easier to test a code block, the more quality that code block has.
And if you want even more quality of your code, make it fast. If your language couldn't make it fast enough, change the language.
How can you make your code faster?
"Make it fast" means you should use better algorithms or data structures to solve the problem. Because as you know, to solve one problem, there're many ways to do it. So it's also called optimization of the code to use better libraries, for example.
Personally, the more that code reads like prose, the higher quality it is. High quality code tells you the story about the business solution that it is implementing.
My favorite code is that which reveals to me something about the business that I did not previously know. Plus, like businesses, it’s written in a way to accommodate the future only when the future arrives.
Maintainable and efficient.
Maintainable means it is easy to understand, sensibly organized, it is painless to make modifications that should be expected (client wants to add another type of report), and as easy as possible to make changes that aren't (client wants a totally new feature)
Efficient means the code uses as few resources as possible to accomplish its job, so that it is as fast and scalable as possible.
Uncle Bob says:
That is good advice for a beginner!
It is written in C.
Could you explain why?
I'm going to use the #likeimfive approach here.
If code is like cake, then good code is like cake that you can enjoy eating and that will not leave you with stomach aches later on.
Note that 'doing what it is supposed to' is not an attribute of good code any more than 'being edible' is an attribute of good cake. That's just a fundamental real-world requirement for when someone asks you to write code / bake a cake. It doesn't have anything to do with either of those being good.
Just to highlight.. so you mean cake is considered good based on the experience of eating it.
In the case of cake, yes. How that translates to code is that code is also experienced as being good by how you interact with it later, i.e. modifying it in any way (rather than just looking at it).
In my opinion "good" code is the one that is disposable. Is a codebase where you can identify with confidence the parts that need to be changed or removed in order to make a new feature or meet a new requirement.
You won't necessarily recognize it when you see it or when you write it for the first time, but you'll know when the times comes and you have to mantain it.
My personal definition is very subjective: A code is of high quality if
High quality code is code written by someone who cares.
What does it mean to care?
Knowing the language beyond the syntax, i.e. writing concise ideomatic code
Naming things in a way which helps understanding the purpose of things
Grouping things together, which belong together
Or as Ward Cunningham once put it:
I heared once, that instead of naming it »software engineering« it should be renamed to »software gardening«. This would connotate the constant effort which has to be put into a codebase in order to keep it beautiful and keep weeds at a minimum.
I’ll chime in with some characteristics I try to impart to my code:
The projects I've worked with that had the best codebase to them actually made it difficult to write bad code with it. Bad code typically comes when there is too much going on and it is not well abstracted, so developers have trouble understanding it and end up writing more bad code, making the problem even worse.
In contrast, a good codebase has very clearly-defined structures and well-architected patterns that guide you toward the solution intended by its creators.
For example, Laravel was created for a specific purpose, and every API it opens up to developers drives you right where it wants you. You really have to put in a lot of work to use Laravel in any way other than it was designed for, and the way it encourages you to develop in it feels very natural and clean. The underlying codebase of Laravel is what I consider to be the best codebase I've ever seen and worked with.
Comparatively, Android's codebase is a bit of a mess. Don't get me wrong, I love Android and it is my favorite platform to develop for, but its codebase is messy and confusing, needlessly complex, often contradictory, and with very little direction given to the developer. It is definitely getting better now that it has matured the core framework, with Google starting to focus on better APIs for UI components and a more opinionated approach with Jetpack, but I still struggle to understand how most of the internal classes work, no matter how long I study their code.
Therefore, a good codebase is the base of good code, isn't it? :)
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.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.