comp.lang.ada
 help / color / mirror / Atom feed
* is exception when others => null; smart?
@ 2002-10-24 14:03 Preben Randhol
  2002-10-24 14:25 ` David C. Hoos, Sr.
                   ` (5 more replies)
  0 siblings, 6 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-24 14:03 UTC (permalink / raw)


Hi

As Emacs (ugg!) got installed when I had to reinstall Debian due to a
hard disc crash, I thought I'd have a look at the ada-mode before
uninstalling Emacs.

Now I'm in the process of making a ada-mode for vim (currently called:
am - Ada in the Morning) which will have much of the functionality of
the ada-mode for Emacs.

However there is one thing with ada-mode which I don't know is what I
want:

If you choose to generate a body for a procedure or a function then you
get this:

   procedue Proc
   is

   begin

   exception
      when others => null;
   end Proc;

My question is: Is this smart? I mean won't you then automatically mask
all the potential problems you might get at run-time so that you won't
see errors in the code during testing? I can see that it might also have
advantages, but before I implement this I would like to hear what you
think.

Thanks in advance.

Preben
-- 
Ada95 makes your code less cryptic.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
@ 2002-10-24 14:25 ` David C. Hoos, Sr.
  2002-10-24 14:28   ` Preben Randhol
  2002-10-24 14:38 ` Per Sandbergs
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 37+ messages in thread
From: David C. Hoos, Sr. @ 2002-10-24 14:25 UTC (permalink / raw)


Well, essentially what it says is
"If anything bad happens, I don't want to know about it."

----- Original Message ----- 
From: "Preben Randhol" <randhol+news@pvv.org>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: October 24, 2002 9:03 AM
Subject: is exception when others => null; smart?


> Hi
> 
> As Emacs (ugg!) got installed when I had to reinstall Debian due to a
> hard disc crash, I thought I'd have a look at the ada-mode before
> uninstalling Emacs.
> 
> Now I'm in the process of making a ada-mode for vim (currently called:
> am - Ada in the Morning) which will have much of the functionality of
> the ada-mode for Emacs.
> 
> However there is one thing with ada-mode which I don't know is what I
> want:
> 
> If you choose to generate a body for a procedure or a function then you
> get this:
> 
>    procedue Proc
>    is
> 
>    begin
> 
>    exception
>       when others => null;
>    end Proc;
> 
> My question is: Is this smart? I mean won't you then automatically mask
> all the potential problems you might get at run-time so that you won't
> see errors in the code during testing? I can see that it might also have
> advantages, but before I implement this I would like to hear what you
> think.
> 
> Thanks in advance.
> 
> Preben
> -- 
> Ada95 makes your code less cryptic.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:25 ` David C. Hoos, Sr.
@ 2002-10-24 14:28   ` Preben Randhol
  0 siblings, 0 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-24 14:28 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> Well, essentially what it says is
> "If anything bad happens, I don't want to know about it."

Exactly what I thought too.

Preben
-- 
Ada95 makes your code less cryptic.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
  2002-10-24 14:25 ` David C. Hoos, Sr.
@ 2002-10-24 14:38 ` Per Sandbergs
  2002-10-25 15:04   ` Robert A Duff
  2002-10-24 16:39 ` Mark Biggar
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 37+ messages in thread
From: Per Sandbergs @ 2002-10-24 14:38 UTC (permalink / raw)


Hi,
In general  i find use of "when others => xxx" dumb especialy if xxx is null
since this as a general is ment to be a last resort
to catch unexpected events and report them.
My opinion about "when others => xxx" is that is may be used in the folowing
situations.

1)
  main_loop:
    loop
      begin
        lots of operations.
      exception
        when others =>
          report the error and reset top a safe state in order to continue.
    end loop;

2)
function work_is_ok(fool) return boolean is
begin
    some computations
exception --
    when others =>
        return false; -- or report error and eventualt raise.
end;
2)
procedure must_not_raie(fool) is
begin
    some computations
exception
    when others =>
        null;
end;
So when others => null is only to be used when you are expecting the
unexpected.
I wont be supprised if other peoplen are of different opinion but after
integration a number of large systems i find the above aproach "wise".

/Regards
/Per


"Preben Randhol" randhol+news@pvv.org wrote in message
news:slrnarfvcc.4ud.randhol+news@kiuk0152.chembio.ntnu.no...
> Hi
>
> As Emacs (ugg!) got installed when I had to reinstall Debian due to a
> hard disc crash, I thought I'd have a look at the ada-mode before
> uninstalling Emacs.
>
> Now I'm in the process of making a ada-mode for vim (currently called:
> am - Ada in the Morning) which will have much of the functionality of
> the ada-mode for Emacs.
>
> However there is one thing with ada-mode which I don't know is what I
> want:
>
> If you choose to generate a body for a procedure or a function then you
> get this:
>
>    procedue Proc
>    is
>
>    begin
>
>    exception
>       when others => null;
>    end Proc;
>
> My question is: Is this smart? I mean won't you then automatically mask
> all the potential problems you might get at run-time so that you won't
> see errors in the code during testing? I can see that it might also have
> advantages, but before I implement this I would like to hear what you
> think.
>
> Thanks in advance.
>
> Preben
> --
> Ada95 makes your code less cryptic.
>





^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
  2002-10-24 14:25 ` David C. Hoos, Sr.
  2002-10-24 14:38 ` Per Sandbergs
@ 2002-10-24 16:39 ` Mark Biggar
  2002-10-24 20:06   ` Robert A Duff
  2002-10-24 20:11   ` is exception when others => null; smart? Simon Wright
  2002-10-24 20:03 ` Robert A Duff
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 37+ messages in thread
From: Mark Biggar @ 2002-10-24 16:39 UTC (permalink / raw)


Preben Randhol wrote:
> Hi
> 
> As Emacs (ugg!) got installed when I had to reinstall Debian due to a
> hard disc crash, I thought I'd have a look at the ada-mode before
> uninstalling Emacs.
> 
> Now I'm in the process of making a ada-mode for vim (currently called:
> am - Ada in the Morning) which will have much of the functionality of
> the ada-mode for Emacs.
> 
> However there is one thing with ada-mode which I don't know is what I
> want:
> 
> If you choose to generate a body for a procedure or a function then you
> get this:
> 
>    procedue Proc
>    is
> 
>    begin
> 
>    exception
>       when others => null;
>    end Proc;
> 
> My question is: Is this smart? I mean won't you then automatically mask
> all the potential problems you might get at run-time so that you won't
> see errors in the code during testing? I can see that it might also have
> advantages, but before I implement this I would like to hear what you
> think.


Probably not.  If you want the opposite policy change it to:

when others => raise;

BTW, make it an optional feature which way you want it.


-- 
Mark Biggar
mark.a.biggar@attbi.com




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
                   ` (2 preceding siblings ...)
  2002-10-24 16:39 ` Mark Biggar
@ 2002-10-24 20:03 ` Robert A Duff
  2002-10-25  1:49 ` SteveD
  2002-10-25  3:48 ` Dennis Lee Bieber
  5 siblings, 0 replies; 37+ messages in thread
