Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't get what's the point. What does it matter if a variable is private? This is not a prison, if you want a private variable, just don't use it.

Why go through all that hoopla?



It's sort of a matter of taste. I use this pattern in Lua of having public attributes visible in my objects, with private values stored as enclosing outer local variables. (They're referred to as "upvalues" in Lua. It's a handy bit of vocab.)

Public object attributes are iterable and otherwise manipulable by clients of the object. Upvalues are opaque to clients - you need the debugger to inspect the local stack frames. They're perfectly accessible to the closures acting as methods on your object though.

It really just comes down to your mental model of the object in question.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: