TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What is good code? A scientific definition

48 pointsby xomateixabout 10 years ago

14 comments

mcphageabout 10 years ago
I feel like this just replaces one vague word &quot;good&quot; with a bunch of other vague words like &quot;readable&quot; and &quot;maintainable&quot;.<p>Like of course, maintainable is good. But what makes code maintainable? When we&#x27;re teaching new developers, what do we tell them to do to make their code maintainable? How do we distinguish between code that is maintainable, and code that is not maintainable? That&#x27;s really the important thing; just knowing it should be &quot;maintainable&quot; doesn&#x27;t particularly help.<p>And &quot;readable&quot; is even more complicated. Sure, there are some syntactic things that help readability—consistent indentation and spacing, good variable names, organized files, shorter lines. But beyond that it kinda breaks down. What makes a method readable? Well, probably a small number of lines, few branches, single purpose. That&#x27;s good. But when you extend that to a codebase, you end up with code that you need to jump between a dozen methods to follow what happens in any given call. Is that readable? Or if you look at it from a class level, having a few methods where the whole chain of logic is in a single place is readable—but then you end up with giant god methods that do way too much. Is that readable? Presumably the balance is somewhere in the middle, but how do we recognize it? Just saying code should be &quot;readable&quot; doesn&#x27;t really help.<p>Or &quot;covered by automated tests&quot;—definitely tests are helpful. Except for bad tests, which are harmful, and make fixing bugs or refactoring a painful process. So &quot;covered by tests&quot; can be good, or it can be bad, and adding the wrong tests can make your codebase worse. How do we distinguish between good tests and bad tests?<p>So I agree that the things mentioned are true about good code, but way too vague to help write better code.
评论 #9185058 未加载
评论 #9184552 未加载
评论 #9184567 未加载
评论 #9184418 未加载
评论 #9184913 未加载
评论 #9184766 未加载
codingdaveabout 10 years ago
I&#x27;m always surprised that &quot;It works.&quot; is not #1 on these lists.<p>I get that as developers, it really matters quite a lot whether the code is good. But on a higher business level, software development is a tool, and the most important thing to the business is that it works. Working well and making it better and more efficient are incremental improvements to the business... but code that doesn&#x27;t work is a deal breaker.<p>Beautiful readable, testable, maintainable code that fails to meet the business need is still a failure.
评论 #9184193 未加载
评论 #9184147 未加载
评论 #9184470 未加载
评论 #9184300 未加载
mhomdeabout 10 years ago
My definition is another: &quot;Great code contains maximum entropy towards to its purpose while being easily understandable and maintainable.&quot;<p>Each part is interconnected to ensure quality and efficiency:<p>1. Maximum entropy means that your codebase should contain as much concentrated &quot;information&quot; as possible in relation to its size. Free of copy &amp; paste code and repetitions that can be reused in libraries, methods and classes. This ensures less code to maintain , easier to spot bugs and easier to spot patterns.<p>2. Understandability (that includes readable): That means no blob classes or methods with an infinite number of purposes. Each layer of abstraction simple enough to keep in mind in its entirety.<p>3. Maintainable: It should be bug resistant, making it hard to do the wrong things and easy to do the right (for example putting required parameters into constructors rather than fields or properties). You should be able to replace and&#x2F;or modify individual parts without side effects. Having as little code as possible also helps with this.<p>I think &quot;covered by automated&quot; tests are nice ... in some cases. It is far from a rule that they&#x27;re a panacea for every kind of project, code and&#x2F;or situation nor are all kinds of code wort the effort (models &amp; algorithms: yes, UI: usually no). It also depends on the team and methodology.<p>That good code does what its suppose to do and should be bug free should be a given :)
评论 #9184772 未加载
评论 #9184360 未加载
评论 #9184368 未加载
bnegreveabout 10 years ago
There is this paper [1] by John McCarthy on what he calls Elaboration Tolerance:<p><i>Elaboration tolerance is the ability to accept changes to a person’s or a computer program’s representation of facts about a subject without having to start all over.</i><p>This could make a good definition of what is &#x27;good code&#x27;.<p>[1] <a href="http://jmc.stanford.edu/articles/elaboration/elaboration.pdf" rel="nofollow">http:&#x2F;&#x2F;jmc.stanford.edu&#x2F;articles&#x2F;elaboration&#x2F;elaboration.pdf</a>
koja86about 10 years ago
&quot;Second, because if you write good code chances are that the product you are building will be much better.&quot;<p>If &quot;better&quot; means anything related to user experience, adoption or commercial success I think that correlation is about zero. Even the dumbest idea can be implemented by good code.
评论 #9184287 未加载
rubicon33about 10 years ago
I&#x27;m not surprised readable is so highly ranked, nor do I disagree that it should be. I am however somewhat surprised that SOLID doesn&#x27;t have a higher representation. I find that in general, as long as you keep code clarity and readability sacred, you can write testable code by following the SOLID principles. Seems to me it provides the basis of &#x27;good code&#x27;.
jacknewsabout 10 years ago
Does that company even care?<p>Their team page at <a href="https://www.intenthq.com/about-intent/" rel="nofollow">https:&#x2F;&#x2F;www.intenthq.com&#x2F;about-intent&#x2F;</a> looks like a classic British social class structure; the people-people, so-called &quot;movers and shakers&quot; at the top, the mere techies all scurrying around on the bottom rungs, and QA almost falling off them. Even the office admin is presented above all the technical people.<p>Anyway, negative, small-minded and snide observations aside, here&#x27;s my totally unscientific summary of their completely scientific survey:<p><pre><code> Readable Simple (as in not entwined) Functional&#x2F;Verifiable Maleable&#x2F;Maintainable Composable&#x2F;Reusable Efficient </code></pre> But of course all of these aspects are also very subjective.
kyledabout 10 years ago
Great code is mostly pure, dense, defines clean interfaces, and favors composition and reuse. Maintenance, testability , readability etc. are just side effects of well written code.
评论 #9184352 未加载
fit2ruleabout 10 years ago
The only metric that matters: there is a user, using the software.
评论 #9184536 未加载
j2kunabout 10 years ago
Well is it scientific or pseudo-scientific? In all seriousness, I assume when you ask someone what makes good code, they will assume the code is correct already.
评论 #9184328 未加载
评论 #9184334 未加载
dhimesabout 10 years ago
OT: I need a css style editor that is point-and-click (or copy-and-click) simple. (I currently use Stylish.) I need something that lets me select a paragraph, adjust a style, and it automagically adjusts the class&#x2F;id style for the page. This light text stuff blows- and unfortunately it kind of biases me against his ability to determine &quot;readabilty&quot; even though that is completely unfair.
mikewardleabout 10 years ago
I would define good as Fit for purpose, Maintainable, and id judge this primarily by SOLID Tested, prefferably TDD aor BDD and finally not iver commented, good code should convey what it does without the need for comments, and as code evolves, comments rarely are updated.
snarfyabout 10 years ago
Good code looks like Carmack&#x27;s code.<p><a href="http://www.codergears.com/Blog/?p=1313" rel="nofollow">http:&#x2F;&#x2F;www.codergears.com&#x2F;Blog&#x2F;?p=1313</a>
评论 #9184746 未加载
nathankleynabout 10 years ago
<i>Good code is written so that is readable, understandable, covered by automated tests, not over complicated and does well what is intended to do.</i><p>Couldn&#x27;t agree more.
评论 #9184469 未加载