From: Robert A Duff @ 2002-10-24 20:03 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> writes:

> If you choose to generate a body for a procedure or a function then you
> get this:
> 
>    procedue Proc
>    is
> 
>    begin
> 
>    exception
>       when others => null;
>    end Proc;
> 
> My question is: Is this smart?

No.  You usually don't want an exception handler, and when you do, you
almost never want "null;".

- Bob



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 16:39 ` Mark Biggar
@ 2002-10-24 20:06   ` Robert A Duff
  2002-10-24 20:23     ` Wes Groleau
  2002-10-24 20:11   ` is exception when others => null; smart? Simon Wright
  1 sibling, 1 reply; 37+ messages in thread
From: Robert A Duff @ 2002-10-24 20:06 UTC (permalink / raw)


Mark Biggar <mark.a.biggar@attbi.com> writes:

> Probably not.  If you want the opposite policy change it to:
> 
> when others => raise;

But that's what happens when you don't have an exception handler at all!

It seems to me that editors that automatically generate procedure body
templates should *not* insert exception handlers.  It's not helpful --
99% of the time, the user will have to delete the thing.  And
furthermore, there is no sensible "default" code to put in the handler.
"Raise;" is better than "null;", but neither one is usually what you
want.

- Bob




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 16:39 ` Mark Biggar
  2002-10-24 20:06   ` Robert A Duff
@ 2002-10-24 20:11   ` Simon Wright
  2002-10-24 21:22     ` Larry Kilgallen
  1 sibling, 1 reply; 37+ messages in thread
From: Simon Wright @ 2002-10-24 20:11 UTC (permalink / raw)


Mark Biggar <mark.a.biggar@attbi.com> writes:

> Probably not.  If you want the opposite policy change it to:
> 
> when others => raise;
> 
> BTW, make it an optional feature which way you want it.

If you do make it optional, the options should be

* have "when others => raise;".

* have no handler at all.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 20:06   ` Robert A Duff
@ 2002-10-24 20:23     ` Wes Groleau
  2002-10-25  1:16       ` Jeffrey Carter
  0 siblings, 1 reply; 37+ messages in thread
From: Wes Groleau @ 2002-10-24 20:23 UTC (permalink / raw)



> It seems to me that editors that automatically generate procedure body
> templates should *not* insert exception handlers.  It's not helpful --
> 99% of the time, the user will have to delete the thing.  And

I would recommend auto-insert:

   --[ exception
   --[    when others => raise;

This makes you think about it, and then it's easy to
auto-strip any you chose not to modify.




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 20:11   ` is exception when others => null; smart? Simon Wright
@ 2002-10-24 21:22     ` Larry Kilgallen
  0 siblings, 0 replies; 37+ messages in thread
From: Larry Kilgallen @ 2002-10-24 21:22 UTC (permalink / raw)


In article <x7v8z0negx6.fsf@pushface.org>, Simon Wright <simon@pushface.org> writes:
> Mark Biggar <mark.a.biggar@attbi.com> writes:
> 
>> Probably not.  If you want the opposite policy change it to:
>> 
>> when others => raise;
>> 
>> BTW, make it an optional feature which way you want it.
> 
> If you do make it optional, the options should be
> 
> * have "when others => raise;".
> 
> * have no handler at all.

The important difference between these options, I presume,
would be whether or not you are being paid by the line of code written :-)



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 20:23     ` Wes Groleau
@ 2002-10-25  1:16       ` Jeffrey Carter
  2002-10-25 10:10         ` In case statment? (was Re: is exception when others => null; smart?) Preben Randhol
  0 siblings, 1 reply; 37+ messages in thread
From: Jeffrey Carter @ 2002-10-25  1:16 UTC (permalink / raw)


