comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Trouble with loop in Ada
Date: Fri, 4 Jan 2013 23:33:56 -0600
Date: 2013-01-04T23:33:56-06:00	[thread overview]
Message-ID: <kc8e0b$h7o$1@munin.nbi.dk> (raw)
In-Reply-To: kc7hgn$gse$1@speranza.aioe.org

"Derek Wyss" <udot7@yahoo.com> wrote in message 
news:kc7hgn$gse$1@speranza.aioe.org...
...
> Paul, thanks for your helpful hints as well.  My next steps for improving
> my toy will be to explore
>
> End_Of_File vs. End_Of_File(Standard_Input) --I like the 2nd one, seems
> more clear
>
> Get vs. Get_Immediate --That should be easy but for me it's worth some
> consideration
>
> Then I'll look at using exceptions in my code like you did.

I'd suggest that you go as quickly as possible to using exceptions. It's 
almost never fool-proof to pre-test for I/O, because something else running 
on the computer could change the I/O stream between the test and the read 
(this is known as a "race condition"). By handling the exceptions, you avoid 
any problems like that, and while it doesn't really make any difference in a 
toy example, it's a good practice to get into right away. (Additionally, 
End_of_File tends to bog down performance for Text_IO; again, that doesn't 
matter in a toy program, but it's another reason to avoid it.)

This is even more true when Opening/Creating files. Just do it and handle 
the exception -- *never* try to pretest for existence - the result means 
nothing as the file could be created or deleted after the test and before 
you actually do the Open. And then you *still* have to handle the exceptions 
(unless the program is a throw-away toy, and even then, good habits are 
recommended), so why bother with the extra test?

                                              Randy.





      reply	other threads:[~2013-01-05  5:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04  4:32 Trouble with loop in Ada Derek Wyss
2013-01-04 10:59 ` Brian Drummond
2013-01-04 11:11   ` Brian Drummond
2013-01-04 12:44 ` Paul Colin Gloster
2013-01-04 21:27   ` Derek Wyss
2013-01-05  5:33     ` Randy Brukardt [this message]
replies disabled

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