What is good code?
-
That's because musicians (and many others) have no UNDO.
Here is an example of programmers with no undo[^] - it performed as designed, but I'm fairly certain it did not perform as intended ...
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)All criteria must be met: 1) Meets statement of purpose 2) Easy for the uninitiated to read and bug fix 3) Easy to check out of SVN 4) Easy to refactor 5) Safe to make changes When I write code I aim to hit these points. Other more "senior" developers often snicker when I don't use an inline LINQ statement that spans several lines that connected to an automagic data source, that requires EF v (who cares) to be installed before it can be debugged. Instead, I like a couple of well intentioned class files and the .NET Framework. Sure, it may be more verbose but any idiot can debug it; and that is who will be replacing me.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)I identify "good" code as being code that:
- works as intended
- is easy to understand (and therefore debug)
- is easy to extend
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
S Houghtelin wrote:
we’ve been auditioning for a fourth member
Damn, too far away. sorry :-D
V.
I suppose travel for the weekly practice would get kind of expensive. :-D
It was broke, so I fixed it.
-
The original point was that code works as designed Basicly coding is design work, and can be seen as the last iteration of the whole design process.
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile
-
Espen Harlinn wrote:
Basicly coding is design work, and can be seen as the last iteration of the whole design process.
Yes it can seen like that. Simply I don't see it like that.
Veni, vidi, vici.
CPallini wrote:
Yes it can seen like that. Simply I don't see it like that.
Most people don't - personally I think it would be a good thing if they did.
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Good code is a little code. If I see you’ve achieved the goal with minimum efforts in coding and maximum in thinking, for me you’re okay and I’ll be glad to work with you.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
This so spot on. Good code is in part measured by how it is used. I don't often bookmark posts, but I did yours. It needs to be re-iterated every time someone asks again about code quality and how to determine it. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
Thanks, Chris. After 30 years doing a job, and making and cleaning up a fair share of messes, you figure a few things out.
Software Zen:
delete this;
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Good code follows these 4 principles: 1. It works and gets the job done. 2. It is the least code that will do the job and no more. 3. It is efficient and performant. 4. It is easy to maintain and extend. These are all things that any programmer worth his salt can do for himself. If you can't ensure your code follows these simple principles then get a different profession.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun -
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Some people seem to be confusing what good code is and what a good developer is. They're not the same thing. A good developer has no problem writing substandard code. If it's a prototype, they might consider writing substandard code. Good code may be written by a bad developer (or a good developer making a bad decision). The code could be a shining example of excellence, but if it took too long and wasted an employer's time, it was a bad decision to write it so well. If the code isn't in source control, that's a bad decision for good code. As far as good code goes, that can vary based on context, but even some of the rules for contextually good code can be generalized:
- Code in the same style as the rest of the code base.
- The above can have exceptions. If you have a new code file and the rest of the code base has crap style, code your file in a better style to set a good example.
- Don't waste CPU cycles. Don't waste memory.
- Waste CPU cycles and memory when it will make the code much more clear or faster to write.
- Some code lives longer or is more widely used than other code. That code should have higher quality.
- Avoid security vulnerabilities (e.g., SQL injection).
- Code that makes use of other good code rather than reinventing the wheel is good code.
- As a corollary, avoid copy/paste code.
- Patterns are good, except when they're not. If the cost of the complexity is greater than the benefit it adds, it's not good.
- Code should be written to adapt to likely change. If you think a feature will be added later, leave room for it to be added without making it a breaking change.
The list could go on and on and vary significantly depending on context.
-
Just because code works, does not mean it is good.
There are only 10 types of people in the world, those who understand binary and those who don't.
When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012) -
Some people seem to be confusing what good code is and what a good developer is. They're not the same thing. A good developer has no problem writing substandard code. If it's a prototype, they might consider writing substandard code. Good code may be written by a bad developer (or a good developer making a bad decision). The code could be a shining example of excellence, but if it took too long and wasted an employer's time, it was a bad decision to write it so well. If the code isn't in source control, that's a bad decision for good code. As far as good code goes, that can vary based on context, but even some of the rules for contextually good code can be generalized:
- Code in the same style as the rest of the code base.
- The above can have exceptions. If you have a new code file and the rest of the code base has crap style, code your file in a better style to set a good example.
- Don't waste CPU cycles. Don't waste memory.
- Waste CPU cycles and memory when it will make the code much more clear or faster to write.
- Some code lives longer or is more widely used than other code. That code should have higher quality.
- Avoid security vulnerabilities (e.g., SQL injection).
- Code that makes use of other good code rather than reinventing the wheel is good code.
- As a corollary, avoid copy/paste code.
- Patterns are good, except when they're not. If the cost of the complexity is greater than the benefit it adds, it's not good.
- Code should be written to adapt to likely change. If you think a feature will be added later, leave room for it to be added without making it a breaking change.
The list could go on and on and vary significantly depending on context.
Your points are well made but I don't think you understood the point of my question. Some of the members who responded to my question, understood what I was trying to get to. Your list of 1-10 is what seems correct...for you. However, I don't agree with most of your list as criteria for good code. Does this mean I'm right? Of course not. Therein lies my point.
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012) -
When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997John Simmons / outlaw programmer wrote:
When you're on a tight schedule, if it was what it's supposed to do, it's "good" code.
You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...well said.
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012) -
Your points are well made but I don't think you understood the point of my question. Some of the members who responded to my question, understood what I was trying to get to. Your list of 1-10 is what seems correct...for you. However, I don't agree with most of your list as criteria for good code. Does this mean I'm right? Of course not. Therein lies my point.
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Your question and assertion seem to be based around the fact that good code is not knowable. This is much like the philosophical argument that right and wrong are subjective and any objective determination cannot be made. I largely agree with those concepts, however I also question the necessity of finding objective determinations of what is good/right/wrong/etc. Such an answer really only has relevance among sentient beings such as humans. The quality of code especially so (not too many platypodes care about the style of brackets you use). And code quality will be relevant to certain humans more than others. There are many dimensions to relevance you could use to judge code quality. For one, a customer probably cares most about how well the code functions (e.g., that it is bug free). However, customers can be pretty ignorant, so they may be unable to judge that code is future-proof, which saves them money (even if they are unaware of it). Then there is your boss. He might care most about getting things done in a timely manner. From his perspective, getting things done fast makes you a quality coder, but whether that means your code is good or not depends on the perspective. From your collegue who was educated with 3 PhD's, maybe your code doesn't look as pristine as she'd like. However, your practical nature might conclude that pristine code is a waste of time, or you might have a different idea of what pristine code looks like. Much like morality, judgement of good or bad depends on the perspective, and that perspective can vary depending on how you want to select a group. You may be right that there is no objective measure of good code. However, that does not mean that, say, the .Net community does not have a few guidelines. And I'd also add that the larger your group is from which you are considering a perspective, the more generic you can be in declaring rules for quality. There may be some absolutes from the widest perspective (all humans), but by that time they may be so generic as to be useless to you on a specific level. So I guess this is really a bigger discussion. One that probably wouldn't be resolved any sooner than the "right" philosophy is achieved. :)
-
When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997John Simmons / outlaw programmer wrote:
ignoring (or ignorant of) the realities of real-world development
I don't think so. In real world development, sure a schedule may be tight and it may be necessary to write code that is not 'as good as it could be' just to get it out the door, or to fix an urgent bug. But that still isn't good code, it is just working code. If it is left as-is, and the code base is modified over time, then such code can cause more and more issues (as you must know) If you're a good, experienced, programmer, then the likelihood of quickly developed code being poor is less, but we all know we sometimes cut corners to get the job done - and we all know it comes back to bite us (or our successor) in the bum when that happens. If someone writes hundreds of lines of spaghetti code to achieve what could have been written in a few lines of well structured code, by your measure, it is good code if the output is as required. But a part of the output should be the codes longevity and maintainability, not just the function return value.
MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)this is good code according to JSOP (to save you compiling and building it, it is a flight simulator) and it works.
#include
#include
#include
#include
double L ,o ,P
,_=dt,T,Z,D=1,d,
s[999],E,h= 8,I,
J,K,w[999],M,m,O
,n[999],j=33e-3,i=
1E3,r,t, u,v ,W,S=
74.5,l=221,X=7.26,
a,B,A=32.2,c, F,H;
int N,q, C, y,p,U;
Window z; char f[52]
; GC k; main(){ Display*e=
XOpenDisplay( 0); z=RootWindow(e,0); for (XSetForeground(e,k=XCreateGC (e,z,0,0),BlackPixel(e,0))
; scanf("%lf%lf%lf",y +n,w+y, y+s)+1; y ++); XSelectInput(e,z= XCreateSimpleWindow(e,z,0,0,400,400,
0,0,WhitePixel(e,0) ),KeyPressMask); for(XMapWindow(e,z); ; T=sin(O)){ struct timeval G={ 0,dt*1e6}
; K= cos(j); N=1e4; M+= H*_; Z=D*K; F+=_*P; r=E*K; W=cos( O); m=K*W; H=K*T; O+=D*_*F/ K+d/K*E*_; B=
sin(j); a=B*T*D-E*W; XClearWindow(e,z); t=T*E+ D*B*W; j+=d*_*D-_*F*E; P=W*E*B-T*D; for (o+=(I=D*W+E
*T*B,E*d/K *B+v+B/K*F*D)*_; p K)N=1e4; else{ q=W/K *4E2+2e2; C= 2E2+4e2/ K
*D; N-1E4&& XDrawLine(e ,z,k,N ,U,q,C); N=q; U=C; } ++p; } L+=_* (X*t +P*M+m*l); T=X*X+ l*l+M *M;
XDrawString(e,z,k ,20,380,f,17); D=v/l*15; i+=(B *l-M*r -X*Z)*_; for(; XPending(e); u *=CS!=N){
XEvent z; XNextEvent(e ,&z);
++*((N=XLookupKeysym
(&z.xkey,0))-IT?
N-LT? UP-N?& E:&
J:& u: &h); --*(
DN -N? N-DT ?N==
RT?&u: & W:&h:&J
); } m=15*F/l;
c+=(I=M/ l,l*H
+I*M+a*X)*_; H
=A* -
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Slacker007 wrote:
We obviously cannot make this determination about ourselves or our code. So who does?
Good Houskeeping magazine. They hand out the Seal of Approval for all sorts of things. So you could write to them. ;P
-
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012) -
Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?
"the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
"No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)Not being a professional programmer myself; only a hobbyist, I would say that good code is code that gets the job done in the most efficient (from a performance point of view), understandable (from a readability point of view) manner and that this will be self evident to anyone viewing the code.