Wes Groleau wrote:
> 
> I would recommend auto-insert:
> 
>   --[ exception
>   --[    when others => raise;

Just as the area for the sequence of statements is empty, the area for 
exception handlers should be as well:

begin

exception

end Joe;

Now the coder has to think about what exception handling, if any, is 
appropriate in order for the code to compile. Too many developers don't 
think about exceptions unless they have to. The other suggestions allow 
the coder to not think about exceptions. This at least forces him to 
think, "Hey, I've got to delete this line to get it to compile.". In the 
process, maybe he'll realize that such-and-such an exception is 
possible, and the correct response is so-and-so.

-- 
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
                   ` (3 preceding siblings ...)
  2002-10-24 20:03 ` Robert A Duff
@ 2002-10-25  1:49 ` SteveD
  2002-10-25  3:48 ` Dennis Lee Bieber
  5 siblings, 0 replies; 37+ messages in thread
From: SteveD @ 2002-10-25  1:49 UTC (permalink / raw)


"Preben Randhol" <randhol+news@pvv.org> wrote in message
news:slrnarfvcc.4ud.randhol+news@kiuk0152.chembio.ntnu.no...
[snip]
>
> My question is: Is this smart? I mean won't you then automatically mask
> all the potential problems you might get at run-time so that you won't
> see errors in the code during testing? I can see that it might also have
> advantages, but before I implement this I would like to hear what you
> think.
>

Although I don't use Emacs or Vi, I would vote to not automatically
inserting exception handlers that ignores exceptions.  Although it might
make Ada appear more familiar to C programmers ;-)

SteveD

> Thanks in advance.
>
> Preben
> --
> Ada95 makes your code less cryptic.





^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
                   ` (4 preceding siblings ...)
  2002-10-25  1:49 ` SteveD
@ 2002-10-25  3:48 ` Dennis Lee Bieber
  2002-10-26 11:34   ` Preben Randhol
  5 siblings, 1 reply; 37+ messages in thread
From: Dennis Lee Bieber @ 2002-10-25  3:48 UTC (permalink / raw)


Preben Randhol fed this fish to the penguins on Thursday 24 October 
2002 07:03 am:

> 
> Now I'm in the process of making a ada-mode for vim (currently called:
> am - Ada in the Morning) which will have much of the functionality of
> the ada-mode for Emacs.
>
        <blink> I have Mandrake, and vim seems to already have an Ada mode...

--  
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



^ permalink raw reply	[flat|nested] 37+ messages in thread

* In case statment? (was Re: is exception when others => null; smart?)
  2002-10-25  1:16       ` Jeffrey Carter
@ 2002-10-25 10:10         ` Preben Randhol
  2002-10-25 14:59           ` Robert A Duff
                             ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-25 10:10 UTC (permalink / raw)


Jeffrey Carter wrote:
> Just as the area for the sequence of statements is empty, the area for 
> exception handlers should be as well:
> 
> begin
> 
> exception
> 
> end Joe;

Thanks all for the input!

I will do it like this so start with. I can add the option to have
exception added later :-)

Now my next question is should a case statment be:

   case Number is

      when others =>
         null;
   end case;

Or simply:

   case Number is

   end case;

I'm leaning towards the latter as this is also how ada-mode does it.

Thanks in advance.

Regards,
Preben
-- 
Preben Randhol  --------------------  http://www.pvv.org/~randhol
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-25 10:10         ` In case statment? (was Re: is exception when others => null; smart?) Preben Randhol
@ 2002-10-25 14:59           ` Robert A Duff
  2002-10-25 15:06             ` Preben Randhol
  2002-10-29 18:23             ` Peter Richtmyer
  2002-10-25 17:13           ` In case statment? <...> when others John Woodruff
  2002-10-27 21:03           ` In case statment? (was Re: is exception when others => null; smart?) Ze Administrator
  2 siblings, 2 replies; 37+ messages in thread
From: Robert A Duff @ 2002-10-25 14:59 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> writes:

> Now my next question is should a case statment be:
> 
>    case Number is
> 
>       when others =>
>          null;
>    end case;
> 
> Or simply:
> 
>    case Number is
> 
>    end case;
> 
> I'm leaning towards the latter as this is also how ada-mode does it.

"When others" is usually a very bad idea, and editors should not
encourage it.  One of the great benefits of Ada is the full-coverage
checking you get (at compile time!) on case statements and aggregates.
(Compared to other languages which default to "when others => null;" or
use run-time checking.)

Some folks think "when others" is just a shorthand for all the rest of
the enumeration literals (or whatever) in the type, that you don't feel
like typing in.  After all, that's what the RM says.  But I think "when
others" really means "all the others, INCLUDING the ones that will be
invented next week or next year".  So you should use "when others" only
when you're pretty sure all the others that will ever be invented must
necessarily fall into the same category.  That's rare.

So I agree: choose the latter.

- Bob



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-24 14:38 ` Per Sandbergs
@ 2002-10-25 15:04   ` Robert A Duff
  2002-10-25 20:41     ` Dale Stanbrough
  2002-10-26  7:47     ` tmoran
  0 siblings, 2 replies; 37+ messages in thread
From: Robert A Duff @ 2002-10-25 15:04 UTC (permalink / raw)


"Per Sandbergs" <prsa@cntw.com> writes:

> 1)
>   main_loop:
>     loop
>       begin
>         lots of operations.
>       exception
>         when others =>
>           report the error and reset top a safe state in order to continue.
>     end loop;
> 
> 2)
> function work_is_ok(fool) return boolean is
> begin
>     some computations
> exception --
>     when others =>
>         return false; -- or report error and eventualt raise.
> end;
> 2)
> procedure must_not_raie(fool) is
> begin
>     some computations
> exception
>     when others =>
>         null;
> end;
> So when others => null is only to be used when you are expecting the
> unexpected.
> I wont be supprised if other peoplen are of different opinion but after
> integration a number of large systems i find the above aproach "wise".

Also,

4)

    when others =>
        clean up;
        raise;

As in:

    procedure Walk_Tree(...) is
    begin
        Push current node on stack;
        walk subtrees;
        Pop stack;
    exception
        when others =>
            Pop stack; -- Keep stack in synch even in case of exception.
            raise;
    end Walk_Tree;

Finalization can also be used for this purpose, and that's a cleaner way
to do it, but finalization is *very* expensive in most Ada compilers,
whereas the above "when others" is pretty cheap.

- Bob



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-25 14:59           ` Robert A Duff
@ 2002-10-25 15:06             ` Preben Randhol
  2002-10-29 18:23             ` Peter Richtmyer
  1 sibling, 0 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-25 15:06 UTC (permalink / raw)


Robert A Duff wrote:
> 
> "When others" is usually a very bad idea, and editors should not
> encourage it.  One of the great benefits of Ada is the full-coverage
> checking you get (at compile time!) on case statements and aggregates.
> (Compared to other languages which default to "when others => null;" or
> use run-time checking.)

