Change default access level of class members

Link to this posting

Postby Ursego » 19 Feb 2013, 22:22

Don't leave the class members PUBLIC as they are created by default - change the access level to reflect their real practical use.

PowerBuilder's instance variables and functions are public by default. Methods access can be changed to private or protected using the dropdown in the declaration section, and instance vars must be "privatized" by adding the private or protected keyword before each var, or the same keyword with a semicolon before a group of vars. Pay attention - if no scope identifier is mentioned explicitly then the vars are public - in contrast to C# (where "no scope identifier" means "private")! IMHO, it was a bad solution of PB authors (everything should be private by default and be changed only if a need arise!), but that's what we have... So, when you are creating a new instance variable or a function, and your brain is busy thinking about the functionality being developed, don't forget to change the access level to what it should be!

Why is this advice important? We can see many PB applications with all functions public, and nothing bad is happening... I would say, it is not too important in the development stage, but when the maintenance time comes... For example, I have to add and even change functionality of an existing object. If the stuff I am touching is private then I know for sure that my changes will not cause straightforward damage in other (sometimes unexpected) parts of the application - for example, I can change the number of parameters or even the name of a private function without having a chance to do any harm to other objects. But if the function is declared as public then I need to perform the Global Application Search (which is extremely slow in PowerBuilder, especially in serious apps) to make sure the function is not called outside the object (and if it is called then, may be, to change the technical solution).

There are more reasons to keep the access in the CORRECT level - please read Private and public affairs in functions
User avatar
Site Admin
Posts: 140
Joined: 19 Feb 2013, 20:33

IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:

Traffic Counter

free counters

eXTReMe Tracker