in reply to Re: How to say 'oops' in OOPs?
in thread How to say 'oops' in OOPs?

I'm personally a fan of $object->errstr, with methods returning 0 on failure. You will either agree or you won't.

Almost the same here. I use error, not errstr (try pronouncing errstr). And I return nothingness on failure.

That's a plain return;. It has the benefit of being undef in scalar context, but an empty list in list context.

Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).

Replies are listed 'Best First'.
Re: Re: Re: How to say 'oops' in OOPs?
by l2kashe (Deacon) on Apr 08, 2003 at 16:25 UTC
    I like this as well, but I usually go one step futher.

    I leave it up to the user how to handle the error, so that they can write code according to how they want to.. I usually allow a definition via the new() method or say $obj->set(err_handler, 1)

    I usually roll my own error methods, and then if an error occurs I call the error method. Based on how the called function was called (the one that caputered the error), and the preferences defined in the object, I will return the error, return 2 elems first being undef and second the actual error, return undef and set error or errstr, or actually handle the via die/warn or croak (if Carp has been use()'d...

    Its alot of work to go through originally, but it allows the user of the package great flexibility.. The same package supports the following snippets..

    $obj->method || die "$obj->{errstr}\n"; # or even $obj->method || handle_errors; # where this is a custom sub # OR (@foo) = $obj->method; die "$foo[1]\n" unless ( defined($foo[0]) ); # OR @foo = $obj->method; # and I catch the error and die out...
    Its nice to leave the programming to the programmer, and not force them to jump through my particular flaming hoops, as I'm sure they have more than enough to jump through on thier own, or they probably wouldnt be using my module in the first place ;)

    /* And the Creator, against his better judgement, wrote man.c */
Re: Re: Re: How to say 'oops' in OOPs?
by sauoq (Abbot) on Jun 07, 2003 at 18:32 UTC
    (try pronouncing errstr)

    air-stir

    I agree though, error() is better.

    -sauoq
    "My two cents aren't worth a dime.";
    
      air-stir
      While I also agree that error is better, if something isn't really pronouncable I usually "expand it". In this case, errstr becomes error string when reading; just like usr (as in /usr/bin/perl) becomes user instead of us-are.
        if something isn't really pronouncable I usually "expand it".

        While I understand your point, there's a long history of pronouncing abbreviations as they look rather than as their expansions. It's the problem of trying to communicate an exact sequence of letters that isn't a real word.

        Say someone comes to me and asks, "this class has a method that returns the error but I can't remember what it is called, what is it?" If I answer "error string" he's likely to try using error_string(); I haven't been very helpful if the function is actually called errstr(). Sure, I might answer "EE-AR-AR-ESS-TEE-AR", but spelling things out makes for tedious communication (and is prone to its own sort of errors.)

        Many abbreviations already have some sort of generally accepted pronunciation. Of course, scores of variations exist too; jargon isn't immune to dialect.

        So, yes, /usr is usually slash-user, but do you call /etc slash-etcetera? You probably call it slash-et-see like everyone else. And tmp is "temp", not "temporary", right? Do you call var "various" or "var"? Is it "opt" or "optional"? How about "dev" or "devices"? While you probably pronounce "mnt" as "mount", I'd bet that you don't call /proc slash-process or /lib slash-library. And so on.

        The same goes for common functions. The str in many standard C function names is, in my experience, generally pronounced "stir" and err as in errno or stderr is often pronounced as "air".¹

        Here are some other examples of abbreviations that are often pronounced in their short forms rather than expanded. Of couse, I'm not claiming this list is definitive or authoritative in any way; these are just some examples from my experience:

        • csh — seesh (rather than C-shell)
        • ksh — koosh, oo like book (rather than korn shell)
        • getc — get-sea (not get character)
        • malloc — mal-luck (not memory allocate)²
        • enum — ee-num (not enumeration)
        • int — int (not integer)
        • chmod — chuh-mod (not change mode)
        • dir — dir (not directory)
        • env — env or onv (not environment)
        • sync — sink (not synchronize)
        • umount — you-mount (not un-mount)
        • ord — ord (not ordinal)
        • lc — ell-see (not lowercase)
        • eof — ee-oh-eff (not end-of-file)
        and so on. . .

        But, like the saying goes, "I say toe-may-toe; you say toe-mah-toe." It doesn't really matter as long as the right meaning is communicated.

        1. I've heard stderr pronounced as "standard error", "standard air", and, infrequently, "stud air". I fall into the second category.
        2. Is it just coincidence that the use of malloc() often results in "mal" (or bad) luck? You decide... :-)

        -sauoq
        "My two cents aren't worth a dime.";