- Side Effects are lies, promises one thing and does other hidden things unexpected changes to variable of its own class
- Avoid using output arguments
- Function should either do something or ans something, but not both
-
Returning error code and then handling the exception in function is not good idea when required immediate action
if(deleteFile() === "OK") { if(deleteReference() == "OK") if(deleteAfterMath() == "OK") } else { console.log("Failed to delete") } //Instead try { deleteFile() deleteReference() deleteAfterMath() } catch (exception) { console.log("Failed to delete") }
- If try exists in function, it should be very first word in the function and that there should be nothing after the catch/finally blocks
- Functions are verbs to the and classes are nouns