Re: Real Time IO routines -- answering Simon Wright part 1



-- This answer is in two parts! This part answers you question about
-- use of enumeration Boolean package and using the IMAGE attribute
-- versus using IO packages versus use user create routines.
--
-- Now, for Boolean it is kind of funny because there is only two
-- valid values (True and False). But it can illustrate some of
-- the reasons.
--
-- Basically, what's wrong with the IMAGE attribute?
--
-- Using IMAGE Attribute. Output formatted and style set by vendor
-- and the output format is not specified in Ada RM.
-- 1.For numeric data. No formatted output.
-- A) No data "Width" control for output.
-- B) No field formatting. Such as setting the "Fore",
-- "Aft" or "Exp" fields.
-- C) No base control.
-- D) No readability formatting. Such as adding "_" or commas
-- in numeric data printed output stream.
-- 2. For non-numeric, enumeration types, Upper-case string values
-- only.
-- 3. Can not be used for complete "Arrays" or "Records". Only
-- single elements of the "Record" or "Array" at a time.
--
-- Now with using standard IO packages like generic packages Text_IO
-- packages.
-- 1.For numeric data. Formatted Output
-- A) Full width control.
-- B) Full field formatting. Link setting the "Fore", "Aft" or
-- "Exp" values.
-- C) Ada Standard Base formatting control.
-- D) No readability formatting. Such as adding "_" or commas
-- in numeric data printed output stream.
-- 2. For non-numeric, enumeration types,
-- A) Set Lower or Upper case
-- B) Width spacing control.
-- 3. Limited printing of the complete fields of a "Record" or
-- "Arrays" using other IO packages like Sequential_IO. But
-- no formatting allowed. The output will be in a "Raw" and
-- even can be packed state.
--
-- The Ada purist way!
-- Internal programmer-create IO routines and packages.
-- 1.For numeric data. Full Formatted Output controls for
-- A) Width control.
-- B) Field control. Setting the "Fore", "Aft" or "Exp"
-- values.
-- C) Full Base formatting control. Even beyond Ada Standards
-- D) Readability formatting. IO algorithm can insert '_' or
-- commas in numeric data.
-- 2. For non-numeric, enumeration types, values printed the way
-- the programmer chooses.
-- 3. Full access to print parts or complete "Record" and "Array"
-- elements in any format and form that a programmer can create.
--
--

--
-- t.adb -- Test all three versions for Boolean type.
--
with Ada.Text_IO ;
use Ada.Text_IO ;

procedure t is
--
-- I/O package for Boolean type.
--
package B_IO is new Ada.Text_IO.Enumeration_IO ( Boolean ) ;


--
-- Put: Internal. Allows programmer to fully format the
-- output the way the programmer's wants. Could be
-- a routine in a programmer created package.
--
-- Plus this internal PUT routine is more efficient
-- than either the IMAGE or Package versions. Do to the
-- fact that the programmer can controller how the code
-- is generated by using "pragmas" and controlling the
-- optimization level. Also knows what type of code will
-- be generated.
--
-- Also, this routine reduces dead (unused) routines in
-- the partition file which reduces the amount of program
-- code loaded into memory during execution.
--
procedure Put ( V : Boolean ) is
begin -- Put
if V then
Put ( "Yes" ) ; -- altered version of TRUE
else
Put ( "No" ) ; -- altered version of FALSE
end if ;
end Put ;


Value : Boolean := False ;

begin

