Example: A program to withdraw money from a Bank Account.
getBalance() // Does One Thing
if(getBalance > withdrawAmount) {
subMoney() // Does One Thing
} else
{
Print ("Insufficient Funds");
}
Other thing, I would like to point is that if you are making the code of your function visible, then it should be properly documented and readable. The compilers do a really great job of Optimizing the code, so there is no need to make the code look smart and have no one understand it. The only place I would put real smart code is when I am coding in assembly. In that situation, there should be really good documentation explaining the reason of your smartness.
Example:
A = 4
B = A X 2
[Smart Code: Right Shift A, but it's not always obvious that you are trying to multiply by 2 here, unless you have an explicit comment]
Example: A program to withdraw money from a Bank Account.
getBalance() // Does One Thing
if(getBalance > withdrawAmount) {
} else{
Print ("Insufficient Funds");
}
Other thing, I would like to point is that if you are making the code of your function visible, then it should be properly documented and readable. The compilers do a really great job of Optimizing the code, so there is no need to make the code look smart and have no one understand it. The only place I would put real smart code is when I am coding in assembly. In that situation, there should be really good documentation explaining the reason of your smartness.
Example:
A = 4
B = A X 2
[Smart Code: Right Shift A, but it's not always obvious that you are trying to multiply by 2 here, unless you have an explicit comment]