exit() to end a function

spir denis.spir at gmail.com
Mon Feb 14 09:21:20 PST 2011


On 02/14/2011 05:39 PM, Steven Schveighoffer wrote:
> On Mon, 14 Feb 2011 11:19:24 -0500, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>
>> On Monday 14 February 2011 06:12:56 Steven Schveighoffer wrote:
>>> On Sat, 12 Feb 2011 17:48:56 -0500, Jonathan M Davis <jmdavisProg at gmx.com>
>>>
>>> wrote:
>>> > There would be some value to having an attribute which indicated that a
>>> > function
>>> > never returns under any circumstances (likely since it always throws),
>>> > but that
>>> > wouldn't help exit any, since it's a C function and wouldn't have the
>>> > attribute.
>>>
>>> The bindings to C can be attributed as we see fit. A C symbol is not
>>> mangled, and so you can attach any attributes you want (you can even
>>> change the number and types of parameters).
>>>
>>> > Regardless, I see little value in complicating dmd even a little bit
>>> > more just
>>> > so that you don't have to insert an extra assert(0) after exit -
>>> > particularly
>>> > when very few programs call exit, and very few should.
>>>
>>> I agree with this.
>>>
>>> > Generally, something is
>>> > horrendously wrong if exit is being called, and there's probably a
>>> > better way to
>>> > handle it.
>>>
>>> I don't agree with this, exit has its valid uses.
>>
>> Well, I agree that it has its valid uses, but I think that such uses are quite
>> rare. You shouldn't normally be writing programs that choose to essentially just
>> die in the middle of their execution.
>
> The most common case I can think of is usage errors. Typically, a usage
> function prints the usage and then exits the program. This can be done
> differently, but it's not "wrong" to do it that way.


Exactly the way I use it :-)
Sometimes test suite are not enough, esp when the flow control is complicated 
and/or cascading. Instead of heavy use of a debugger, I "plant' 1-2-3 
writelines on the way, one exit, & run! Then i move back or forth.
There are a few precious features which, imo, have nothing to do with app 
logics, and make the whole difference between an usable and an unusable 
language. (write*, exit, literals...)

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d-learn mailing list