comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Get_Line problem (GNAT bug?)
Date: Thu, 07 Dec 2006 09:26:07 +0100
Date: 2006-12-07T09:26:07+01:00	[thread overview]
Message-ID: <el8j6v$nmr$1@cernne03.cern.ch> (raw)
In-Reply-To: <1c1gbc5u9cpvp.1wj1zhhn7q86j$.dlg@40tude.net>

Dmitry A. Kazakov wrote:

> When End_Of_File meets a CR (Ctrl-M) it cannot know if this CR manifests
> the end of the current line or both the line end and the file end.

I understand. But then I consider the specs to be broken, see below. :-)

> The rules of thumb I suppose I and many other Ada programmers are using:
> 
> 1. Never ever use End_Of_File with text files;

This is broken. For me, End_Of_File is a concept that is completely 
orthogonal to what the file contains and how it is interpreted.
It is true that it is defined in Text_IO and therefore it might be a 
hint that actually EOF is somehow entangled with interpretation of text 
markers, but that's not what I would expect.

> 2. If you yet use End_Of_File then do it for *each* character of the file;

I don't see how it might solve this problem - End_Of_File would block 
after first <CR> anyway.

> 3. As Adam has suggested, End_Error exception is the right design;

I don't find it to be "right". For me, exception is something that is 
unexpected. An error, usually. With files, EOF happens - on average - 
almost once per file and it is something that I expect. There is nothing 
unusual in the fact that there is no more data in a file, *unless* in 
the given environment we really want to work with conceptually infinite 
data sources. But this is an exception (no pun intended) and is rather 
domain-specific, so should not be imposed by the general-purpose library.

EOF might be an error if, for example, with some known file format the 
parser expected some more data and there isn't any (like with the XML 
file which was truncated somewhere in the middle). *That* would be the 
reason to raise an exception, but then it's the business of the parser, 
not IO library. The library should not interfere with my interpretation 
of what I want to see in the file.

> 4. End_Error is not only cleaner and correct, but also more efficient.

It's not cleaner for me (see above), it is very likely correct (in the 
sense that the real solution is broken) and I don't see on what basis it 
is expected to be more efficient. :-)

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



  parent reply	other threads:[~2006-12-07  8:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06 14:25 Get_Line problem (GNAT bug?) Maciej Sobczak
2006-12-06 18:06 ` Adam Beneschan
2006-12-06 20:34 ` Gautier
2006-12-06 21:47 ` Dmitry A. Kazakov
2006-12-06 23:40   ` Adam Beneschan
2006-12-07  0:02     ` Björn Persson
2006-12-07  1:09       ` Adam Beneschan
2006-12-07  1:28         ` Björn Persson
2006-12-07  5:00         ` Jeffrey R. Carter
2006-12-07  8:26   ` Maciej Sobczak [this message]
2006-12-07  9:21     ` Jean-Pierre Rosen
2006-12-07 13:35       ` Ludovic Brenta
2006-12-07 22:23       ` Robert A Duff
2006-12-07 10:22     ` Dmitry A. Kazakov
2006-12-07 14:51       ` Maciej Sobczak
2006-12-07 16:29         ` Dmitry A. Kazakov
2006-12-08  8:22           ` Maciej Sobczak
2006-12-07 22:50       ` Robert A Duff
2006-12-08  0:13         ` Randy Brukardt
2006-12-08  4:04         ` Larry Kilgallen
2006-12-08  9:11         ` Dmitry A. Kazakov
2006-12-07  9:14   ` Jean-Pierre Rosen
2006-12-07  3:34 ` Steve
2006-12-07 17:42   ` Adam Beneschan
2006-12-07 22:35     ` Robert A Duff
replies disabled

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