Ask Slashdot: What Makes Some Code Particularly Good?
itwbennett writes: When developers talk about what makes some source code particularly 'good,' a handful of qualities tend to get mentioned frequently (functional, readable, testable). What would you add to this list?
When it's mine.
Doesn't every self important developer think that their own code is the best?
How many managers does it take to reach a decision to begin a study to determine whether a light bulb should be replaced?
I'll see your senator, and I'll raise you two judges.
Code needs to fail in an easy to understand and predictable way. If possible and practical provide descriptive and easy to follow details through logging or return values...
And say "thank you, my past self for making this so easy to understand and versatile!".
Good code feels obvious and self-evident, as though its design springs directly from the problem, rather than from the cleverness of the developer.
Good code is free of regret; regardless of how much it's been modified and refactored, it feels as though it was written in a single sitting, by a developer who somehow knew the right way to do it already.
Good code is not just readable, but inviting. It feels as though there is no wrong place to start reading it.
Good code doesn't have a single goddamn class named "Manager".
The opinions stated herein do not necessarily represent those of anybody at all. Deal with it.
That it works.
Lots and lots of GOTO NNNN and I know it's good code!
-The wise argue that there are few absolutes, the fool argues that there are no probabilities.
I think i can shed light on this subject, having several years experience in this field. New programmers and seasoned alike often make this mistake, either through carelessness or ignorance. When working to write good code, you must make sure to set good="yes" or good="veryyes." ive written code for 20 years now and this has only ever failed me in PHP. Apparently the language does not support "good" code.
Good people go to bed earlier.
If you have no rhyming variable names, then your code sucks. 1 stars
If you have one or two, it is barely acceptable. 2 stars
Half rhyme, then 3 stars.
If most, but not all, rhyme, 4 stars.
If every single variable rhymes with at least one other variable, you have a great job, 5 stars.
To get the coveted 6 stars, all the variable names have to rhyme with each other.
excitingthingstodo.blogspot.com
When it's written by a gender and race balanced team, in a positive, multicultural environment, then it's good code!
For newly written code, things like readability, testability, and maintainability all can come in to whether it is "good" or not
For legacy stuff, Good code is code that works. Who cares how easy it is to read or test as long as it works?
The second one should also include "immutable". If it's hard to understand it will evolve easily to non working, and time spent on improvements can start to creep up very fast.
I have worked in very clever, solid code, but not easy to read. It was then maintained and extended by average, but competent programmers down the road, and turned into a big mess, only because it was so hard to understand.
In my experience, good code is easy to read, above all. That will make it easy to extend it coherently, find bugs and stuff. Also, if it doesn't work OK, it's easy to find out why. The single metric that saves time, money, and improves quality down the road is readability. Eveything else should be suject to that.
And, about the last point in the "article", "efficient", it's nonsense. Premature optimization is the root of all evil. You should _always_ follow the second rule of optimization (see http://c2.com/cgi/wiki?RulesOfOptimization ).
It communicates clearly what it is trying to do.
It doesn't, actually. Looking at that as someone who doesn't know what a CRC32 is I have no idea why it's doing what it's doing. Some actual useful comments might be nice.
After 5 years you can still read it and understand what it was supposed to accomplish, and it does so.
I would definitely add "simple". Everybody can write complex code but it takes experience and great knowledge to be able to choose the best fit for the implementation. More experience and knowledge you have more options to choose from. Beginner will usually go with the first hunch that will get complex sooner or later as he will meet challenges he didn't expect...
So yeah, simple, readable, documented, functional, consistent...
Well, I've got to get back to work. When I stop rowing, the slave ship just goes in circles.
Good code has documentation for knowing what it should do, and has unit tests to verify that it actually does that. If there are any problems good code can be modified to meet the (possibly changed) requirements better, while unit tests ensure the modifications do not make the code worse. Code which cannot be modified is not good code. It's that simple.
Their whole mindset still makes me want to puke.
Obfuscated crap. Techno-machismo teens playing games trying to get their code into the least number of characters and the least amount of memory. I've had to fix or test so much of this junk and it's still just plain stupid.
The *human* part of the system is what *matters* and that includes the code interface. First, I want comments not about *what* is happening. I can read that. I need to know *why* it was done, so I don't undo it, or I can do something different safely. Comments should be one liners, limited to "why" and sometimes "how".
If adding a variable aids readability, add the fucking variable! Shove all the results into a meaningful, readable variable name and then shove *that* into your function argument, not some long series of nested function. It's not the 90s. You don't have to save memory! Memory is there to make your code readable. Use it!
Ok, rant over. I'm going back to work now.
Please do not read this sig. Thank you.
What if the comment is // this code sucks.?
Who ordered that?
FACT: The PC to Server ratio is MILLIONS to 1 alone
This does not stand to even 5 ms of thinking. I am living in a country with 5 million people. You are claiming we have 5 servers or something like that.
Or if you are an american: How many cities do you have with more than 5 million people? How many cities with more than 5 servers? ...
Or ... there are about 7 billion people on the earth. Lets assume that each have a PC (many don't). You are claiming there are only 7000 servers on earth.