Good point. Thanks!

OK, I'll continue implementing now :-)

Preben
-- 
Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
Just vim it.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? <...> when others
  2002-10-25 10:10         ` In case statment? (was Re: is exception when others => null; smart?) Preben Randhol
  2002-10-25 14:59           ` Robert A Duff
@ 2002-10-25 17:13           ` John Woodruff
  2002-10-27 21:03           ` In case statment? (was Re: is exception when others => null; smart?) Ze Administrator
  2 siblings, 0 replies; 37+ messages in thread
From: John Woodruff @ 2002-10-25 17:13 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> wrote in message news:<slrnari64a.pd.randhol+news@kiuk0152.chembio.ntnu.no>...
<...>
 
> Now my next question is should a case statment be:
> 
>    case Number is
> 
>       when others =>
>          null;
>    end case;
> 
> Or simply:
> 
>    case Number is
> 
>    end case;
> 
> I'm leaning towards the latter as this is also how ada-mode does it.


I urge you to follow your leaning.  My reasoning is that (in my
experience) it is fairly common to extend an enumeration;  By omiting
the "others", I will be sure to be reminded that I need to revisit the
case statement(s).

John



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-25 15:04   ` Robert A Duff
@ 2002-10-25 20:41     ` Dale Stanbrough
  2002-10-26 23:04       ` Robert A Duff
  2002-10-26  7:47     ` tmoran
  1 sibling, 1 reply; 37+ messages in thread
From: Dale Stanbrough @ 2002-10-25 20:41 UTC (permalink / raw)


Robert A Duff wrote:

> Finalization can also be used for this purpose, and that's a cleaner way
> to do it, but finalization is *very* expensive in most Ada compilers,
> whereas the above "when others" is pretty cheap.


Are the same costs associated with C++ destructors, or is there
something peculiar to Ada that causes it to be so expensive?

Dale



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-25 15:04   ` Robert A Duff
  2002-10-25 20:41     ` Dale Stanbrough
@ 2002-10-26  7:47     ` tmoran
  1 sibling, 0 replies; 37+ messages in thread
From: tmoran @ 2002-10-26  7:47 UTC (permalink / raw)


> but finalization is *very* expensive in most Ada compilers,
A loop calling a procedure
  procedure p(i : in integer) is
    x : a_record_with_field_n;
  begin
    if x.n /= 0 then global_junk := 1;end if;
  end p;
took 12 nanoseconds on my 866Mhz machine when "x" was an ordinary
small record, but nearly 400 nanoseconds when x was controlled and had
an explicit Finalize procedure.  Similar times with two different
compilers.
  In many contexts objects to be Controlled last long enough that
0.4 microseconds to finalize one is not fatally expensive.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-25  3:48 ` Dennis Lee Bieber
@ 2002-10-26 11:34   ` Preben Randhol
  0 siblings, 0 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-26 11:34 UTC (permalink / raw)


Dennis Lee Bieber wrote:
>         <blink> I have Mandrake, and vim seems to already have an Ada mode...

Oh? You are not refering to that it has Ada support for syntax
highlighting and indentation?

What I'm making are templates so that by pressing[*] f.ex \aP
will inserted the text below after asking for a package name:

package Package_Name is

end Package_Name;

and put the cursor between the two lines. After making all the templates
and also support for commenting/uncommenting blocks I will release a
version. Then my plan is to develope some glue (if needed) with other
very useful scripts that exists for vim. Examples are:

   http://vim.sourceforge.net/script.php?script_id=69
   http://vim.sourceforge.net/script.php?script_id=31
   http://vim.sourceforge.net/script.php?script_id=294
   http://vim.sourceforge.net/script.php?script_id=42
   http://vim.sourceforge.net/script.php?script_id=39
   http://vim.sourceforge.net/script.php?script_id=21
   http://vim.sourceforge.net/script.php?script_id=58
   http://vim.sourceforge.net/script.php?script_id=273

For more scripts and tips see: http://vim.sf.net/
_____________________________________________________________
[*] The keybindings will all be configurable for the user.


Regards,
Preben
-- 
Vim the winner of "Favorite Text Editor" category in the 2002 Readers'
Choice Awards of the Linux Journal.



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: is exception when others => null; smart?
  2002-10-25 20:41     ` Dale Stanbrough
@ 2002-10-26 23:04       ` Robert A Duff
  0 siblings, 0 replies; 37+ messages in thread
From: Robert A Duff @ 2002-10-26 23:04 UTC (permalink / raw)


Dale Stanbrough <dstanbro@bigpond.net.au> writes:

> Robert A Duff wrote:
> 
> > Finalization can also be used for this purpose, and that's a cleaner way
> > to do it, but finalization is *very* expensive in most Ada compilers,
> > whereas the above "when others" is pretty cheap.
> 
> Are the same costs associated with C++ destructors, or is there
> something peculiar to Ada that causes it to be so expensive?

I don't know the details of C++ well enough to answer that
for sure.

It's interesting that C++ had destructors first, and then added
exception handling, and folks would rend their clothing over the added
complexity of exception handling.

Ada had exception handling first, and then added finalization, and folks
would rend their clothing over the added complexity of finalization.

The truth is that there are interactions between the two features,
and the last one added to the language gets the blame.

I suspect that the total complexity of these features in Ada and C++ is
roughly equal.  And likewise, the difficulty of doing it efficiently.
I think finalization *can* be done efficiently, but it's not easy.
I think the Rational compiler uses an efficient method, but the others
don't (including the one *my* company, SofCheck, sells -- sigh).

The one thing I can think of that is special to Ada is aborts (including
"select-then-abort" statements.  Finalization requires aborts to be
deferred, and that is expensive in many systems.  (I think the fact that
it's expensive is a design flaw in some operating systems, but since I
usually write compilers and not (desk-top) operating systems, I don't
have too much control over that.)  The "abort" issue does not come up
for C++.

- Bob



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-25 10:10         ` In case statment? (was Re: is exception when others => null; smart?) Preben Randhol
  2002-10-25 14:59           ` Robert A Duff
  2002-10-25 17:13           ` In case statment? <...> when others John Woodruff
