lua-users home
lua-l archive

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


On Thu, Dec 30, 2010 at 9:20 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> Just why must x and y be private if you plan to provide read and
> write access to them?

Having had this moment with some Java[2] I was charged with sorting
out, I must agree. The classic answer is that a.x confuses
implementation with access, but _if_ a.x needs to invoke some code at
some later date, well then there's always the property pattern.[1]

A much bigger problem than classic privacy/implementation hiding is
not spelling a field name correctly, since this is not a runtime
error.

steve d.

[1] the table doesn't contain 'x', so __index will always fire, and
some code gets called; if we cannot find a field x try to call the
method get_x. Ditto for x/set_x.
[2] in any case with Java the IDEs are so good that you can find all
the references to a field and correct them very quickly. Technology
should trump ideology.