lua-users home
lua-l archive

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




On Monday, October 27, 2014, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2014-10-27 8:38 GMT+02:00 Hao Wu <wuhao.wise@gmail.com>:

> Curious why/when you need such a function? Would the retrieval become
> dependent on how the accessor is implemented, which would lead to that
> the client code will rely on implementation details of API provider?

It's mainly for debugging, but you can't have anything in the debug library
(in fact, in any standard library) if it is not in the API.

But I can think of a perfectly genuine non-debugging application too.

A database may be implemented as a table, where each time new
information is added, the old database is the __index of a new table
containing the items that have just been added/updated and some
fields identifying the update.

When you retrieve an item, you would like to know its provenance.
The "which" function directs you immediately to the source, or
maybe to "SECRET".

It does not rely on implementation details, only on the chronological
ordering of updates.


Fair enough. If I understand correctly, in such an application, 'which' is equivalent to whether the value comes from the application cache or the actual data source. IMHO, you can have a different API, say, is_data_expired. I still feel the same way that asking which is equivalent to the object type in OO world, which has valid usage but disencouraged.