← Back to team overview

libbls-dev-list team mailing list archive

Re: Proposed API change for bless_buffer_can_undo

 

On Sat, May 16, 2009 at 08:43:56PM +0300, Michael Iatrou wrote:
> When the date was Saturday 16 May 2009, Alexandros Frantzis wrote:
> 
> > In the current (0.2.0) API we have the 'bless_buffer_can_undo' and
> > 'bless_buffer_can_redo' functions to get whether there are any actions
> > to undo/redo.
> >
> > I think it would be better to change this API to replace the
> > aforementioned functions with something like
> > 'bless_buffer_get_{undo,redo}_count' which will return the number of
> > actions that can currently be
> > undone/redone. It has the same functions signature as before but with
> > more capabilities.
> 
> It is so, indeed. 
> 
> On the other hand, providing such capability may lead to misuse. For 
> example, undo bookkeeping from user (which is implied by the new API) on a 
> multithreaded environment is error prone. 

All this is done so that the user doesn't have to maintain undo information
manually. Actually, they can't do that accurately without knowing the
internal state so we must do it for them.

As libbls is not thread-safe the user would have to be careful anyway
when using libbls in a multi-threaded environment.

> 
> Since the current API implementation is cheap in performance overhead, I 
> don't see the potential gain of such a change. Do you have a specific use 
> case in mind?

The overhead of the new function is the same as the overhead of the current one.
We gain an additional capability without complicating the API, allowing
us to offer more features in the future (eg see use case below).

Also it would be useful to know the number of actions beforehand for
memory management purposes in many cases (like in the code snippet in my
first mail).

> > It may be useful to later add a bless_buffer_get_undo_info() api
> > which will return information about the actions
> 
> This is an independent addition, so I am much less reluctant; but still a 
> use case would help.
> 

The use case I had in mind for all of these changes were the ability to
inspect the undo/redo actions and report information about them to the
user eg like vim does "2 fewer lines; before #94 13 seconds ago".
Another use is to present the history and let the user revert to a
specific state or produce a binary diff-like output.

Anyway, I mentioned bless_buffer_get_undo_info() as something to
have in mind, not a priority.

-- 
Alexandros



References