lua-users home
lua-l archive

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


On Thursday 30 December 2010 07:30:31 Axel Kittenberger wrote:
> > print('table isvirgin ',table.maxn(tab)==#tab)
> 
> And again another # pitfall. This might or might not return true for
> tables with holes!
> 
> I wonder how many more bugs will be out there due to people expecting
> # to be in this or that way, other than the random indix when called
> upon a table with hole.
> 
> Personally I too consider for a language that presents itself as easy
> and the code looking tidy, the # notion an unfortunate stumbling block
> I'm sure many more people will get their nose bloody.

Which brings us full circle to when somebody asked me why one should have 
obj.setx("whatever") instead of just setting x. obj.setx("whatever") could see 
whether obj["x"] exists, and if not increment obj["numberOfElements"] so that 
obj["numberOfElements"] represents the true number of elements. But the minute 
a hurried and uninformed maintenance programmer sets an element directly 
(obj.x="whatever"), all bets are off and the program breaks far away from the 
maintenance programmer's mistake.

Hey, I'm not saying that level of encapsulation is always the right way to go, 
but it does have its purposes.

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt