News for hackers. Stuff that matters.
Re:Cleaning bad code by einhverfr on Tuesday August 21, 2012 @10:00AM (#4412713)
Most of this is really great advice. However I have run into horror stories that would shock you. For example:

1) Delete most of the comments 2) Stuff breaks. WTF? The code was processing its own comments!

Also I would add a third option here (the option we chose with LedgerSMB) which is:

"Localize the bad code, and replace with good code, a block at a time."

Some code can never be cleaned up effectively. In this case, you separate out, rewrite, and live with the fact that this will break some stuff while you get something that, on the whole, is more robust. Now in this approach the thing that is critical is you make as few changes to the legacy code base as you can. You also look for other layers at which you can implement things like new, needed security controls, or API's and you do everything you can to avoid putting new stuff through the legacy sections.

Re:Cleaning bad code by praptak on Tuesday August 21, 2012 @10:32AM (#4412842)
> 1) Delete most of the comments 2) Stuff breaks. WTF? The code was processing its own comments!

My campfire story: change method name, stuff breaks. Method names had been parsed in a wrapper object (Python's __getattr__ being abused) so that calling 'setFoo()' triggered a 'Foo_changed' event. In fact, the method names constituted a mini-language with its own grammar and semantic. Apparently someone had gotten high on reflection.

Re:Cleaning bad code by evilbit on Tuesday August 21, 2012 @12:07PM (#4413313)
Corollary: AOP is the enemy of refactoring.

You unwittingly changed one of the (seemingly unused/unnecessary) pointcuts and your aspects aren't firing anymore. While not impossible to track down, these problems are difficult to resolve.

Re:Cleaning bad code by ldh on Tuesday August 21, 2012 @04:16PM (#4414568)
This worries me every time I use AOP, but I mitigate that risk by writing integration tests which assert that the aspects are doing what they are intended to, and also to raise an alarm if somebody unknowningly breaks them.
Re:Cleaning bad code by praptak on Tuesday August 21, 2012 @03:02PM (#4414196)
I am not sure if this was AOP though maybe I'm committing the no true Scottsman fallacy here. Side note: decorators were not present in Python then, so there was no easy way to do the cutpoint thing in a visible way.