lua-users home
lua-l archive

Re: A matter of "style"...

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Mike Cuddy <mcuddy@fensende.com> wrote:
> Should I define the "member functions" inside the table declarations for
> the class...
> Or should I declare them outside of the declaration of the "Class" ...
I like the later for the reasons you mentioned. 
I also use a couple of other conventions to solve some name conflict 
problems
I've run across:
- instance variable names begin with an underscore and a lower case 
character. 
Example:
 Point = 
 {
 _x = 0,
 _y = 0,
 _z = 0,
 }
- method names begin with a lower case character and contain an underscore 
for 
 every argument the method accepts. 
Examples:
 function Point:x()
 return self._x
 end
 function Point:x_(x)
 self._x = x
 return self
 end
 function Point:x_y_z_(x, y, z)
 self._x = x
 self._y = y
 self._z = z
 return self
 end
This is to avoid name collisions between instance variables and methods of 
different types. In the example above there's an instance variable "_x", a 
getter method "x" and a setter method "x_" with no name collisions.
Steve

AltStyle によって変換されたページ (->オリジナル) /