Re: Real Time IO routines answering Simon Wright part 2



--
-- This is Part 2. A simpler version of an Ada purist type of
-- answer to the original thread poster question. Also ths
-- version should answer "Dmitry A. Kazakov" concerns about
-- types being defined in private. The RM does have its view on
-- this version.
--

--
-- Where did I get the information that IMAGE should be use for
-- debugging only? A few Ada conferences back in the early to
-- mid 1990's dealing with Ada programming and debugging
-- techniques. And is fully embrased by Adacore aka creaters of
-- GNAT.
--

--
-- z.adb
--
--
-- Compile with "-gnatwI" or you may receive Portable and Version
-- Warnings, for the sub package "ada.real_time.io" aka user-written
-- child of "ada.real_time". (GNAT)
--

with Ada.Real_Time ;
with Ada.Real_Time.IO ; -- programmer Ada extension package
with Ada.Text_IO ;

use Ada.Real_Time ;
use Ada.Text_IO ;


procedure z is

Time_Value : Time ;

begin

Time_Value := Clock ;

Put ( "Time := " ) ;
Ada.Real_Time.IO.Put ( Time_Value ) ;

New_Line ;

end z ;


--
-- a-retiio.ads
--
-- Package must be included with program source code, do to
-- the "non-Portable" nature of this code.
--
package Ada.Real_Time.IO is

--
-- Put: Uses the default Put routine. To keep this example
-- simple the routines uses the type default for
-- formatting
--
procedure Put ( Z : Time ) ;

end Ada.Real_Time.IO ;


--
-- a-retiio.adb => Ada Standard Extension Package.
--
pragma Style_Checks (OFF); -- not needed if you use GNAT style
-- requirements aka rules for spacing

--
-- Gnat will view this package as a "Language Defined Unit" even
-- though it is not in the Standard GNAT package list.
--
-- Package must be included with program source code, do to
-- the "non-Portable" nature of this code.
--

-- ------------------------------------------------------- --
-- An Ada Purist would have bypassed using a package --
-- routine and added a local routine for printing the --
-- "Time" value directly to a text file. That way they --
-- could reduce the code to the bare bones. --
-- ------------------------------------------------------- --
-- I used a generic package because it was faster and --
-- easier to generate the example of an extension to --
-- the Standard Ada packages. --
-- ------------------------------------------------------- --

with Ada.Text_IO ;

package body Ada.Real_Time.IO is

--
-- Time specification comes from the parent's code.
--
package D_IO is new Ada.Text_IO.Fixed_IO ( Time ) ;


--
-- Put: Uses the default Put routine. To keep this example
-- simple the routines uses the type default for
-- formatting
--
procedure Put ( Z : Time ) is

begin -- Put

D_IO.Put ( Z ) ;

end Put ;

end Ada.Real_Time.IO ;


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: How to exit an Ada program with (unix shell) error code?
    ... First, the RM (Ada 2005). ... Most packages allow a vendor to add to a package aka altering the ... compiler that are use to write modules or OS type of programs. ... If the main subprogram is a function the binder creates the binding ...
    (comp.lang.ada)
  • Re: Tutorial and guidelines: Coding standards (long message)
    ... >> Many languages already have well established coding standards. ... Since I have referenced an Ada style guide I will speak of the ... Ada way to make scope visible. ... An Ada package is added to the scope of a program ...
    (comp.programming)
  • Re: Tutorial and guidelines: Coding standards (long message)
    ... >> Many languages already have well established coding standards. ... Since I have referenced an Ada style guide I will speak of the ... Ada way to make scope visible. ... An Ada package is added to the scope of a program ...
    (comp.os.linux.development.apps)
  • Re: Tutorial and guidelines: Coding standards (long message)
    ... >> Many languages already have well established coding standards. ... Since I have referenced an Ada style guide I will speak of the ... Ada way to make scope visible. ... An Ada package is added to the scope of a program ...
    (comp.unix.programmer)
  • Re: Separate Compilation in Programming Languages
    ... And that is exactly analogous a change to an Ada package spec ... exactly the same as changing an Ada package spec. ... A dependent unit, when the specification ... If the public signatures do not change, ...
    (comp.lang.ada)