of evil! KISS - KEEP IT SIMPLE AND STUPID equals understandable DO ONE THING ONLY – AND DO IT WELL keep the level of abstraction to a minimum ZERO ARGUMENTS – THE IDEAL pursue it, as best as you can (think about testing)
LIES! the function should do one thing EXTRACT ERROR HANDLING improve readability, don’t obscure logic RETURN ONLY ONCE – OR FAIL FAST keep the exit clear
later DON’T COMMENT OUT CODE we have VCS for this! NO CHANGE HISTORY HEADER see above (it wouldn’t be maintained anyway) NO REDUNDANT OR MANDATED COMMENTS example: why document an accessor?
FUNCTIONS ON TOP followed by called functions } VERTICAL DENSITY what belongs together should be together HORIZONTAL ALIGNMENT don’t align just for the looks
functions - do one thing SMALL keep away from the “god”-classes ORGANIZE FOR CHANGE – USE INTERFACES it’s most likely going to happen LoD - LAW OF DEMETER (LOOSE COUPLING) a given object should assume as little as possible about the structure or properties of anything else
them EXTRACT HANDLING BLOCKS (TRY/CATCH) don’t disturb the code flow DON’T RETURN NULL, DON’T PASS NULL avoid NPEs LoD - LAW OF DEMETER (LOOSE COUPLING) a given object should assume as little as possible about the structure or properties of anything else
them INDEPENDENT no test should depend on another test REPEATABLE in any environment, your laptop, the CI server… SELF-VALIDATING pass or fail - no manual action required TIMELY don’t write your tests too late, it only gets harder F.I.R.S.T
CODE METRICS track your discussions and descisions early problem recognition analyze your code with heuristics define your cycles keep a clean history educate your team