Привет. Решил узнать, существуют ли какие-либо приемы трассировки и ассертов, которые не портили бы читабельность кода.
Вот кусок кода, до использования:
...
HandlingOperationStatus status =
TransactionLogManager.GetHandlingStatus(TransactionsLog, this.Name);
//we don't need to handle already completed operation.
if (status == HandlingOperationStatus.Complete)
{
return;
}
//this code runs when handler was stop before it has time to
//rollback.
else if (status == HandlingOperationStatus.Running)
{
Rollback(TransactionsLog);
}
...
а вот после:
Debug.Assert(tfsEvent != null, "tfsEvent == null");
Trace.WriteLine(string.Format("{0} handler {1} start handling {2} msg",
Thread.CurrentThread.ManagedThreadId,
this.Name, tfsEvent.MessageGuid));
HandlingOperationStatus status =
TransactionLogManager.GetHandlingStatus(TransactionsLog, this.Name);
//we don't need to handle already completed operation.
if (status == HandlingOperationStatus.Complete)
{
Trace.WriteLine(string.Format("{0} tfs event {1} was already " +
"handled by {2} handler",
Thread.CurrentThread.ManagedThreadId,
tfsEvent.MessageGuid, this.Name));
return;
}
//this code runs when handler was stop before it has time to
//rollback.
else if (status == HandlingOperationStatus.Running)
{
Trace.WriteLine(string.Format("{0} Rollback due to Running " +
"status of {1}",
Thread.CurrentThread.ManagedThreadId,
tfsEvent.MessageGuid));
Rollback(TransactionsLog);
}
Читабельность в разы падает =(