Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you write code that is easily read by other people who have had no hand in writing any part of it?

Tags:

readability

How do you write code that is easily read by other people and who have had no hand in writing any part of it?

like image 971
Codeslayer Avatar asked Sep 02 '08 12:09

Codeslayer


People also ask

Why is it easier to write code than read it?

The first reason code is harder to read than to write has to do with the sheer amount of data you need to keep in your head in order to read code. When you write code, you only need to remember the variables, algorithms, data, etc. relevant to the feature your are currently writing.


1 Answers

The best way to ensure that others can read your code is to make sure that it is clear and concise. Namely,

  • Use self documenting names for variables, functions, and classes.
  • Comment complex algorithms so that the reader doesn't have to spend to long figuring out what it does.
  • Ensure that tabbing and line breaks are constant throughout the code.

Beyond that you start to get in to the areas that might be a bit subjective, most people should agree on these items.

like image 50
rjzii Avatar answered Sep 21 '22 17:09

rjzii