Albert D. Kallal
Registered User.
- Local time
- Today, 04:31
- Joined
- Jun 11, 2009
- Messages
- 29
But any var declared as public in that class? You get intel-sense anyway - hard to make a case for then writing out a getter/setter, right?I would argue that if you are lazy (and have MZTools) then creating accessors (let, get, set) for all class variables save a lot of coding time. With MZTools it takes a second to create the accessors from a class variable, but now coding is much faster especially with larger classes. I do not have to remember variable names, scroll up to the top to see what I called a variable, or type a variable. I simply type "Me." and intellisense takes over. Further there is a good chance that the accessor needs more code then simply setting or returning the value. There may be some checks in the accessor. So I might as well start with the stub to begin with.
However, for some reason there is a shortfall in vba that defeats good use of accessors. Maybe someone knows why that is. Unlike in .Net private accessors cannot be called inside the class as would be expected
If you type "Me." they do not show in intellisense
nor can you call them by Me.somePrivateProperty
This kind of defeats the whole purpose. You have to call it without Me.
The other thing that is annoying is In VBA, you cannot have a property with a private Let and a public Get directly. VBA's property accessors (Property Get, Property Let, and Property Set) must all be declared with the same visibility level—either all Public, all Private, or all Friend.
There are SOME use cases for Get/Set, but 99% of the time, if you just setting a var value? Make it public - you don't need the get/sets.....
and in regards to priviate (non public) vars in VBA class? Yes, 100% agree that me. should intel-sense those private members when writing code inside of the class.
Edit:
But, be it .net, or VBA?
Public vars do play nice with intel-sense, and that includes writing code inside, or outside of the class. And it also a nice "code smell", since then I can with ease determine which public members have code, and those that don't..........
It's a simple point here: I don't see much of any need nor advantages of building a geter/setter if you just setitng a value - make that var public, and you have intel-sense, and you have less code, and I can't really see any advantage in such cases to build that getter/setter.
Now, of course if you need other code, then of course build that getter/setter - it just "oh so often" people blind write out get/set code when no such code is required.....
R
Albert
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
		
	
	
	
		
			
		
		
	
								
							
							 
	 
 
		 
 
		