You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Madan U S <ma...@collab.net> on 2006/03/31 19:55:54 UTC

RE: [Svnmerge] [PATCH] svnmerge.py: all error handling to be doneusing the error() function

Daniel Rall said:
> madan said:
> +def error(s):
> +    """Subroutine to output an error and bail."""
> +    print >> sys.stderr, "%s: %s" % (NAME, s)
> +    sys.exit(1)
> +

> > We don't really need to relocate the definition of this function
> > within the source file.

I would think so too. But I tried with a sample pythong script. It expected the declaration of a function to preceed the usage. Wondering what could be different?!

Regards,
Madan.

Re: [Svnmerge] [PATCH] svnmerge.py: all error handling to be doneusing the error() function

Posted by David James <dj...@collab.net>.
On 3/31/06, Madan U S <ma...@collab.net> wrote:
>
>
> Daniel Rall said:
>
>  > madan said:
>  > +def error(s):
>  > +    """Subroutine to output an error and bail."""
>  > +    print >> sys.stderr, "%s: %s" % (NAME, s)
>  > +    sys.exit(1)
>  > +
>
>  > > We don't really need to relocate the definition of this function
>  > > within the source file.
>
>  I would think so too. But I tried with a sample pythong script. It expected
> the declaration of a function to preceed the usage. Wondering what could be
> different?!

In Python, functions must be declared before they are called. If your
"main" function is only called at the bottom of the program, then you
can call any function in the program from the main function. For
example:
   def main():
      hello()
   def hello():
     print "hello"
   main()

If you move the call to "main()" up above the declaration of "hello",
then the program does not work. This is the difference.

Cheers,

David




--
David James -- http://www.cs.toronto.edu/~james

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: [Svnmerge] [PATCH] svnmerge.py: all error handling to be doneusing the error() function

Posted by Daniel Rall <dl...@collab.net>.
On Fri, 31 Mar 2006, Madan S. wrote:

> Daniel Rall said:
> > madan said:
> > +def error(s):
> > +    """Subroutine to output an error and bail."""
> > +    print >> sys.stderr, "%s: %s" % (NAME, s)
> > +    sys.exit(1)
> > +
> 
> > > We don't really need to relocate the definition of this function
> > > within the source file.
> 
> I would think so too. But I tried with a sample pythong script. It
> expected the declaration of a function to preceed the
> usage. Wondering what could be different?!


As this is Python (rather than C), that's not required.
<soapbox>Stylistically speaking, when the implementation language
allows it, I prefer definition of high-level code to proceed
lower-level utility routines within a source file (e.g. public stuff
before private stuff), as I feel it results in more easily
understandable code for those who come later (it's top-down,
literally).</soapbox> Also, it avoids spurious diffs in the change
history.  As usual, YMMV.
-- 

Daniel Rall