I'm debugging a huge piece of legacy code at the moment (the better part of 100,000 lines from what I can tell, some of it included HTML chunks and SQL statements), and it's using one of the earliest, ugliest and nastiest antipatterns I've ever seen: Pass-by-global.
As usual, the global variables being used aren't documented, nor is their behavior. My best bet at the moment is to bring up two ssh sessions and examine a "working" version, comparing it to a new rewritten version that should help isolate what the behavior really is...
Now, a Python bigot would be able to point to this big mess of code and utter: "See! Friends don't let Friends program in Perl!" Realistically speaking, a big pile of messy code is a big pile of messy code in any language, regardless of the idioms used. Java, for example, may be designed to limit or even prohibit the use of global variables. However, that does not prevent pathological anti-patterns from being used -- it just forces new ones to be created. :-) (Python is incapable of preventing this pass-by-global idiom; it just deprecates it differently...)
And feel your pain! We fixed it by systematically removing each function to a separate file, turning on C<use strict;>, and then running
$ perl -c program 2>&1 | head
and removing an error at a time. Fortunately most changes we made removed several thousand error lines at a time. Change "head" to "wc -l" for real fun. After perl -c works clean, take out the -c. After that runs clean, move another function into its own file.
Re:Been there, done that
ziggy on 2002-01-16T21:28:40
I did a brief guesstimation on the size of this system. It's looking like it's roughly 100,000 lines of Perl code. (It's quite difficult to tell actually; there are about 200 non-core, non-CPAN locally writen modules involved here with only the most incestuous of relationships found...) The reason why it's difficult tell the overall size is because (1) the modules are split into two different directory structures, and (2) one of them appears to be isolated to this product (with ~60,000 lines), and the other is code reused across a family of products (consisting of ~227,000 lines). Furthermore, that includes things that should be counted (such as whitespace, comment lines, and HEREDOCs for SQL, HTML, etc.)What's really nice is that the code exhibits a couple of similar but subtly different anti-patterns:
The really tricky part is that it probably won't get rewritten. I'm dealing with some bits of the backend, but much of the code in dire need of remediation is shared between a backend and a frontend (which is a completely different effort altogether...)
- pass-by-global
(all variables in %main::)- export-to-everywhere
(many modules importing the same symbols from a common module, so they're effectively global, but at the same time not really global)
Re:Oh ghod... I feel your pain
pdcawley on 2002-01-16T21:51:02
Oh yes, forgot to say. When I finally got a travesty of the functionality working under mod_perl, it ran in about 100th of the time.