Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write good and understandable code without any comments?

Tags:

comments

Can any one suggest what is the best way to write good code that is understandable without a single line of comments?

like image 1000
pang Avatar asked Apr 24 '09 01:04

pang


People also ask

Is comments required for the code?

It's possible to write code without comments, as long as you know when and where they're actually needed.

Do comments make code more readable?

Commenting involves placing Human Readable Descriptions inside of computer programs detailing what the Code is doing. Proper use of commenting can make code maintenance much easier, as well as helping make finding bugs faster. Further, commenting is very important when writing functions that other people will use.

Does clean code need comments?

Ideally, our code should be self-explanatory and we wouldn't even need any comments. However, sometimes it's not possible to express something purely using code.


2 Answers

I once had a professor when I was in college tell me that any good code should never need any comments.

Her approach was a combination of very precise logic split out into small functions with very descriptive method/property/variable names. The majority of what she presented was, in fact, extremely readable with no comments. I try to do the same with everything I write...

like image 175
Justin Niessner Avatar answered Sep 22 '22 04:09

Justin Niessner


Read Code Complete, 2nd Edition cover to cover. Perhaps twice.

To give some specifics:

  • Making code readable
  • Eliminating code repetition
  • Doing design/architecture before you write code
like image 16
Instance Hunter Avatar answered Sep 21 '22 04:09

Instance Hunter