#12: finnish() is superflouse.
--------------------------+-------------------------------------------------
Reporter: anonymous | Owner: emil
Type: bug report | Status: new
Priority: major | Milestone: neo-1.0
Component: neo-core api | Resolution:
Keywords: |
--------------------------+-------------------------------------------------
Comment (by emil):
I disagree. I think the try-finally-finish idiom is actually cleaner and
requires less code in most cases. For example, let's say in your example
that we'd have to specifically deal with more than one exception:
{{{
Transaction tx = Transaction.begin();
try
{
// Actual logic
tx.success();
}
catch( FirstException e )
{
// handle FirstExceptions in one way
tx.failure();
}
catch ( SecondException e )
{
// handle SecondExceptions in another way
tx.failure();
}
catch ( Throwable t )
{
// required, or we'll leave the transaction hanging
tx.failure();
}
}}}
What I dislike about that code is that we'll have to remember to invoke
{{{tx.failure()}}} in every catch-block. We also have to catch a Throwable
and mark it as failed, in order to not leave any transactions hanging if
we get runtime exceptions or errors.
Whereas that code with the existing API would look like:
{{{
Transaction tx = Transaction.begin();
try
{
// Actual logic
tx.success();
}
catch( FirstException e )
{
// handle FirstExceptions in one way
}
catch ( SecondException e )
{
// handle SecondExceptions in another way
}
finally
{
tx.finish();
}
}}}
IMHO, that code is less error-prone.
I think this is a pedagogical problem. We're poor at describing our
transaction philosophy. I think the key getaway is that a transaction is
failed by default, which means that if nothing happens to it (ie
{{{success()}}} is invoked) then it will be rolled back in the finally
block. This means that you only have to invoke {{{success()}}} once --
after the last statement in the transactional block has successfully been
executed.
WDYT?
--
Ticket URL: <https://trac.neo4j.org/ticket/12#comment:1>
neo4j.org <http://trac.neo4j.org/>
The Neo4J.org Issue Tracker_______________________________________________
Neo mailing list
[email protected]
http://lists.neo4j.org/mailman/listinfo/user