28

Robert C. Martin offers in the fist chapter of his book 'Clean Code' several definitions of 'clean code' from differen well known software experts. How do you define clean code?

4

8 回答 8

48
  • Easy to understand.
  • Easy to modify.
  • Easy to test.
  • Works correctly (Kent Beck's suggestion - very right).

These are the things that are important to me.

于 2009-06-05T07:03:30.393 回答
19

Code I'm not afraid to modify.

于 2009-06-05T07:02:36.793 回答
14

Code that doesn't require any comments to be easily understood.

于 2009-06-05T07:04:10.627 回答
3

Code which reads as close to a human language as possible. I mean it on all the levels: from syntax used, naming convention and alignment all the way to algorithms used, quality of comments and complexity of distribution of code between modules.

Simplest example for naming convention:

if (filename.contains("blah"))

versus

if (S_OK == strFN.find(0, "blah"))

Part of it depends on the environment/APIs used, but most of it is of course the responsibility of the developer

于 2009-06-05T07:18:23.907 回答
2

Point-free Haskell code. (Not really, though.)

于 2009-06-05T07:06:51.043 回答
1

Code in which the different modules or classes have clearly defined contracts, is a good start.

于 2009-06-05T07:01:42.097 回答
1

Code which doesn't break in multiple places when you make a single, seemingly insignificant change. It is also easy to follow the control path of the program.

于 2009-06-05T07:03:59.270 回答
1

Reusable code is also important. So not only important is the quality of the code, but where do you put. Example, business logic into a Controller is a useless code

于 2014-07-27T15:35:24.250 回答