User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 17 Jan 2003, 08:20   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Question Commenting C & C++ code

How do you comment your C and C++ (or any similar) code? I'm wondering because I don't have a generic way of doing this myself.

Any tips?

TY
Structural Integrity is offline   Reply With Quote
Unread 17 Jan 2003, 08:43   #2
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Code:
/*************************************************
* Function:  foo                                 *
* Use:  What the hell it's used for.             *
* Description of arguments goes here.            *
* Variable list in here.                         *
* Notes:  Specific things to point out (if any). *
*************************************************/

int foo (char bar)
{
}
No comments in functions themselves, if the code needs it it's too complex for easy maintenance.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!

Last edited by Gayle29uk; 17 Jan 2003 at 10:22.
Gayle29uk is offline   Reply With Quote
Unread 17 Jan 2003, 13:33   #3
Nodrog
Registered User
 
Join Date: Jun 2000
Posts: 8,476
Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Nodrog has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
A line or two before any functions that dont have obvious names to explain what they do, and a single line comment next to any variable that isnt used for something obvious.
Nodrog is offline   Reply With Quote
Unread 17 Jan 2003, 14:30   #4
djbass
mmm.. pills
 
djbass's Avatar
 
Join Date: Apr 2000
Location: Australia
Posts: 2,152
djbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond reputedjbass has a reputation beyond repute
What's the point in writing illegible code if you're going to explain it all to them?

=[DJ Bass]=
__________________
CSS : the result of letting artists design something only an engineer should touch.
djbass is offline   Reply With Quote
Unread 17 Jan 2003, 14:35   #5
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by djbass
What's the point in writing illegible code
All jokes about 'job security' aside, legible code is almost always better. I've just written a PHP interface for some DB related bits at work and I could have made the code twice as efficient and half the size. I didn't because in it's current form it's easy for someone else to modify at a later date and the difference between a runtime of 50 microseconds and 25 microseconds doesn't really matter to anyone.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 17 Jan 2003, 14:48   #6
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Quote:
Originally posted by Gayle28uk
All jokes about 'job security' aside, legible code is almost always better. I've just written a PHP interface for some DB related bits at work and I could have made the code twice as efficient and half the size. I didn't because in it's current form it's easy for someone else to modify at a later date and the difference between a runtime of 50 microseconds and 25 microseconds doesn't really matter to anyone.
Yes it does... to my kind of applications. 1 frame per second more on YOUR machine is definately something to aim for, as it can have quite and impact on playability and thus a bigger audience.

If only I could get my profiler to work I'd look how I can speed my app up.
Structural Integrity is offline   Reply With Quote
Unread 17 Jan 2003, 14:56   #7
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Structural Integrity
Yes it does... to my kind of applications. 1 frame per second more on YOUR machine is definately something to aim for, as it can have quite and impact on playability and thus a bigger audience.

If only I could get my profiler to work I'd look how I can speed my app up.
I said almost always. I've written self modifying code to save execution cycles before now but if it's not necessary you don't do it. If you do you document it
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 17 Jan 2003, 19:22   #8
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Last time I checked Gayle, you were in support? Not development?

Quote:
'No comments in functions themselves, if the code needs it it's too complex for easy maintenance'
To be honest, thats just crap. I pity you if the day ever comes when someone calls you at 4 in the morning saying 'blah blah' has broken can you fix it. Its bad enough if its your own code, but even worse if its someone else's.

Lack of comments in code gets right on my tits.

Also, what is the case if the code is complex? There will always be instances (unless your only doing trivial things) where the code can get compilcated. Always remember that whatever you write, it will be 10 times more compilcated for someone else to alter.

As a result I tend to comment fairly heavily, most people wont like my notation mind as I use Hungarian notation, but heres an example snippet from a recently used method.

Code:
/////////////////////////////////////////////////////////////////////////
// Initialise And Connect To DB

// Open Databse Connection
SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnection"]);
objConnection.Open();
			
/////////////////////////////////////////////////////////////////////////
// Validate User Login
			
// Create Command Interface
SqlCommand cmdStoredProc = new SqlCommand("db_CheckLogin", objConnection);
cmdStoredProc.CommandType = CommandType.StoredProcedure;
// Fill The Parameters Collection Based Upon Stored Procedure.
SqlParameter workParam = null;
workParam = cmdStoredProc.Parameters.Add("@LoginName", SqlDbType.Char, 15);
workParam = cmdStoredProc.Parameters.Add("@Password", SqlDbType.Char, 15);
// Prepare Output Parameter
workParam = cmdStoredProc.Parameters.Add("@ReturnCode", SqlDbType.UniqueIdentifier, 16);
workParam.Direction = ParameterDirection.Output;
// Set Values For Our Procedure
cmdStoredProc.Parameters["@LoginName"].Value = ctrlUsername.Text;
cmdStoredProc.Parameters["@Password"].Value = ctrlPassword.Text;
// Exec Procedure
cmdStoredProc.ExecuteNonQuery();

/////////////////////////////////////////////////////////////////////////
// Next Thing .... etc etc
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 17 Jan 2003, 20:43   #9
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Raging.Retard
Last time I checked Gayle, you were in support? Not development?
I do work in support but it's by choice. My university course was systems analysis/programming oriented though, I will however admit to not having developed any commercial apps so my commenting tends to be enough for someone who knows what they're doing but not enough for a beginner.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 17 Jan 2003, 21:10   #10
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by Gayle28uk
I do work in support but it's by choice.
Appologies, it wasnt my intent to belittle your choice of employment, but to query the origin of your opinions.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 17 Jan 2003, 21:24   #11
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Raging.Retard
Appologies, it wasnt my intent to belittle your choice of employment, but to query the origin of your opinions.
No worries, looking around at my fellow supprot peeps 90% of them wouldn't know what gcc even stood for I simply meant to state that while I chose tech support over development I still know one end of a compiler from the other, I do admit my lack of commercial coding experience though.

[edit] Apparently I don't know what GCC stands for either but my point still stands [/edit]
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!

Last edited by Gayle29uk; 17 Jan 2003 at 22:44.
Gayle29uk is offline   Reply With Quote
Unread 17 Jan 2003, 22:52   #12
Petrucci
Guest
 
Posts: n/a
Gnu C Compiler ?

  Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 09:06.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018