Other peoples code
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
Andrew Torrance wrote: I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Doesn't sound all that quirky to me. :-D Paul I think there're pieces of me you've never seen - Tori Amos, Tear in Your Hand
-
Andrew Torrance wrote: I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Doesn't sound all that quirky to me. :-D Paul I think there're pieces of me you've never seen - Tori Amos, Tear in Your Hand
I find writing the comments first helps me plan out a function :) Davy Weblog, Ramblings and more... www.latedecember.com
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
I also like one exit point. Just seems like good coding technique. My quirk is that I use "temp" as a variable far too often i.e. temp1, temp2,... Very bad habit but I'm not as bad about it as I used to be. Later. Brad Jennings
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
I mostly agree with Bryce's comment below about comments (no pun intended), that code should be written in a way to be self documenting, which is achieved primarily through useful class, function, and variable names. However, I occasionally have to write some "algorithmic" code which is not obvious. My own quirk regarding comments is that I think they mostly make the code unreadable. Therefore, if the code is non-intuitive, I put comments just above the function name, and I comment important lines within the function or class. However, I still encounter companies where the rule is "don't go past 80 characters", so comments wrap (as does code!), and are placed inbetween lines of code. Argh! :mad: What is this? The days of teletype terminals? I typically place my comments way out beyond the right margin (at least 150 chars). But then, I also use screen resolutions of at least 1280x1024, and I set my text font to 8 pt. Of course, I'm probably going blind too! :rolleyes: I like the embedded XML comment capability of C#, but I find myself spending more time writing documentation than code. (Oh, that's the way it's supposed to be, isn't it). Marc Help! I'm an AI running around in someone's f*cked up universe simulator.
-
bryce wrote: think the best thing to do for your own coding is to ake it self documenting ergo needing little or no comments Comments aren't there for describing what the code does, they are there for describing why you are doing something. All code should be commented, so that in 3 months time you don't say "Why the **** did I do it like this" bryce wrote: Readable code is something which needs to be worked on as you code Quiet agree. Michael "I've died for a living in the movies and tv. But the hardest thing I'll ever do is watch my leading ladies, Kiss some other guy while I'm bandaging my knee." -- The Unknown Stuntman
Michael P Butler wrote: Comments aren't there for describing what the code does, they are there for describing why you are doing something. All code should be commented, so that in 3 months time you don't say "Why the **** did I do it like this" i dont know if i agree with this if the code is easy to read then you dont need comments do you? (added) a line of comment before each function is about all you need and to keep your functions short - 25 lines of code is all you need , anything more and it increases % of bugs and makesit harder to read/keep track of. course, that being said i'm not showing you my code ;) Bryce
-
i think the best thing to do for your own coding is to ake it self documenting ergo needing little or no comments if someone can't figure out whats going on fromthe code itself then the code itself is the problem. Something which should be taken into account at the time of writing, not later on :) Readable code is something which needs to be worked on as you code :) cheers Bryce
bryce wrote: think the best thing to do for your own coding is to ake it self documenting ergo needing little or no comments Comments aren't there for describing what the code does, they are there for describing why you are doing something. All code should be commented, so that in 3 months time you don't say "Why the **** did I do it like this" bryce wrote: Readable code is something which needs to be worked on as you code Quiet agree. Michael "I've died for a living in the movies and tv. But the hardest thing I'll ever do is watch my leading ladies, Kiss some other guy while I'm bandaging my knee." -- The Unknown Stuntman
-
i think the best thing to do for your own coding is to ake it self documenting ergo needing little or no comments if someone can't figure out whats going on fromthe code itself then the code itself is the problem. Something which should be taken into account at the time of writing, not later on :) Readable code is something which needs to be worked on as you code :) cheers Bryce
"Self-documenting" code is a myth. There's no such thing. I don't care how careful you are, reading comprehension and perception of almost EVERYBODY else will be all over the scale. I'm currently dealing with numerous projects where there is little/no comments in the code, and it's driving everybody working on those projects absolutely NUTS. Comment well, and comment often. Use complete sentences and spell correctly to lessen the chances of misinterpretation. Do NOT rely on external tools or the promise of external documentation. Even better, don't rely on anyone else to follow up and comment your code for you when they happen to have to look at it. As far as coding style, don't get any fancier than you need to get. Fancy usually means complex, and complex always means unmaintainable by new team members. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
-
Michael P Butler wrote: Comments aren't there for describing what the code does, they are there for describing why you are doing something. All code should be commented, so that in 3 months time you don't say "Why the **** did I do it like this" i dont know if i agree with this if the code is easy to read then you dont need comments do you? (added) a line of comment before each function is about all you need and to keep your functions short - 25 lines of code is all you need , anything more and it increases % of bugs and makesit harder to read/keep track of. course, that being said i'm not showing you my code ;) Bryce
I'll save my reply to this for his reply to my post. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
-
I also like one exit point. Just seems like good coding technique. My quirk is that I use "temp" as a variable far too often i.e. temp1, temp2,... Very bad habit but I'm not as bad about it as I used to be. Later. Brad Jennings
I like one exit point too, but a lot of times, that just makes the code hard to follow. Get the exceptions out of the way as early as possible, and then write the business end of the function. Otherwise, you'll have deeply nested code that is a bitch to follow. My rule is that if there's more than three levels of nesting needed to support the desire for a single exit point, it's best not to do it. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
-
"Self-documenting" code is a myth. There's no such thing. I don't care how careful you are, reading comprehension and perception of almost EVERYBODY else will be all over the scale. I'm currently dealing with numerous projects where there is little/no comments in the code, and it's driving everybody working on those projects absolutely NUTS. Comment well, and comment often. Use complete sentences and spell correctly to lessen the chances of misinterpretation. Do NOT rely on external tools or the promise of external documentation. Even better, don't rely on anyone else to follow up and comment your code for you when they happen to have to look at it. As far as coding style, don't get any fancier than you need to get. Fancy usually means complex, and complex always means unmaintainable by new team members. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
John Simmons / outlaw programmer wrote: 'm currently dealing with numerous projects where there is little/no comments in the code, and it's driving everybody working on those projects absolutely NUTS. sounds like you're saying the code is unreadable? John Simmons / outlaw programmer wrote: As far as coding style, don't get any fancier than you need to get. Fancy usually means complex, and complex always means unmaintainable by new team members. i'll agree with this :) simple stuff is nearly always better Bryce
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
I used to be a style fanatic, wanting everyone to use my coding standards, but over the years I have come to realize the following to be true. Can you read the code and understand its intent? Yes, coding style is good enough. No, something has to change. There are different levels to examine here, layout/names/spacing is the minor, and logic is the major. As long as the code is understandable and the logic is correct don't stress and worry over the minor. Unless its your own code and you are not proud of how it looks! :-D
-
i think the best thing to do for your own coding is to ake it self documenting ergo needing little or no comments if someone can't figure out whats going on fromthe code itself then the code itself is the problem. Something which should be taken into account at the time of writing, not later on :) Readable code is something which needs to be worked on as you code :) cheers Bryce
I totaly agree with John Simmons. Self documenting code is a myth. There is no way for the code to explain why you did it this way. Other than trivial functions you must explain why and what assumptions you are making. It is amazing how smart your were years ago and do not tell me you remember why you coded something last year. Or 10 years ago or 100 years ago, If the product you are supporting has a long life span it may very well be that the code behind it must be kept. So these figures are not made up! "We are what we repeatedly do. excellence, then, is not an act, but a habit." Aristotle
-
I like one exit point too, but a lot of times, that just makes the code hard to follow. Get the exceptions out of the way as early as possible, and then write the business end of the function. Otherwise, you'll have deeply nested code that is a bitch to follow. My rule is that if there's more than three levels of nesting needed to support the desire for a single exit point, it's best not to do it. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
John Simmons / outlaw programmer wrote: Get the exceptions out of the way Good point and I agree. There are allways exceptions. It bothers me when someone blindly follows absolutes that their instructors drilled into them. Even GOTO's have usage at times. I am not saying do not follow good practices. "We are what we repeatedly do. excellence, then, is not an act, but a habit." Aristotle
-
Andrew Torrance wrote: I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Doesn't sound all that quirky to me. :-D Paul I think there're pieces of me you've never seen - Tori Amos, Tear in Your Hand
Look at the code on this site , it is almost universal to find a return in a conditional statement . A single exit point means that return cannot be in such a segment of code. What starts off as trivial can end up growing into something painful. so I avoid things like.. if(MyVariable = true) return(); // The use of bracketted return is another quirk ! Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
-
I like one exit point too, but a lot of times, that just makes the code hard to follow. Get the exceptions out of the way as early as possible, and then write the business end of the function. Otherwise, you'll have deeply nested code that is a bitch to follow. My rule is that if there's more than three levels of nesting needed to support the desire for a single exit point, it's best not to do it. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
Do you follow any 'rules' when handling exceptions ? E.g dealing with them close to where they happen or appending data to them and rethrowing them ? There must be some good ideas on exception handling , but all I ever see are nuts and bolts type articles never any ones on good practices. Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
-
I used to be a style fanatic, wanting everyone to use my coding standards, but over the years I have come to realize the following to be true. Can you read the code and understand its intent? Yes, coding style is good enough. No, something has to change. There are different levels to examine here, layout/names/spacing is the minor, and logic is the major. As long as the code is understandable and the logic is correct don't stress and worry over the minor. Unless its your own code and you are not proud of how it looks! :-D
Justin Hallet wrote: As long as the code is understandable and the logic is correct don't stress and worry over the minor. Fair enough , but what is understandable to one person may be difficult for another if the style used is not what you are used to . Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
-
We all have our own styles of writing , how do you find other peoples styles ? I have a quirk in that my functions only EVER have one exit point , and the first thing I do in any function is to default any returned parameters. Looking at this site I seem to be in a minority of slightly less than two , so what I do must be quirky , anyone else have style quirks ? And how do you get on with other peoples quirks ? Am I the only one forever playing catch up with technology , while all the juicy opportunites keep rolling by ?
Objects should implement their own behaviour. This implies that methods do one thing, not 2, 3, 4. This from what I see does a lot for understanding the code, whether or not you actualjy wrote it. Also good for self-documentation even without // or /*. And also good for component code reusability.
How low can you go ?
(MS rant) -
"Self-documenting" code is a myth. There's no such thing. I don't care how careful you are, reading comprehension and perception of almost EVERYBODY else will be all over the scale. I'm currently dealing with numerous projects where there is little/no comments in the code, and it's driving everybody working on those projects absolutely NUTS. Comment well, and comment often. Use complete sentences and spell correctly to lessen the chances of misinterpretation. Do NOT rely on external tools or the promise of external documentation. Even better, don't rely on anyone else to follow up and comment your code for you when they happen to have to look at it. As far as coding style, don't get any fancier than you need to get. Fancy usually means complex, and complex always means unmaintainable by new team members. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
Hear Hear. No, hear hear!
David Wulff http://www.davidwulff.co.uk
"Unfortunatly Deep Throat isn't my cup of tea" - Martin Marvinski
-
"Self-documenting" code is a myth. There's no such thing. I don't care how careful you are, reading comprehension and perception of almost EVERYBODY else will be all over the scale. I'm currently dealing with numerous projects where there is little/no comments in the code, and it's driving everybody working on those projects absolutely NUTS. Comment well, and comment often. Use complete sentences and spell correctly to lessen the chances of misinterpretation. Do NOT rely on external tools or the promise of external documentation. Even better, don't rely on anyone else to follow up and comment your code for you when they happen to have to look at it. As far as coding style, don't get any fancier than you need to get. Fancy usually means complex, and complex always means unmaintainable by new team members. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
I definitely agree with you, John. Additionally, people who aren't expert coders in whichever language your using, might have to come after you to maintain it, for whatever reason. Additional comments will be greatly beneficial to these folks. In both my last two programming jobs, I've had to learn languages while working on projects, and good commenting helped tremendously, thereby saving my employer money. Helping people understand your code, is all about saving time. If an added comment will clarify things later, just do it. No need to be stubborn about it. BW "I'm coming with you! I got you fired, it's the least I can do. Well, the least I could do is absolutely nothing, but I'll go you one better and come along!" - Homer J. Simpson