@ 2002-10-27 21:03           ` Ze Administrator
  2002-10-28 10:04             ` Preben Randhol
  2002-10-28 12:32             ` In case statment? (was Re: is exception when others => null;smart?) Adrian Hoe
  2 siblings, 2 replies; 37+ messages in thread
From: Ze Administrator @ 2002-10-27 21:03 UTC (permalink / raw)



> Now my next question is should a case statment be:
> 
>    case Number is
> 
>       when others =>
>          null;
>    end case;
> 
> Or simply:
> 
>    case Number is
> 
>    end case;

Not easy to do, but it would be really cool
if you could generate

    case Number is

       when One   =>
       when Two   =>
       when Three =>
etc.

In other words, if the tool could be smart enough
to find and parse the type of Number and provide
all the slots.




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-27 21:03           ` In case statment? (was Re: is exception when others => null; smart?) Ze Administrator
@ 2002-10-28 10:04             ` Preben Randhol
  2002-10-28 20:05               ` Wes Groleau
  2002-10-28 12:32             ` In case statment? (was Re: is exception when others => null;smart?) Adrian Hoe
  1 sibling, 1 reply; 37+ messages in thread
From: Preben Randhol @ 2002-10-28 10:04 UTC (permalink / raw)


Ze Administrator wrote:
> Not easy to do, but it would be really cool
> if you could generate
> 
>     case Number is
> 
>        when One   =>
>        when Two   =>
>        when Three =>
> etc.
> 
> In other words, if the tool could be smart enough
> to find and parse the type of Number and provide
> all the slots.

Not easy, besides what if you wanted:

      case Numer is
         when One | Two =>
         --
         when Three =>
         --


-- 
Preben Randhol  --------------------  http://www.pvv.org/~randhol
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null;smart?)
  2002-10-27 21:03           ` In case statment? (was Re: is exception when others => null; smart?) Ze Administrator
  2002-10-28 10:04             ` Preben Randhol
@ 2002-10-28 12:32             ` Adrian Hoe
  1 sibling, 0 replies; 37+ messages in thread
From: Adrian Hoe @ 2002-10-28 12:32 UTC (permalink / raw)


Ze Administrator wrote:

> 
>> Now my next question is should a case statment be:
>>
>>    case Number is
>>
>>       when others =>
>>          null;
>>    end case;
>>
>> Or simply:
>>
>>    case Number is
>>
>>    end case;
> 
> 
> Not easy to do, but it would be really cool
> if you could generate
> 
>    case Number is
> 
>       when One   =>
>       when Two   =>
>       when Three =>
> etc.
> 
> In other words, if the tool could be smart enough
> to find and parse the type of Number and provide
> all the slots.
> 

This will be difficult and can have hundreds of possiblities, who knows?

But if the editor is interactive enough when it is asked to generate 
case, it can be considered.
-- 
type Dmitry is new Adrian;           -- Adrian Hoe
                                      -- http://adrianhoe.com
                                      -- Remove *nospam* to email




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-28 10:04             ` Preben Randhol
@ 2002-10-28 20:05               ` Wes Groleau
  2002-10-30 11:31                 ` Preben Randhol
  0 siblings, 1 reply; 37+ messages in thread
From: Wes Groleau @ 2002-10-28 20:05 UTC (permalink / raw)


Preben Randhol wrote:
> Ze Administrator wrote:
> 
>>Not easy to do, but it would be really cool
>>if you could generate
>>
>>    case Number is
>>
>>       when One   =>
>>       when Two   =>
>>       when Three =>
>>etc.
>>
>>In other words, if the tool could be smart enough
>>to find and parse the type of Number and provide
>>all the slots.
> 
> Not easy, besides what if you wanted:
> 
>       case Numer is
>          when One | Two =>
>          --
>          when Three =>
>          --

Not easy--that's what I said.  As for the above,
in most editors, I would highlight

     =>
   when

and hit the vert bar key.  Much easier than typing
the whole thing.




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-25 14:59           ` Robert A Duff
  2002-10-25 15:06             ` Preben Randhol
@ 2002-10-29 18:23             ` Peter Richtmyer
  2002-10-30  2:52               ` Steven Deller
                                 ` (3 more replies)
  1 sibling, 4 replies; 37+ messages in thread
From: Peter Richtmyer @ 2002-10-29 18:23 UTC (permalink / raw)


Robert A Duff <bobduff@shell01.TheWorld.com> wrote in message news:<wccpttyk1ia.fsf@shell01.TheWorld.com>...
> 
> "When others" is usually a very bad idea, and editors should not
> encourage it.  

I find this topic somewhat amusing because my previous employer
required a "when others" on ALL case statements, even when 
all values were covered by the "when" clauses. My current job
requires us to specify all cases, and we are not allowed to 
put a "when others" clause in.

As the following example illustrates, it really depends upon
the compiler too. A "bad" value is handled differently as
shown:
-----------------------------------------------------------
with system;
with text_io;
procedure test is
    
     a : character := character'val(2#11111111#);   
     for a'size use 8;
     b : boolean;
     for b'address use a'address;
     for b'size use 8;
     
begin 

   case b is
      when true =>
        text_io.put_line ("b is true");     
      when false =>
        text_io.put_line ("b is false");
      when others =>
        text_io.put_line ("ObjectAda for Windows V7.1.105 "    & 
                          "professional " edition gets here, " &
                          "and so does Rational Apex Ada 95 v. 4.0.0b");    
   end case;
     
exception
   when others =>  
      text_io.put_line ("Gnat 3.14P gets here ");  
end test;
---------------------------------------------------------------



^ permalink raw reply	[flat|nested] 37+ messages in thread

