Closed orip closed 12 years ago
My main gripe is that calling close() isn't necessary. Another way to write the code above is:
boolean success = false;
Editor e = cache.edit(key);
try {
// edit values
e.commit();
success = true;
} finally {
if (!success) e.abort();
}
I can't claim that this is any better. But I do think it's more intention-revealing.
@swankjesse What bothers me with the current interface is that I have to maintain the success state in every scenario that I edit keys. If it's inherent to editing, I lean towards the Editor having explicit support for this state.
An alternative would be just keeping and exposing the state instead of creating the .close()
logic:
...
} finally {
if (!e.wasCommitted())
e.abort();
}
but making the Editor closeable feels elegant to me, and I think maps to Java's idioms better.
Do we all hate this name?
e.abortUnlessCommitted() ?
I'm coming around to close(), but I still dislike the fact that it makes a naked commit() look leaky.
I like it. Close doesn't exactly convey what's happening behind the scenes.
That's a really good name.
Merged to dev
.
In order to always match an edit to a
commit()
orabort()
, even in case of exceptions, it would be nice to be able to do this:I can submit a pull request if preferred.