develooper Front page | perl.perl6.language | Postings from February 2001

Re: assign to magic name-of-function variable instead of "return"

Thread Previous | Thread Next
From:
Johan Vromans
Date:
February 10, 2001 04:04
Subject:
Re: assign to magic name-of-function variable instead of "return"
Message ID:
14981.10326.261146.466581@phoenix.squirrel.nl
Damian Conway <damian@cs.monash.edu.au> writes:

> 	sub {
> 		...
> 		return $yadda_yadda;
> 	}
> 	always { close F }

Let's try not to fall into the Java trap.
If exception handling gets too wordy, programmers will try to reduce
the overhead by combining many statements. In Java, one often sees
things like:

    try {
        ... enormous amount of statements ...
    }
    catch ( Exception e ) {
        e.printStackTrace();
    }

As a result, error messages become utterly useless. I almost never see
a Java program that reports "Cannot open file foo". Instead, it
reports a java.lang.ioerrorexception and a stracktrace of several
pages. Useless if you do not have the source, often even if you have.

And no, don't call this just a programmer's habit. It is significantly
induced by the formality and verbosity of the language. Compare:

    open my $f, $thefile or die ("$thefile: $!\n");

with

    try {
        File f = new File (theFile);
    }
    catch ( FileNotFoundException e1 ) {
        System.err.println (theFile + ": Not found");
	System.exit();
    }
    catch ( IOErrorException e2 ) {
        System.err.println (theFile + ": IO error");
	System.exit();
    }
    catch ( ... ) {
        ...
    }

-- Johan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About