comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Text_IO, was: Re: Something I don't understand
Date: Sun, 16 Feb 2014 11:17:16 -0500
Date: 2014-02-16T11:17:16-05:00	[thread overview]
Message-ID: <wcca9drdoc3.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: ldpv63$vc0$1@dont-email.me

Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> writes:

> On 2014-02-15, Robert A Duff <bobduff@shell01.TheWorld.com> wrote:
>>
>> FWIW, Text_IO is a poor design, and I don't blame you for having
>> trouble with it!
>
> I'm always interested in learning how people would do things differently
> if they were given a second chance.
>
> So, what do you dislike about Text_IO and what design changes would you
> make if given a second chance ?

I/O should be separated from processing.  In this case, the "processing"
I'm talking about is formatting and parsing of data (e.g. turning
an integer into a human-readable sequence of characters).  See how
it's done in Java.

Formatting for type T belongs with type T, not in Text_IO.

Input should be separate from output.  Put(Stream, X), where X is an
integer makes sense, because we know X is an integer.  Get(X)
makes no sense, because we have no idea what the user is going
to type.  For text input, you need "read the next token, and tell
me what it is", not "read an integer token, and blow up if the
user typed something else".

A simplified and type-safe version of C's printf style
(template-based) formatting would be more readable than
concatenating a bunch of strings together to print messages,
and MUCH better than using a series of Put calls to print
a single message.

I/O should be task safe, at least for standard output and friends.

There are various ways operating systems have chosen to represent text
files: lines separated by a single character, lines separated by two
characters (CR/LF), record oriented.  Obviously, the language design
needs to pick one of those models, and the implementation needs to map
that model onto whatever the OS does.  Any model will work, but Ada
chose the least convenient one.

Path names (file names with directory names and so on) should be
represented using an appropriate type, with structure, properly
interoperating with Ada.Directories.  String is the wrong type for that.
See how it's done in Common Lisp, quite portably.

The Get_Line procedure invites people to write broken programs
with arbitrary annoying line-length limitations.  However long
you make that String, it will be either too short or too long,
and most likely both.  The Get_Line function is better.

There should be a convenient way to read an entire file into
a String.  Similar for writing.

String should be a private data type with appropriate operations,
representing full Unicode, probably represented in UTF-8.
But we can't blame the designers of Ada 83 for choosing 7-bit
ASCII.  Even that was a bold move, at a time when most languages
didn't even define a standard character set, leaving it up to
the operating system.

There should be a standard way to represent multi-line text
in a String.

There is no convenient way to open a file in append mode,
creating it (empty) if it doesn't exist, atomically.

Calling Create followed by Close, with no intervening output,
does not create an empty file.  That's broken.

The line-counting business is largely useless, and somewhat confusing.

The page-handling is largely pointless, and gets in the way even
when you don't care about pages.

