Original Post
There is a such thing as over commenting. !? I know this topic was up before but ugg when I see every line commented it''s annoying. x+=1 // yup thats incrementing X! well im just ventin''
// Below I explain my intentions.
// The idea is that sometimes I say things that others
// don''t understand.
I''m going to start commenting what I say around here, because
obviously there are many who don''t know what I''m talking about
When I speak.
// End of statement.
public int maxCon2(int[] x){
int maxSoFar=0; //O(1) constant time
for(int i = 0; i < x.length; i++){ //O(n)
int sum = 0;
for(int k = i; k < x.length;k++){ //O(n)
sum+=x[k];
if(sum>maxSoFar)
maxSoFar=sum;
}
}
} //Function is O(n^2)... or something like that...
int function( int x )
{ // Begin function
// Declarations
char choice;
// Prompt user
cout << "Enter choice:";
cin >> choice; // Get letter from keyboard
// Enter for loop
for( int y = 0; y <= x; y++ )
{ // Begin for
// Display numbers
cout << y;
} // End for
// See what choice the user picked
if( choice == ''A'' )
{ // Begin if
cout << "You chose the first letter in the alphabet";
} // End if
} // End function
quote:
Original post by circlesoft
My programming teacher makes me comment every single little thing, from curly braces to declarations. It is really quite annoying...int function( int x )
{ // Begin function
// Declarations
char choice;
// Prompt user
cout << "Enter choice:";
cin >> choice; // Get letter from keyboard
// Enter for loop
for( int y = 0; y <= x; y++ )
{ // Begin for
// Display numbers
cout << y;
} // End for
// See what choice the user picked
if( choice == ''A'' )
{ // Begin if
cout << "You chose the first letter in the alphabet";
} // End if
} // End function
T complexFunc<typename T>(int epsilon, float gamma, T theta)
{
int epSquared = epsilon*epsilon; //epSquared = epsilon squared
float gamma2 = gamma;
T pnz = qwerty(theta);
for(int i=0; i < epSquared; i+=2) //go up from 0 to epsilon only evens
{
gamma2 -= i ? epsilon/i : theta != pnz ? qwerty(pnz) : theta;
}
return static_cast<T>(gamma2); //return gamma2 casted to T
}
int //This is going to be one of those functions that returns an integer value.
function //I''m calling this function "function". Not a very descriptive name; perhaps I''ll fix that in the future.
( // Here is the beginning of the parameter list of the function that I previously named "function".
int // "Integer" is the first parameter type
age // I''m calling this parameter "age" because the variable used in the function is going to represent the age of someone (or something!)
) // This closing parenthesis signifies the end of the parameter list of the function "function"
{ // This is the beginning of the function, right here!
while // This is a while loop, which iterates while (get it?) a certain condition is true.
( // The condition needs to be wrapped in parentheses! Here''s the opening one.
age // We are using the variable "age" as the parameter to the while loop.
) // This closing parenthesis signifies the end of the condition in the while loop
{ // Here''s where the block that iterates while age is not zero begins.
age // We''re referring to the variable "age" here, just so you know.
= // This is assignment, NOT a test for equality!
1 // Set the integer variable age to the number "one".
} // This brace signifies the end of the while loop.
} // This brace signifies the end of the function.
/* FIXME: This function will result in an infinite loop, unless
the argument is zero! Tell the users of this function to only
give it zero as its parameter. */
quote:LOL
Original post by bishop_pass
// Below I explain my intentions.
// The idea is that sometimes I say things that others
// don''t understand.
I''m going to start commenting what I say around here, because
obviously there are many who don''t know what I''m talking about
When I speak.
// End of statement.___________________________________
"The outside of a horse is good for the inside of a man" - Winston Churchill
quote:
Original post by circlesoftint function( int x )
{ // Begin function
// Declarations
char choice;
// Prompt user
cout << "Enter choice:";
cin >> choice; // Get letter from keyboard
// Enter for loop
for( int y = 0; y <= x; y++ )
{ // Begin for
// Display numbers
cout << y;
} // End for
// See what choice the user picked
if( choice == 'A' )
{ // Begin if
cout << "You chose the first letter in the alphabet";
} // End if
} // End function
int function( int x ) {
char choice;
// Prompt user
cout << "Enter choice:";
cin >> choice;
// iterate, printing the index of each iteration (?!)
for( int y = 0; y <= x; y++ ) {
cout << y;
}
// Print the choice the user picked
if( choice == 'A' ) {
cout << "You chose the first letter in the alphabet";
}
} quote:
Original post by Russell
No, you need 7 comments per line of code. Maybe you could add in what kind of ''int'' you are working with, and what other kinds of ''int'' you might be working with on other architectures. Example:
int/*this is going to be an integer function. an ''int'' in this case is a 32-bit value on my machine at home, but at work we have itaniums, so an ''int'' at work is a 64-bit value. i also have this old DOS machine in my closet, and if i ran my program .....
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more