Recommendations for elegant or graceful code:
- Easy to read,
Indented in a consistent manner,
Meaningful variable and function names,
objects/functions well organized.
Comments where needed.
- Straightforward, no unnecessary complexity
- Complex vs. simple means finding the simplest solution and using it. If you find yourself writing alot of code for something, you may be making it more complicated than it should be.
- Good architecture.
No redundant/duplicate code,
Reuse of modules/files/functions as appropriate.
- Separation of application and presentation.
HTML not embedded in PHP, but stored in templates.
- Refers more to web applications (for example a cart or content management system) than sites, where there is significant logic. In that case, you want to allow the design team access to the HTML, without having them editing PHP files.
- Robust field validation,
graceful error handling
- Secure, appropriate reactions to malicious or accidental actions.
- Runs as intended
- Common configuration settings/constants sourced from a single point
- If you have a database that will be accessed from more than one place, the username, and password should be stored in a single place. That way, if they change, they only have to change in one place.
- Use of all available resources.
Includes using Linux commands or scripting where appropriate.
- PHP is primarily for web sites. If it has to run a file system command, such as a copy, it should be done as a Linux command, otherwise, you are reinventing the wheel. There may be times this won't work, due to permissions and configurations.
- Efficient logic
- Efficient logic covers issues such as if you have to iterate through an array more than once, all the operations are performed in a single loop, even if they are unrelated. That way, there is only one loop.
- Small footprint