by Klaus Graefensteiner
28. March 2010 05:49
Introduction
I recently came across a nice collection of coding standards that the developers at Gallery2.org are using. I especially liked the summary of settings for Eclipse PDT. I applied them to my Eclipse PDT development environment, took some screenshots and put this article together for my personal reference:
Eclipse PDT editor settings
Here is the list of common editor settings that promote readable source code:
Note: The following screenshots and settings apply to Eclipse Galileo (Build id: 20090920-1017).
General text editor settings
Go to Window/Preferences/General/Editors/Text Editors and verify the following settings:
- Displayed tab width = 2
- Insert spaces for tabs should be checked
- Show print margin should be checked
- Print margin column = 100
Figure 1: General Text Editor settings
PHP style format settings
Go to Window/Preferences/PHP/Code Style/Formatter and verify the following settings:
- Tab policy = Spaces
- Indentation Size = 2
Figure 2: PHP Code Style Formatter settings
Source control integration settings
Go to Window/Preferences/Team/Ignored Resources and make sure that ".cache", ".project", ".buildpath" and ".settings" are ignored.
Figure 3: Files excluded from source control
File Save settings
Go to Window/Preferences/PHP/Editor/Save Actions and verify that:
- Remove trailing whitespace should be checked
- Choose All lines is selected
Figure 4: Clean-up actions when saving a file
Ausblick
Besides these editor settings there is another very powerful feature that makes it easy to follow coding standards without having to think about it. And this features is called Code Templates, which are similar to Microsoft Visual Studio code snippets. Here is a list of PHP templates that are predefined in PDT. You can modify these to meet your coding standard and you can create additional ones.
Go to Window/Preferences/PHP/Templates and you see a complete list of them:
Figure 5: Code templates help also with coding standards without the need to remember all the details