comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Subject: Re: Text_IO, was: Re: Something I don't understand
Date: Mon, 17 Feb 2014 12:52:21 +0000 (UTC)
Date: 2014-02-17T12:52:21+00:00	[thread overview]
Message-ID: <ldt0m5$2ad$1@dont-email.me> (raw)
In-Reply-To: wcca9drdoc3.fsf@shell01.TheWorld.com

On 2014-02-16, Robert A Duff <bobduff@shell01.TheWorld.com> wrote:
> 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.
>

Agreed, but it should be a two-way thing.

There should be both External_To_Internal and Internal_To_External
support to convert between the external (human readable) format and
the internal format. You would also need to specify a format when
going from internal to external format so the output would fit in
the requested field width and obey the requested attributes (for
example, number of decimal places).

> 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".
>

While the current input routines need replacing, I don't agree with the
Ada RTL trying to work out what the input format is and pass a token
type back to the program. The problem is that unless you are careful,
you can end up with a Excel type solution in which it works most of
the time but fails when it thinks it knows better than you do what
you entered.

For example, consider the input "123,456".

Is the user entering a array of two numbers ?

Is the user entering one number but with a thousands seperator ?

Is the user in mainland Europe and hence is really entering "123.456" ?

Should this input be treated as a string (because it has a comma in it)
or should the Ada RTL impose it's idea of a number and convert the
input into some standard format even though that may not look anything
like what the user meant ?

What happens when the final destination is a range limited data type ?
You either have to still do the checking manually or take a exception
if the input value is outside of the range of the data type.

> 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.
>

_Totally_ agree with this. It would also be nice if one could write
something like this (pseudo Fortran style to get the idea across):
"5(I4,2X,F10.4,2X)" so you could specify the layout for 5 columns worth
(in this example) of data cleanly.

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

Yes, but you may need two methods. One for binary (unchanged) input and
one for text input with end of line conversions.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


  reply	other threads:[~2014-02-17 12:52 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
2014-02-17 12:52             ` Simon Clubley [this message]
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