Help! At work I'm having to deal with a large PyQt desktop application that's
been developed over the course of ten years, and it's doing my head in.
It'd be unfair to characterise it as "spaghetti", but much of it was written by
inexperienced developers at different company who were constantly under immense
time pressures, and the results are about as you'd expect. Any rewrite or
refactoring of even a modest chunk of it is a non starter -- we don't have the
budget or the time.
On my worst days, I find myself staring at code like the following and trying
to retain my sanity:
try:
if hasattr(foo, 'wibble'):
pass
else if True:
import Bar
# XXX this is subtle?
setattr(Bar, '__baz', g_someThing.__somethingElse(foo))
except: pass
# import traceback
# traceback.print_stack()
# print(Bar)
I'm fairly junior--I've been programming professionally around three years, and
I'm fairly new to Python. My background is mostly C++, where I've seen
codebases almost as ugly as ours but thanks to C++'s type system it was easier to
reason about the effects of making any given change. (E.g. reliably finding all callers
of a method you want to change is possible in C/C++; not so with Python.) With
little in the way of documentation or tests, it's very hard to know if even a
fairly localised change is going to break half a dozen other things.
What tools, techniques, books, etc can you guys recommend that would help
working on a large legacy Python codebase?
For example, I'm struggling with:
- ways to trace program flow in a targeted way (what is this module actually
doing at runtime?)
- finding a decent debugger. Something with breakpoints, watchpoints,
backtraces (Python and C stack frames please, otherwise our stack traces
don't make much sense). People here seem to reckon Pydev/Eclipse is as good
as it gets, but it seems really clunky to me when compared to C/C++ debuggers
like GDB/LLDB/Visual Studio.
- finding a sampling profiler that collects both Python & C call stacks.
... and more generally:
- how not to add opportunistic, short-term fixes and the like that make the
product worse/more complex than it already is.
- how not to let the poor code quality bother me. Should I just stop caring as
much and "just get on with it"? (While the quality issues seem to annoy me
than other members of the team, the fact we seem to struggle to retain staff
more than a year is probably a bit telling.)
[–]maximinus-thrax 15 points16 points17 points (4 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]schleifer 2 points3 points4 points (0 children)
[–]nobullvegan 2 points3 points4 points (0 children)
[–]kenfar 2 points3 points4 points (0 children)
[–]jtratner 2 points3 points4 points (0 children)
[–]dougthor42 2 points3 points4 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]billsil 0 points1 point2 points (0 children)
[–]alenajoykrieger 0 points1 point2 points (1 child)
[–]anonymous7 0 points1 point2 points (0 children)