I think there have been several good points raised here, which I'll try to highlight, and I have a bit of my own to add. YMMV.
First off: "one thought" per function. Time spent organizing your code into structure, data, and actions is always time well spent, especially in a long-running project that will evolve and morph. When I start making stupid coding mistakes at 11 pm, I go home and sleep. Then I start in the next morning on a structural re-write.
Second: data-driven programming. I totally agree with
tye that rolling up constraints and actions into data structures is a really good thing to do. Think in terms of the high-level activity you're trying to accomplish:
- recognize a pattern from this set, grab the pertinent data, and perform a corresponding action from another set
- perform a sequence of actions based on a sequence of tokens (little languages)
- parse a pattern and perform actions based on the state of the system (state machines)
- etc., etc., etc.
Finally: parameter globalization. One of the big bugaboos people run into while attempting to chop modules down to size is that they have been taught not to use global variables. Function parameter lists that are longer than the code are a Bad Idea. :) In web coding, especially with the better templating systems, persistent state variables can really simplify your code. In non-web code as well, global system objects and class variables can really help clarify what's going on.
In all of this, the goal is to help you abstract and understand your code so that you can zero in on the right place to tweak. Yes, you will have more modules, but if you lay them out properly, you'll also have clear categories of modules and be able to dive into the right directory and file to get to the code you need.
Don Wilde
"There's more than one level to any answer."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.