Finalization (which didn't exist in Ada 83) should be used to
automatically close files.

Open should be a build-in-place function (which didn't exist in Ada 83),
instead of a procedure.

> In a modified Ada, do you still see a role for Text_IO as it stands
> (with additional I/O package(s) implementing your desired changes) or do
> you think Text_IO should be outright replaced ?

You mean if compatibility were not a concern?  Yeah, the only reason
to keep Text_IO as it is is for compatibility.  In a from-scratch
language design, I'd do it rather differently.

- Bob

  parent reply	other threads:[~2014-02-16 16:17 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 23:57 Something I don't understand Laurent
2014-02-14  0:18 ` adambeneschan
2014-02-14  7:05   ` Charles H. Sampson
2014-02-15 15:27   ` Laurent
2014-02-15 19:10     ` Laurent
2014-02-15 20:05       ` Niklas Holsti
2014-02-15 21:16         ` Laurent
2014-02-15 21:40       ` Jeffrey Carter
2014-02-16  1:39       ` Robert A Duff
2014-02-16  9:08         ` Text_IO, was: " Simon Clubley
2014-02-16  9:43           ` Dmitry A. Kazakov
2014-02-16 16:57             ` Dennis Lee Bieber
2014-02-16 16:17           ` Robert A Duff [this message]
2014-02-17 12:52             ` Simon Clubley
2014-02-17 15:32               ` G.B.
2014-02-17 15:35                 ` G.B.
2014-02-17 17:34                 ` Mike H
2014-02-17 16:59               ` Niklas Holsti
2014-02-17 17:17                 ` Dmitry A. Kazakov
2014-02-17 17:42                   ` Niklas Holsti
2014-02-17 19:55                     ` Dmitry A. Kazakov
2014-02-18  7:14                       ` Niklas Holsti
2014-02-18  8:40                         ` Dmitry A. Kazakov
2014-02-18  9:00                           ` Niklas Holsti
2014-02-18  9:31                             ` Dmitry A. Kazakov
2014-02-19  8:36                               ` Niklas Holsti
2014-02-19  9:40                                 ` Dmitry A. Kazakov
2014-02-19 13:20                                   ` Niklas Holsti
2014-02-19 14:13                                     ` Dmitry A. Kazakov
2014-02-19 15:37                                       ` Georg Bauhaus
2014-02-19 16:32                                         ` Laurent
2014-02-19 17:46                                           ` Simon Clubley
2014-02-20  2:39                                         ` Dennis Lee Bieber
2014-02-20 11:44                                           ` G.B.
2014-02-19 21:45                                       ` Niklas Holsti
2014-02-20  9:52                                         ` Dmitry A. Kazakov
2014-02-20 18:19                                           ` Niklas Holsti
2014-02-19 15:06                                     ` Robert A Duff
2014-02-19 17:03                                       ` Niklas Holsti
2014-02-19 22:30                                         ` Robert A Duff
2014-02-17 18:13                 ` Simon Clubley
2014-02-17 20:09                   ` Dmitry A. Kazakov
2014-02-18  7:50                     ` Georg Bauhaus
2014-02-18  8:28                       ` Dmitry A. Kazakov
2014-02-17 20:22                   ` Niklas Holsti
2014-02-18  0:50                     ` Simon Clubley
2014-02-18  6:56                       ` Niklas Holsti
2014-02-18  8:04                         ` Georg Bauhaus
2014-02-19 22:01                     ` Robert A Duff
2014-02-20  8:25                       ` Dmitry A. Kazakov
2014-02-20 15:54                         ` Robert A Duff
2014-02-20 17:54                           ` Dmitry A. Kazakov
2014-02-20 20:45                       ` Niklas Holsti
2014-02-19 21:52                   ` Robert A Duff
2014-02-20  0:50                     ` Simon Clubley
2014-02-19 21:46                 ` Robert A Duff
2014-02-20  0:09                   ` Jeffrey Carter
2014-02-20  1:09                     ` Simon Clubley
2014-02-20  7:06                       ` Niklas Holsti
2014-02-20 13:05                         ` Simon Clubley
2014-02-20 11:51                       ` G.B.
2014-02-20 12:53                         ` Simon Clubley
2014-02-21 11:50                       ` Brian Drummond
2014-02-23 21:37                         ` AdaMagica
2014-02-23 23:23                           ` Bill Findlay
2014-02-24  4:29                           ` AdaMagica
2014-02-24 12:22                           ` Brian Drummond
2014-02-24 19:03                             ` AdaMagica
2014-02-20 20:02                   ` Niklas Holsti
2014-02-19 21:15               ` Robert A Duff
2014-02-19 22:01                 ` Simon Clubley
2014-02-16 14:50         ` Mike H
2014-02-17 16:09         ` Laurent
2014-02-17 17:42           ` Mike H
2014-02-18  1:05             ` Dennis Lee Bieber
2014-02-17 22:31           ` Jeffrey Carter
2014-02-19 12:51             ` Laurent
replies disabled

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