Put ( "Image Value := " ) ;
--
-- VENDOR Controlled
-- Output: Upper case only, No width control.
--
-- This statement besides the code generated by the call to
-- "Ada.Text_IO.Put ( string ) ;" routine. Will generated an
-- indeterminate number of cpu instructions (depend on the vendor).
-- And will include anywhere from 2 to 5 extra packages (again depend
-- on the vendor) which can have dead code and have an indeterminate
-- algorithm for generating the actual image. For the Boolean type it
-- could be a simple "if-then-else" routine, but since Boolean is an
-- enumeration type the algorithm could be more complex than that,
-- which could decrease the performance of the partition.
--
Put ( Boolean'Image ( Value ) ) ;
New_Line ;

--
-- Using a package. Programmer define Case and Width Controls.
--
-- In using a generic IO package, there are a number of
-- concerns. The first is the amount of dead code and memory
-- required to load this code. The second is will this IO
-- package require addition statements, such as "Open", "Close"
-- and etc. Also will it interfere with other screen IO
-- routines. The Plus, side is the formatting of the data. In
-- the case of a Boolean Type that is altering the case and
-- setting of spacing
--
Put ( "Package IO Value := " ) ;
B_IO.Put ( Value ) ; -- default to upper case.
New_Line ;
--
-- Define alternate width and case values for package version.
-- Will set field with to 6 spaces and out to lower case.
--
Value := True ;
Put ( "Package IO Value := " ) ;
B_IO.Put ( Item => Value, Width => 6, Set => Lower_Case ) ;
New_Line ;


--
-- Then there is the full control over data being displayed.
--
Put ( "IO Routine Value := " ) ;
T.Put ( Value ) ;
New_Line ;

end t ;

In <m2tzoc5iqw.fsf@xxxxxxx>, Simon Wright <simon.j.wright@xxxxxxx> writes:
anon@xxxxxxxx (anon) writes:

Ada Purist never and I mean NEVER uses IMAGE attribute, in the body of
a program. They create a package or sub-package that performs the IO
functions with the use of the IMAGE attribute.

IMAGE attribute is the last thing a programmer should use. to print a value.
It is normally use for DEBUGGING ONLY! A programmer should always create
a routine or better yet a package that uses an algorithm to prints the value
without the use of attributes.

Mostly programs that are created by newbees use IMAGE attribute.

I must be a newbie (NB spelling!) then.

Where on earth do you get this viewpoint from? Please say why it is
better to instantiate enumeration IO for Boolean rather than to use
Boolean'Image?

I suppose you would ban people from using Integer_IO, too. Good grief.

And as for my code! It answer the person question without adding extra
code that might confuse him. Plus, the "Ada.Real_Time" package uses:

type Time is new Duration;

which is in private section. So I know what to convert the value to.

This is true so long as you and the person to whom you are giving
advice are both using *this version of* *GNAT*. Whatever makes you
suppose that the code you see in that private part will be the same
for any other compiler? or for any other version of GNAT? or for GNAT
for a different platform?

.



Relevant Pages

  • Re: Why most run Microsoft, not RedHat
    ... I tried to give some examples of ease of use vs manual control. ... What happens when the package manager is compromised? ... But chattr works only as root and you can only run rpm -as root ... even if some files have the immutable flag set. ...
    (Fedora)
  • Re: [9fans] Help for home user discovering Plan 9
    ... The update/installation process in Ubuntu sucks. ... using BSD ports or Gentoo portage, you can fine tune things and have ... one can acquire a complete control over any common ... Linux distribution, can opt for tuning and, tweaking around any package ...
    (comp.os.plan9)
  • Re: Performance and Parallelism in SSIS
    ... In the system design docs, I had documented a Control table on similar ... 2)In the Package: Initiate two DateTime variables, ...
    (microsoft.public.sqlserver.dts)
  • Re: CFAN (was: A small wildcard matching algorithm)
    ... meant by package is, e.g., a zip file containing the individual files ... Concerning version control, ... They have a Virtual File System that lets them put a bunch of stuff ... Are there important standardisation issues? ...
    (comp.lang.forth)
  • Re: CFAN (was: A small wildcard matching algorithm)
    ... Anton Ertl wrote: ... I don't know what you understand by package and component. ... Concerning version control, ... submission, or even per new submitter, with some other interventions ...
    (comp.lang.forth)