From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,75c440b4b7ed5f91 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Real Time IO routines -- answering Simon Wright part 1 Reply-To: anon@anon.org (anon) References: <1193410739.367181.96050@50g2000hsm.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Mon, 29 Oct 2007 19:28:21 GMT NNTP-Posting-Host: 12.64.222.8 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1193686101 12.64.222.8 (Mon, 29 Oct 2007 19:28:21 GMT) NNTP-Posting-Date: Mon, 29 Oct 2007 19:28:21 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:2622 Date: 2007-10-29T19:28:21+00:00 List-Id: -- 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 , Simon Wright writes: >anon@anon.org (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?