Learn 50 coding laws that can help you become a better programmer. These laws cover various aspects of coding such as avoiding comments, naming variables and functions, writing clean code, and following best practices.

22m read timeFrom medium.com
Post cover image
Table of contents
Follow these laws or get fired.LAW 1: Avoid Comments At All CostLAW 2: Do Not Use Type Attributes As A Name For VariablesLAW 3: Class Names Should Be Nouns.LAW 4: Function Names Should Be VerbsLAW 5: Functions Should Specify The Parameter And Return TypeLAW 6: A function Must Perform One Functionality OnlyLAW 7: Functions Should Be At The Same Level Of AbstractionLAW 8: A Function and It’s Argument(s) Should Be Like Brothers And SistersLAW 9: Functions Should Be SmallLAW 10: Avoid Noise/Redundant WordsLAW 11: Do Not Be A Dirty ProgrammerLAW 12: Open Closed PrinciplesLAW 13: Liskov Substitution PrincipleLAW 14: Know When To Use A CommentLAW 15: When Is A Comment Bad?LAW 16: Keep Source Files ShortLAW 17: Know When To Use Blank LinesLAW 18: Keep Related Lines Of Code/Functions/Classes CloseLAW 19: Know When To Use White SpacesLAW 20: Obey Team RulesLAW 21: Avoid Magic NumbersLAW 22: Avoid Deep NestingLAW 23: Avoid Temporary VariablesLAW 24: Avoid Cryptic AbbreviationsLAW 25: Avoid Hardcoding PathsLAW 26: Always use Try-Catch-Finally StatementsLAW 27: Provide Context with ExceptionsLaw 28: Avoid Using Multiple Exception ClassLAW 29: A function must either mutate or return something, but not both.LAW 30: Not all function names should be verbsLAW 31: Classes should be smallLAW 32: Classes should have a small number of instance variablesLAW 33: Your classes should be cohesive.LAW 34: Use the with Statement for Resource ManagementLAW 35: Avoid Complex Ternary ExpressionsLAW 36: Use ‘is’ and ‘is not’ for Identity ComparisonLAW 37: Dependency Inversion PrincipleLAW 38: Avoid Using ‘assert’ for Data ValidationLAW 39: Avoid Hard-Coded NumbersLAW 40: Follow the DRY (Don’t Repeat Yourself) PrincipleLAW 41: Follow Established Code-Writing StandardsLAW 42: Law of DemeterLAW 43: Readability over concisenessLAW 44: Keep Imports CleanLAW 45: Do Not Return Null/NoneLAW 46: Separate Construction From Its UseLAW 47: Simple Design Contains All These RulesLAW 48: Avoid Nested Try-Except BlocksLAW 49: Use Concurrency Only When NeededLAW 50: Follow The 49 Rules
51 Comments

Sort: