I use to place all my functions first out of habit, as my first training in programming was from Pascal. In Pascal you can't call a function or a procedure if it is listed below the function or procedure you are calling from. (that use to be the case anyway, haven't used that language for several years now, and Delphi doesn't require this sturcture)

It was explained to me (way back then) that the reason for this encumberance was that the programer had to give structure to his/her thoughts before writing code. I have to admit that because of this my "thought" on code is probably better than if I was taught first with a more "open" means of programming, such as Perl and C allows. You couldn't just say "hey, I need a function" and just throw it in there. It kept code clean and tight.. in my opinion anyway. I'm sure that others would have a more practical view point on this, such as "damn, I need a function here"

I have since changed to putting the main program above and functions below, for exactly the reasons you describe, its easier to go through the code, and most of my stuff is Object programming these days, so its more or less a mute point.

Update

I have since learned of the possiblity of unexpected Global variables, and I belive Globals are the seeds of the DEVIL :-) Out of habit I declare all variables with my so this keeps the possiblity of Global variables sneaking into the effects of my scripts, but thought I would mention this, incase you don't read further down to some of the great posts below this one.

Glenn H.
webadept.net

In reply to Re: where do you put your subs by webadept
in thread where do you put your subs by greenFox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.