As a consultant, I often have to deal with bad habit concerning variables declarations inside PowerBuilder Application I have to maintain.
Here, I will not enter in the endless discussion about naming convention as if my client use one, I will have to stuck on it anyway regardless of its quality;
but I will focus on some kind of common sense rules.
DON'T DISSEMINATE LOCAL VARIABLES DECLARATIONS ANYWHERE IN YOUR CODE !
Some developers, often with a 2GL background like C,C++ or even Java, prefer to place the local variables declarations to the nearest corresponding code, and if possible only when it is needed, so often inside IF block, claiming it optimize both memory consumption and code readability.
The problem is that with PowerBuilder it is useless as all the variables will be handled by the compiler at the beginning and instantiated in any case.
The code readability reason is also discutable because it is always easier to look at the top of the code to find a particular variable declaration than looking for it inside the code furthermore than PowerBuilder do not have a "Go to Definition" functionality.
DON'T STUCK VARIABLES DECLARATIONS ON THE SAME LINE
Again a 2GL background bad habit where variables of the same data type are stuck on very long line separated by commas.
Not only it does make very difficult to find specific variables declaration but it also make refactoring/clean up of the code a nightmare.
DON'T ADD NEW VARIABLE DECLARATION HAPHAZARDLY
Very often, people add the variables they need at the end of the last variable declaration as it comes.
At the end, the variables declarations block is a total mess.
DO PLACE VARIABLES DECLARATIONS AT THE TOP OF THE SCRIPT
That way no need to search in other place than the top of the script for a particular variable.
DO DECLARE ONLY ONE VARIABLE BY LINE
This will make code refactoring and cleanup easier.
Will also facilitate third party tools source code parsing and avoid related issues.
DO SORT & GROUP VARIABLES DEFINITIONS LOGICALLY
A good habit will be, at least to :
or when possible or wanted:
CONCLUSION
Following these few common senses rules will greatly enhance your productivity while maintaining existing or developing new solutions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 13 | |
| 12 | |
| 12 | |
| 11 | |
| 10 | |
| 10 | |
| 9 | |
| 9 |