How We Cleaned Up Our Own Code
First We Set Goals
- We want our code to look fresher.
- We want our code to be more standard in appearance (indents, etc.).
- We are aware that our package and example code is something that our customers see and want to provide meaningful information and clearer guidance.
Next, We Defined the Process
- Use the new compiler warning system in the Studio to ensure code has no obsolete usage.
- Clean up indents and remove some of the easiest comments.
- In the Studio, select the entire file, cut, and paste it back to itself. This tricks the editor into applying proper casing to commands. Every little bit helps.
- Review the package and manually make changes. 99% of these changes will be removing comments.
Lastly, We Defined Some Basic "Rules for DataFlex Code"
As part of our code cleanup, we defined some rules that we wanted to apply to our code – this is the code you see in our samples and packages. While we are not necessarily recommending that you abide by these rules, we present them as guidelines you may wish to consider.
- Use spaces and not tabs for indentation.
- Indent is 4 spaces.
- When using multiple lines for a single command (using “;”), try to indent in groups of 4. Don't try to line up by code.
- Don't add comments with method, object, or class names to end blocks (e.g.,
End_Class,End_Object). - Avoid unneeded comment lines and don't add information to a comment block that is obvious by looking at the code.
- Keep file header comment blocks small or non-existent. This is code at the top of a file.
- Don't keep history logs at the top of a file or elsewhere (remove them). Source control provides the real history, and these never seem to stay up to date.
- Avoid comment break lines (e.g.,
//*************) unless it really serves a purpose. - Don't create comment blocks with a right-aligned border (e.g.,
// test //). - Remove old code that is commented out – use source control as your history.
- When in doubt, leave a comment in. We don't penalize people for writing comments!
- Don't worry about embedded comments lining up. Don't worry about spaces between code lining up. What is, is.
- We are not looking for perfection or complete standardization.
This has been an interesting process, and the more we did this, the more we became convinced this was a very good process for us to go through (and will probably be valuable to you as well). The code now appears a lot lighter (we removed many heavy comment blocks) and a lot newer (we removed many old dates). What gets left behind is good code with really good comments. We've done a pretty good job with our comments. We got rid of a lot of mistakes, such as End_Class blocks with the wrong class name and method names in comments above the wrong method (because the method was changed or was part of a copy/paste/edit).
We also moved some packages out of dfallent.pkg because they are obsolete. In some cases, you will need those packages – if so, just “use” them in your code. Alternatively, you can add all of these old classes back by including the OldDFAllent.pkg file immediately following the Use DFAllEnt.pkg.