* RE: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-29 18:23             ` Peter Richtmyer
@ 2002-10-30  2:52               ` Steven Deller
  2002-10-30  8:58               ` Anders Wirzenius
                                 ` (2 subsequent siblings)
  3 siblings, 0 replies; 37+ messages in thread
From: Steven Deller @ 2002-10-30  2:52 UTC (permalink / raw)


Peter,
I'd bet it also depends on optimization.  At least for Rational, using
the "for" clauses is tantamount to saying "I know the values at this
location are ok, so just use them".  A 'valid could be used to test, but
otherwise, Rational opts to not test.  And the "when others" is, as
expected, a last ditch if the first two compares fail.

You might change your code to do something like:
  c : boolean
...
begin
   begin
     c := b ;
   exception
     when others => text_io.put_line "yet another possibility" ;
   end ;
   case b is
...

And you might test at different optimization levels.  At level 0,
Rational may very well include a constraint check on b that is, at
higher optimizations, optimized away per RM permissions.

Regards,
Steve
   

> -----Original Message-----

> As the following example illustrates, it really depends upon 
> the compiler too. A "bad" value is handled differently as
> shown:
> -----------------------------------------------------------
> with system;
> with text_io;
> procedure test is
>     
>      a : character := character'val(2#11111111#);   
>      for a'size use 8;
>      b : boolean;
>      for b'address use a'address;
>      for b'size use 8;
>      
> begin 
> 
>    case b is
>       when true =>
>         text_io.put_line ("b is true");     
>       when false =>
>         text_io.put_line ("b is false");
>       when others =>
>         text_io.put_line ("ObjectAda for Windows V7.1.105 "    & 
>                           "professional " edition gets here, " &
>                           "and so does Rational Apex Ada 95 
> v. 4.0.0b");    
>    end case;
>      
> exception
>    when others =>  
>       text_io.put_line ("Gnat 3.14P gets here ");  
> end test;
> 




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-29 18:23             ` Peter Richtmyer
  2002-10-30  2:52               ` Steven Deller
@ 2002-10-30  8:58               ` Anders Wirzenius
  2002-10-30 19:57                 ` Peter Richtmyer
  2002-10-30  9:36               ` Lutz Donnerhacke
  2002-10-30 13:28               ` Marin David Condic
  3 siblings, 1 reply; 37+ messages in thread
From: Anders Wirzenius @ 2002-10-30  8:58 UTC (permalink / raw)


"Peter Richtmyer" <prichtmyer@yahoo.com> wrote in message
news:1b585154.0210291023.70af4929@posting.google.com...

> As the following example illustrates, it really depends upon
> the compiler too. A "bad" value is handled differently as
> shown:
> -----------------------------------------------------------
> with system;
> with text_io;
> procedure test is
>
>      a : character := character'val(2#11111111#);
>      for a'size use 8;
>      b : boolean;
>      for b'address use a'address;
>      for b'size use 8;
>
> begin
>
>    case b is
>       when true =>
>         text_io.put_line ("b is true");
>       when false =>
>         text_io.put_line ("b is false");
>       when others =>
>         text_io.put_line ("ObjectAda for Windows V7.1.105 "    &
>                           "professional " edition gets here, " &
>                           "and so does Rational Apex Ada 95 v. 4.0.0b");
>    end case;
>
> exception
>    when others =>
>       text_io.put_line ("Gnat 3.14P gets here ");
> end test;
> ---------------------------------------------------------------

But if you move the assignment to after begin, the Gnat behaviour changes:
...
     a : character;
     for a'size use 8;
     b : boolean := false;
     for b'address use a'address;
     for b'size use 8;

begin
   a := character'val(2#11111111#);
...
and the program execution ends up under when others =>

Anders






^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-29 18:23             ` Peter Richtmyer
  2002-10-30  2:52               ` Steven Deller
  2002-10-30  8:58               ` Anders Wirzenius
@ 2002-10-30  9:36               ` Lutz Donnerhacke
  2002-10-30 19:44                 ` Peter Richtmyer
  2002-10-30 13:28               ` Marin David Condic
  3 siblings, 1 reply; 37+ messages in thread
From: Lutz Donnerhacke @ 2002-10-30  9:36 UTC (permalink / raw)


* Peter Richtmyer wrote:
> As the following example illustrates, it really depends upon
> the compiler too. A "bad" value is handled differently as
> shown:
> -----------------------------------------------------------
> with system;
> with text_io;
> procedure test is
>     
>      a : character := character'val(2#11111111#);   
>      for a'size use 8;
>      b : boolean;
>      for b'address use a'address;
>      for b'size use 8;

Don't map variable b without pragma Import(Ada, b);
This prevents initialising of address space, which--in this case--renders
your example unusable.




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-28 20:05               ` Wes Groleau
@ 2002-10-30 11:31                 ` Preben Randhol
  0 siblings, 0 replies; 37+ messages in thread
From: Preben Randhol @ 2002-10-30 11:31 UTC (permalink / raw)


Wes Groleau wrote:
> Not easy--that's what I said.  As for the above,
> in most editors, I would highlight
> 
>      =>
>    when
> 
> and hit the vert bar key.  Much easier than typing
> the whole thing.

I have now added support for case. It will only ask for the variable and
then write:

   case Number is
      
   end case;

I've added a function for 'when' too so that you'll get asked for
discriminates until you give an empty response, then it writes => and let
you type the statement. If you don't give any discriminates then the
cursor is placed after when so you can type it in yourself.

-- 
Preben Randhol  --------------------  http://www.pvv.org/~randhol
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-29 18:23             ` Peter Richtmyer
                                 ` (2 preceding siblings ...)
  2002-10-30  9:36               ` Lutz Donnerhacke
@ 2002-10-30 13:28               ` Marin David Condic
  2002-10-30 20:34                 ` Robert Spooner
  3 siblings, 1 reply; 37+ messages in thread
From: Marin David Condic @ 2002-10-30 13:28 UTC (permalink / raw)


Well, one excuse for always having a "when others" in a case statement might
be that you anticipate additions to the enumerated type driving it and you
want the code to take come appropriate action if it gets a new, unknown
value.

If you never use a "when others", you get the advantage that perhaps the
compiler or runtime will catch inadvertent errors. If you always use "when
others" you get the advantage of a built in accommodation for a software
fault. Its an engineering tradeoff so "never" and "always" don't seem to
really apply. It depends on the nature of the system and the consequences of
hitting a case statement with a value not covered.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Peter Richtmyer <prichtmyer@yahoo.com> wrote in message
news:1b585154.0210291023.70af4929@posting.google.com...
> Robert A Duff <bobduff@shell01.TheWorld.com> wrote in message
news:<wccpttyk1ia.fsf@shell01.TheWorld.com>...
>
> I find this topic somewhat amusing because my previous employer
> required a "when others" on ALL case statements, even when
> all values were covered by the "when" clauses. My current job
> requires us to specify all cases, and we are not allowed to
> put a "when others" clause in.
>






^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-30  9:36               ` Lutz Donnerhacke
@ 2002-10-30 19:44                 ` Peter Richtmyer
  0 siblings, 0 replies; 37+ messages in thread
From: Peter Richtmyer @ 2002-10-30 19:44 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnarv9vv.pr.lutz@taranis.iks-jena.de>...
> * Peter Richtmyer wrote:
> > As the following example illustrates, it really depends upon
> > the compiler too. A "bad" value is handled differently as
> > shown:
> > -----------------------------------------------------------
> > with system;
> > with text_io;
> > procedure test is
> >     
> >      a : character := character'val(2#11111111#);   
> >      for a'size use 8;
> >      b : boolean;
> >      for b'address use a'address;
> >      for b'size use 8;
> 
> Don't map variable b without pragma Import(Ada, b);
> This prevents initialising of address space, which--in this case--renders
> your example unusable.

The type boolean does not have a default value, so the program 
behaves the same (on Gnat) with or wothout the Pragma. You can see 
this by adding this line after "begin":

   text_io.put_line ("a'pos is " & integer'image (character'pos(a)));

and you should see:    a'pos is  255

Mapping the 'b' variable over 'a' does not affect the value of 'a' here.

Peter



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-30  8:58               ` Anders Wirzenius
@ 2002-10-30 19:57                 ` Peter Richtmyer
  2002-10-31  7:02                   ` Anders Wirzenius
  0 siblings, 1 reply; 37+ messages in thread
From: Peter Richtmyer @ 2002-10-30 19:57 UTC (permalink / raw)


"Anders Wirzenius" <anders.wirzenius@pp.qnet.fi> wrote in message news:<CaNv9.103$eX2.5358@read2.inet.fi>...
> "Peter Richtmyer" <prichtmyer@yahoo.com> wrote in message
> news:1b585154.0210291023.70af4929@posting.google.com...
> 
> > As the following example illustrates, it really depends upon
> > the compiler too. A "bad" value is handled differently as
> > shown:
> > -----------------------------------------------------------
> > with system;
> > with text_io;
> > procedure test is
> >
> >      a : character := character'val(2#11111111#);
> >      for a'size use 8;
> >      b : boolean;
> >      for b'address use a'address;
> >      for b'size use 8;
> >
> > begin
> >
> >    case b is
> >       when true =>
> >         text_io.put_line ("b is true");
> >       when false =>
> >         text_io.put_line ("b is false");
> >       when others =>
> >         text_io.put_line ("ObjectAda for Windows V7.1.105 "    &
> >                           "professional " edition gets here, " &
> >                           "and so does Rational Apex Ada 95 v. 4.0.0b");
> >    end case;
> >
> > exception
> >    when others =>
> >       text_io.put_line ("Gnat 3.14P gets here ");
> > end test;
> > ---------------------------------------------------------------
> 
> But if you move the assignment to after begin, the Gnat behaviour changes:
> ...
>      a : character;
>      for a'size use 8;
>      b : boolean := false;
>      for b'address use a'address;
>      for b'size use 8;
> 
> begin
>    a := character'val(2#11111111#);
> ...
> and the program execution ends up under when others =>
> 
> Anders

Were you using Gnat ? 

I tried it your way and still got the exception (which is the 
behavior I like). I also tried it your way, but with the 'a'
data definition of null char:

         a : character := character'val(0);
         for a'size use 8;
         b : boolean;
         for b'address use a'address;
         for b'size use 8;
    
     begin 
         a := character'val(2#11111111#); 

and still got the exception on Gnat. Which is what I would
expect (on Gnat).

Peter



^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-30 13:28               ` Marin David Condic
@ 2002-10-30 20:34                 ` Robert Spooner
  2002-10-31 12:40                   ` In case statment? (was Re: is exception when others => null;smart?) Marin David Condic
  0 siblings, 1 reply; 37+ messages in thread
From: Robert Spooner @ 2002-10-30 20:34 UTC (permalink / raw)


If you avoid using "when others" and a value is added to the enumeration 
type later, the compiler will tell you where _all_ the case statements 
using that enumeration type are so that you can examine them and see 
what changes should be made.  Then you don't have to spend a lot of time 
using the debugger to crawl around in your code finding and fixing the 
parts that don't work right.  There's no guarantee that the default case 
will be correct for a new value, and shifting errors from run time to 
compile time is one of Ada's bigest advantages in my estimation.

Bob

Marin David Condic wrote:
> Well, one excuse for always having a "when others" in a case statement might
> be that you anticipate additions to the enumerated type driving it and you
> want the code to take come appropriate action if it gets a new, unknown
> value.
> 
> If you never use a "when others", you get the advantage that perhaps the
> compiler or runtime will catch inadvertent errors. If you always use "when
> others" you get the advantage of a built in accommodation for a software
> fault. Its an engineering tradeoff so "never" and "always" don't seem to
> really apply. It depends on the nature of the system and the consequences of
> hitting a case statement with a value not covered.

-- 
                             Robert L. Spooner
                      Registered Professional Engineer
                        Associate Research Engineer
                   Intelligent Control Systems Department

          Applied Research Laboratory        Phone: (814) 863-4120
          The Pennsylvania State University  FAX:   (814) 863-7841
          P. O. Box 30
          State College, PA 16804-0030       rls19@psu.edu




^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null; smart?)
  2002-10-30 19:57                 ` Peter Richtmyer
@ 2002-10-31  7:02                   ` Anders Wirzenius
  0 siblings, 0 replies; 37+ messages in thread
From: Anders Wirzenius @ 2002-10-31  7:02 UTC (permalink / raw)



"Peter Richtmyer" <prichtmyer@yahoo.com> wrote in message
news:1b585154.0210301157.5358caa1@posting.google.com...
> "Anders Wirzenius" <anders.wirzenius@pp.qnet.fi> wrote in message
news:<CaNv9.103$eX2.5358@read2.inet.fi>...
> >
> > But if you move the assignment to after begin, the Gnat behaviour
changes:
> > ...
> >      a : character;
> >      for a'size use 8;
> >      b : boolean := false;
> >      for b'address use a'address;
> >      for b'size use 8;
> >
> > begin
> >    a := character'val(2#11111111#);
> > ...
> > and the program execution ends up under when others =>
> >
> > Anders
>
> Were you using Gnat ?
>
> I tried it your way and still got the exception (which is the
> behavior I like). I also tried it your way, but with the 'a'
> data definition of null char:
>
>          a : character := character'val(0);
>          for a'size use 8;
>          b : boolean;
>          for b'address use a'address;
>          for b'size use 8;
>
>      begin
>          a := character'val(2#11111111#);
>
> and still got the exception on Gnat. Which is what I would
> expect (on Gnat).
>
> Peter

Sorry, I had made another change, too, and had forgot to mentioned it :-(. I
had initialized the variable b:

b : boolean := false;

which was not in your code.

Anders






^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: In case statment? (was Re: is exception when others => null;smart?)
  2002-10-30 20:34                 ` Robert Spooner
@ 2002-10-31 12:40                   ` Marin David Condic
  0 siblings, 0 replies; 37+ messages in thread
From: Marin David Condic @ 2002-10-31 12:40 UTC (permalink / raw)


True enough, but I don't think that really changes anything with respect to
needing to look at your situation and see if it makes sense. A case
statement might process *some* of the set of possible values & adding new
enumerals can go to the default case. If it processes all of them and, while
designing it, you think about what action you want it to take if anything
new is added, you might have a proper accommodation.

I would generally agree that if a case statement is intended to process all
of a set of enumerals, avoiding "when others" helps you discover if you have
a problem should the set expand. Its just that "never" is a very long time
and engineers are wise to consider the unique circumstances around what they
are building and use what works best for that situation. A blanket rule of
"Never use 'when others'..." is a bad idea because sometimes it will make
sense to do so. That's why I dislike blanket coding conventions.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Robert Spooner <rls19@psu.edu> wrote in message
news:3DC04270.3060505@psu.edu...
> If you avoid using "when others" and a value is added to the enumeration
> type later, the compiler will tell you where _all_ the case statements
> using that enumeration type are so that you can examine them and see
> what changes should be made.  Then you don't have to spend a lot of time
> using the debugger to crawl around in your code finding and fixing the
> parts that don't work right.  There's no guarantee that the default case
> will be correct for a new value, and shifting errors from run time to
> compile time is one of Ada's bigest advantages in my estimation.
>
> Bob
>






^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2002-10-31 12:40 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 14:03 is exception when others => null; smart? Preben Randhol
2002-10-24 14:25 ` David C. Hoos, Sr.
2002-10-24 14:28   ` Preben Randhol
2002-10-24 14:38 ` Per Sandbergs
2002-10-25 15:04   ` Robert A Duff
2002-10-25 20:41     ` Dale Stanbrough
2002-10-26 23:04       ` Robert A Duff
2002-10-26  7:47     ` tmoran
2002-10-24 16:39 ` Mark Biggar
2002-10-24 20:06   ` Robert A Duff
2002-10-24 20:23     ` Wes Groleau
2002-10-25  1:16       ` Jeffrey Carter
2002-10-25 10:10         ` In case statment? (was Re: is exception when others => null; smart?) Preben Randhol
2002-10-25 14:59           ` Robert A Duff
2002-10-25 15:06             ` Preben Randhol
2002-10-29 18:23             ` Peter Richtmyer
2002-10-30  2:52               ` Steven Deller
2002-10-30  8:58               ` Anders Wirzenius
2002-10-30 19:57                 ` Peter Richtmyer
2002-10-31  7:02                   ` Anders Wirzenius
2002-10-30  9:36               ` Lutz Donnerhacke
2002-10-30 19:44                 ` Peter Richtmyer
2002-10-30 13:28               ` Marin David Condic
2002-10-30 20:34                 ` Robert Spooner
2002-10-31 12:40                   ` In case statment? (was Re: is exception when others => null;smart?) Marin David Condic
2002-10-25 17:13           ` In case statment? <...> when others John Woodruff
2002-10-27 21:03           ` In case statment? (was Re: is exception when others => null; smart?) Ze Administrator
2002-10-28 10:04             ` Preben Randhol
2002-10-28 20:05               ` Wes Groleau
2002-10-30 11:31                 ` Preben Randhol
2002-10-28 12:32             ` In case statment? (was Re: is exception when others => null;smart?) Adrian Hoe
2002-10-24 20:11   ` is exception when others => null; smart? Simon Wright
2002-10-24 21:22     ` Larry Kilgallen
2002-10-24 20:03 ` Robert A Duff
2002-10-25  1:49 ` SteveD
2002-10-25  3:48 ` Dennis Lee Bieber
2002-10-26 11:34   ` Preben Randhol

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox