OO versus nested_scopes in Twisted code (OO wins (not to spoil the suspense or anything))
Written by
on
in
Snaking.
So, I've been figuratively staving in my skull with tracking down the weird hanging cases that have been showing up in the ping scanning mechanism. For the most part, I've been storing the state in either explicitly passed arguments, or using nested scopes.
Having reached a point where the whole darn thing was just a mass of spaghetti this evening I realised that the problem is the way I've been writing the code. The explicit argument passing and nested scopes are fine when you're breaking up tiny functions, but they really aren't appropriate for anything non-trivial. For that, setting up utility objects to track the execution state is more appropriate.
To test that theory, converted the group-ping runners to use a helper object. Cut at least 40 lines from the implementation, eliminates the hangs entirely (because it's much easier to track down all the possible exit conditions), and is much easier to follow. TwistedSNMP uses a helper object for its table downloading, but somehow I'd forgotten why I did that when I sat down to work on the ping scanner.
Pingbacks
Pingbacks are closed.
Comments
Comments are closed.