I often use TEXT_IO in the code examples I publish. This should not be considered an endorsement of TEXT_IO. The fact is, I don't like TEXT_IO very much. I use it because all Ada programmers are familiar with it. If I used SCROLL_TERMINAL or FORM_TERMINAL, the unusual user interface would distract readers from the point of the example.
The second problem with TEXT_IO is that it is heavily
dependent upon the host operating system. That means it
works differently on different computers, which makes it
difficult to move programs from one computer to another. For
example, a program containing the line
TEXT_IO.put_line(OUTPUT_FILE,"Some Text"); may write
" You get some nastier surprises when you instantiate
INTEGER_IO for integers and then call get(X); to read the
integer X. Suppose while entering X the user types the wrong
character and uses the rub out key to delete it. Some
operating system calls will respond to the editing command
and pass the corrected number X to INTEGER_IO for
processing. Other operating system calls will just leave the
rub out character in the middle of the string of digits.
INTEGER_IO will recognize that rub out is not a decimal
digit and raise DATA_ERROR, which at best will prompt the
user to enter the number again.
Even if the user doesn't make a typing error, there are
still problems. INTEGER_IO.get(X) will read all the
characters up to, but not including, the end of line marker.
These characters will be correctly converted to the number
X, but the input buffer pointer will be sitting just in
front of the end of the line marker. If you then call
get_line(TEXT,LENGTH), it will return a null string. You
have to remember to write get(X); skip_line; every time you
get an integer.
Since input data editing may or may not be done by the
operating system called by the get procedure, you never can
tell if CTRL-X will erase a whole line, or if backspace will
be the same as delete. These things all combine to frustrate
the user and make Ada appear to be a user-hostile language.
I got fed up with TEXT_IO in a hurry, and wrote a set
of replacement user interfaces. These packages are called
VIRTUAL_TERMINAL, SCROLL_TERMINAL, and FORM_TERMINAL. They
don't have a lot of state-of-the-art bells and whistles
(like graphics and pop-up windows) because they have to run
on "glass teletype" terminals, but they do provide a
portable, consistent, friendly user interface.
Contents | Next ...