• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualÁlvaro

Posted 17 April 2013 - 07:20 AM

// Used to check if x is equal to 0
if (x == 0)
{
x  =  5;        // give x the value of 5
}
else                 // if x is not equal to 0 then do this
{
x = 4;         // give x the value of 4
}


The only comment I want in that code is one explaining what x' means, and why it makes sense that up to that point in the code values like 0 or something else made sense, and after that point in the code 4 and 5 make sense. Separating x into two variables (one for whatever it represented up to that point in the code and one for whatever it represented after that point in the code) and giving them good names would result in code that is much more readable than that horrible thing you just posted.
int default_number_of_tax_allowances = (number_of_children == 0) ? 5 : 4;


### #1Álvaro

Posted 17 April 2013 - 07:19 AM

// Used to check if x is equal to 0
if (x == 0)
{
x  =  5;        // give x the value of 5
}
else                 // if x is not equal to 0 then do this
{
x = 4;         // give x the value of 4
}


The only comment I want in that code is one explaining what x' means, and why it makes sense that up to that point in the code values like 0 or something else made sense, and after that point in the code 4 and 5 make sense. Separating x into two variables (one for whatever it represented up to that point in the code and one for whatever it represented after that point in the code) and giving them good names would result in code that is much more readable than that horrible thing you just posted.
int default_number_of_tax_allowances = (number_of_children == 0) ? 4 : 5;


PARTNERS