From: Peter J. Holzer on
On 2010-08-10 03:20, Uri Guttman <uri(a)StemSystems.com> wrote:
> i review code for my recruiting business and i would downgrade any
> code with predeclared subs. putting the subs before the calls makes
> for a hard to read file.

The top-down vs. bottom-up debate will probably never be decided. You
are obviously firmly in the top-down camp, but others may prefer it the
other way around. Some time ago I read "Coders at Work" by Peter Seibel.
He asked every one "top-down or bottom-up?" and although I didn't count
the answers, I seem to remember that it was about an even split (with
quite a few answering "both" or "neither").

hp

From: Peter J. Holzer on
On 2010-08-10 05:27, Uri Guttman <uri(a)StemSystems.com> wrote:
>>>>>> "BM" == Ben Morrow <ben(a)morrow.me.uk> writes:
>
> BM> Quoth "Uri Guttman" <uri(a)StemSystems.com>:
>
> >> and that is a waste of pixels as well. why do more work than you need
> >> to? i review code for my recruiting business and i would downgrade any
> >> code with predeclared subs.
>
> BM> Well, apart from anything else it moves errors from runtime to compile
> BM> time, which is always a good thing.
>
> true in general. but then we would all be using prototypes! :)

The main reason I don't use prototypes is that they are ignored for
method calls.

hp

From: Keith Thompson on
"Uri Guttman" <uri(a)StemSystems.com> writes:
>>>>>> "KT" == Keith Thompson <kst-u(a)mib.org> writes:
>
> KT> "Uri Guttman" <uri(a)StemSystems.com> writes:
> >>>>>>> "KT" == Keith Thompson <kst-u(a)mib.org> writes:
> KT> I tend to omit parentheses in many cases where they're not necessary.
> KT> For example, I might write:
> >>
> KT> sub Foo;
> KT> ...
> KT> my $x = Foo 42; # rather than Foo(42)
> KT> ...
> KT> sub Foo {
> KT> my($arg) = @_;
> KT> return $arg + 1;
> KT> }
> >>
> >> that only works if you declare Foo before you call it. perl can't tell
> >> if a bareword is a sub if it hasn't seen it before unless you use parens.
>
> KT> Which is why I always predeclare all my subroutines.
>
> and that is a waste of pixels as well. why do more work than you need
> to? i review code for my recruiting business and i would downgrade any
> code with predeclared subs. putting the subs before the calls makes for
> a hard to read file. i put low importance subs at the bottom and order
> the rest is some form of logical top down. this allows for easier
> understanding of the code as you read it. and that means predeclaring
> won't work. remember code is for people, not computers. and code is for
> OTHER people, not yourself.
[snip]

It seems to be that predeclaring vs. not predeclaring is largely a
matter of taste. Personally, I like to see the list of subroutines
collected in one place, at the top of the source file; it's an
opportunity to add comments briefly describing each one, rather
than having such documentation scattered throughout the program
(or script, or whatever we're calling it this week).

I am admittely influenced by some other languages I've used, in
which the interface (e.g., list of subroutines) and implementation
(e.g., statements that perform the actual work) conventionally
are, or in some cases must be, physically separated. I'm thinking
particularly of Ada's separate specifications and bodies and C and
C++'s .h and .c (or .cpp) files, but I tend to apply the pattern
even for a program contained in a single source file. Sure, it's
some extra typing, but my fingers can use the exercise.

YMMV -- in fact, apparently YMDV.

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"