Clean Code
Moderator: General Moderators
- Saethyr
- Forum Contributor
- Posts: 182
- Joined: Thu Sep 25, 2003 9:21 am
- Location: Wichita, Kansas USA
- Contact:
Clean Code
As a PHP newbie I have a question. Does cleaner code come with time or are some just inclined to write messy code. Now I realize from coding in C that everyones definition of clean and dirty code varies, but, is there a "RIGHT" way and a wrong way if both pieces of code execute in the same way and in the same amount of time?
If what you write is barly understandable to you, then you must expect that it will be that way for others. I write clean code so that i can debug better, and so that if i want to share the code other people can understand and debug it also. other than that i dont think that clean VS. messy really makes a difference. Just as so it gets to job done.
Clean Code is defined by having a feature of readability. Is the code easy to ready by the general programming community. There are different standards, of course. However, clean code is readable by most people.
This means naming of code, structure, etc, is all important. Indenting is important as well, of course, not indenting too much is also important.
A good book that covers writing clean code is "Code Complete", from Microsoft Press (forget the author). It's a good book, and covers the topic of the how's and why's of writing clean, readable code.
Note that readable code and comments are two different things. You will find people that encourage comments everywhere, and people like me who find that excessive comments actually make clean code less readable.
Clean code is just like anything other type of writing. Literature that has large paragraphs is generally more difficult to read than text that is cut into many paragraphs. Code is generally the same way. If you have large blocks of thick code, it will usually be more difficult to read.
Clean code is pretty easy to determine though. PEAR (pear.php.net) presents an overall view of generally clean code. For certain, some code is less clean, and some code is exceptional, but it is generally clean.
This means naming of code, structure, etc, is all important. Indenting is important as well, of course, not indenting too much is also important.
A good book that covers writing clean code is "Code Complete", from Microsoft Press (forget the author). It's a good book, and covers the topic of the how's and why's of writing clean, readable code.
Note that readable code and comments are two different things. You will find people that encourage comments everywhere, and people like me who find that excessive comments actually make clean code less readable.
Clean code is just like anything other type of writing. Literature that has large paragraphs is generally more difficult to read than text that is cut into many paragraphs. Code is generally the same way. If you have large blocks of thick code, it will usually be more difficult to read.
Clean code is pretty easy to determine though. PEAR (pear.php.net) presents an overall view of generally clean code. For certain, some code is less clean, and some code is exceptional, but it is generally clean.