DEV Community

zeeshan mehdi
zeeshan mehdi

Posted on

Rules that i follow for clean Code

  • Avoid Switch Statements instead use polymorphysm so for example you have a class Shape and there are few children like triangle, circle so in future if you want to add new shape like rectangle you can just inherit it from Shape and you do not have to change anything in the base class.
  • Don't Pass more than three arguments instead pass an object
  • Don't pass a boolean to a function
  • Use functions inside if statements
  • Clearly name your folders, modules, functions, classes, object and variables in a way that easily understandable what they do.
  • Function has to do just one thing
  • Function should not have more than 2 indents, ideally no ident.
  • No side Effects ( for example if you open a file ,you should not leave it open but close it after you are done with it.)
  • Don't write any code inside try block instead just a function call.
  • Don't duplicate code convert them to reusable methods.

I will write part 2 to this post.

Top comments (0)