comp.lang.ada
 help / color / mirror / Atom feed
* Text_IO for other standard types
@ 1998-01-09  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  1998-01-10  0:00 ` Nick Roberts
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1998-01-09  0:00 UTC (permalink / raw)



    So we have a standard type Integer and a corresponding package
    Ada.Integer_Text_IO. We have a standard type Float and a
    corresponding package Ada.Float_Text_IO. We have a standard type
    Boolean but no corresponding package Ada.Boolean_Text_IO? Or for
    that matter, the standard type Duration and no
    Ada.Duration_Text_IO.

    Oh sure, I can make my own declarations for these things and its
    pretty trivial. But it seems like it would be good to have all
    this stuff in one place - under the parent package Ada. (I don't
    believe it is legal for the end user to extend the package Ada.
    GNAT chokes on attempts to do so...) Would it be a bad idea to
    require a Ada.xxx_Text_IO package for any predefined elementary
    type xxx? I think it would make life easier and would simplify
    things for a student just starting out learning the language.

    And a related matter: Would it be difficult to implement an
    attribute 'Image for composite types? (At least arrays and records
    - pretty hard to figure out what this would mean for tasks and
    protected types.) The idea being if you want to implement some
    debug code or error handling code in which you want to output a
    message like: "Found a faulty input record: xxxxx" getting an
    ascii image for quick&dirty error checking would be pretty handy.
    Handy without dramatically altering the language or imposing undue
    burden on the compiler.

    And while we're at it, would there be some food value in requiring
    a few extra predefined types? I'm thinking of predefined Modular
    types similar to predefined Integer types and possibly some
    convenient Decimal Fixed Point types (most commonly used for
    money, I suppose).

    My reasoning for having these and their corresponding predefined
    I/O instantiations is that it would make the language easier to
    teach. Generics and even to some extent type declarations
    themselves can be inaccessible to the beginning programmer or a
    programmer familiar only with more primitive languages. Having
    predefined types for modular numbers would enable one to teach or
    discuss modular math & build simple programs to illustrate this
    without having to delve into the heavier concepts of type
    definition or generic instantiation.

    It doesn't sound to me like this would be a difficult extension to
    Ada and the only potential problem I would anticipate would be the
    possibility of collisions with existing name usage. Any thoughts
    on this subject? Good idea? Bad idea? Hmmmm?

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-95, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
=============================================================================
    "I filled out an application that said, 'In Case Of Emergency
    Notify'. I wrote 'Doctor'... What's my mother going to do?"
        --  Steven Wright
=============================================================================




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Text_IO for other standard types
@ 1998-01-12  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  0 siblings, 0 replies; 30+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1998-01-12  0:00 UTC (permalink / raw)



"Tarjei T. Jensen" <tarjei@ONLINE.NO> writes:
>Oh Horror! With these changes one could write a portable text editor in
>Ada without any host specific code. Horrors of horrors; we would be able
>to turn off input buffering and get access to each character as they are
>typed. Transparantly.
>
    An admirable goal. I'm not sure that the facilities aren't already
    available in Text_IO to write a transparent text editor (Please
    make it look like TPU!) but it may be lack of consistent
    implementation that kills you. You can do cursor motion now by
    outputting escape sequences - except that you are then dependent
    on some specific terminal standard (VT100, usually). There is a
    "Get_Immediate" call which will let you read a keystroke at a
    time, but my experience is that it's implementation is a little
    inconsistent/buggy/slow. (Does it require echoing of the
    character? Shouldn't it not require a CR before reading the
    keystroke? What about "special" keys, like F-keys, arrows, ctrl,
    alt, etc?) Again, your code is likely to get hung up on a specific
    keyboard standard as well.
>
>It would be very nice to have a stream base standard library. I assume
>it would be easy to connect any stream to any sort of I/O (serial,
>socket, text files, etc).
>
    Don't forget that there is, in fact support for streams and
    Stream_IO, the goal of which was to give you exactly the ability
    you are talking about. Of course there are always limitations on
    this sort of thing because it becomes very hardware/os dependent.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-95, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
=============================================================================
    "I filled out an application that said, 'In Case Of Emergency
    Notify'. I wrote 'Doctor'... What's my mother going to do?"
        --  Steven Wright
=============================================================================




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Text_IO for other standard types
@ 1998-01-15  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  1998-01-15  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1998-01-15  0:00 UTC (permalink / raw)



Jean-Pierre Rosen <rosen.adalog@WANADOO.FR> writes:
>NO, NO, NO, NEVER.
>One of the most important things in Ada teaching is to train people to
>design types according to the problem domain, and forget about predefined
>types. Forcing people to forget about Integer is in my experience one of the
>most difficult things.
>OTOH, teaching a total newcomer about type definitions, and about the fact
>that you cannot add apples and oranges is easy, easier than to an
>experienced programmer.
>
>More predefined types would be a help only if you teach Ada the same way
>that you teach other languages, and (IMHO) that's the last thing to do.
>
    I afraid I would have to respectfully disagree for a couple of
    different reasons.

    1) You already have *some* predefined types which pretty much get
    used the same way that predefined types in other languages are
    used. I need to get some relatively simple job done with no great
    concern for portability, etc., so I declare something to be of
    standard type Float or Integer. So what's wrong with a predefined
    Modular type or two which correspond in size to the predefined
    Integer types?

    2) While I would agree that the concept of data types and specific
    types for specific purposes (apples & oranges, as you say) is, in
    general, A Good Idea, there is such a thing as taking something
    too far. Not all programs are million line behemoths which will be
    maintained for dozens of years. Some are quite simple or may be
    just a training exercise where the concept might be to show how to
    build code to solve some equation where having to stop to explain
    the whole business of data type definitions might only distract
    you from the problem at hand.

    3) Not all students are CS majors who need to be steeped in the
    theoretical culture because they will be designing the future. In
    my particular case here at Pratt, I was busy trying to get a bunch
    of mechanical & electrical engineers up to some passing familiarity
    with Ada so that when they saw it they would have some
    understanding of it. These engineers have had some moderate level
    of exposure to programming with FORTRAN or Basic and might need to
    occasionally hack together a few lines of code to execute some
    control module or some other light duty job that must be done in
    an Ada environment. I need to communicate to these engineers that
    anything they can do in FORTRAN is just as easy and just as simple
    in Ada. These guys are just barely accepting of the notion that
    they should have to declare a variable before they use it. Forcing
    them to define the type in the interest of theoretical purity is
    only going to frustrate them more.

    (And, P.S.: Try explaining generic instantiation to a room full of
    non-programming engineers just so you can do simple I/O exercises
    with them and see how difficult this is! They generally instantly
    hate Text_IO because it isn't as simple as what they are used to
    and they really can't cope with generic instantiations of
    Float_IO, etc. The instantaneous reaction is: "All I wanted was a
    simple little program to compute 'Y := M * X + B" and print the
    result. Why do I need all this junk getting in my way?!?!?!" You
    don't win if you turn them off from wanting to have anything to do
    with the language.)

    4) Even with someone who is going to be a CS major, there is still
    a point where they are just starting out and getting them
    comfortable with the notion of a "variable" as a simple box in
    which to keep data, predefined types are very useful. Getting them
    familiar with Modular or Decimal arithmetic without involving type
    definitions can also be helpful because you are free to talk about
    how modular math works and not confuse things with how type
    definitions work or why you need them.

    So I guess that while I can agree with your opinion about type
    definitions being a very important concept, I'd have to disagree
    that every kind of student or every kind of application should be
    forced into doing this right from the get-go. Hence, this is why I
    would like to see more predefined types and predefined
    instantiations of the I/O routines. It's not hard to implement,
    other languages provide it, it isn't inconsistent with what has
    gone before and there are legitimate uses for it.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-95, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
=============================================================================
    "I filled out an application that said, 'In Case Of Emergency
    Notify'. I wrote 'Doctor'... What's my mother going to do?"
        --  Steven Wright
=============================================================================




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Text_IO for other standard types
@ 1998-01-19  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  0 siblings, 0 replies; 30+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1998-01-19  0:00 UTC (permalink / raw)



Jean-Pierre Rosen <rosen.adalog@WANADOO.FR> writes:
>I would respectfully continue to agree with myself :-).
>I think this discussion rises from a much deeper issue. From what you wrote,
>it appears that you consider predefined types as the "normal" types, and
>that user defined types are just an extra burden (or luxury) which i only
>cost effective for high security, long-lived, etc. projects. I do not share
>that view.
>
    Well, I'm not sure that's where I was heading. I agree that user
    defined types for a wide range of situations makes sense. In most
    situations where software is beyond trivial or throw-away or
    purely illustrative, it pays to explicitly define the required
    accuracy, range, etc. and to avoid mixing things that shouldn't be
    mixed. (Although I've seen this taken to extremes: "type
    Miles_Type... type Hours_Type..." And why imply that you don't
    want to compute Miles/Hour?)

    What I'm saying is that the predefined types do in fact have
    legitimate use - especially when trying to teach raw beginners. If
    they had no legitimate use, then I'd have to presume you would
    argue that Ada should eliminate the types Integer, Float, etc. and
    all programs everywhere should be required to define every data
    type they require. This of course would only end up creating the
    situation where every programmer would have a package defined
    called "package My_Standard is..." that they would always with/use
    and circumvent the intent. I've seen exactly this done in
    beginning-student-level Ada books where the author will develop
    something like "package Easy_Text_IO is" and provide
    instantiations, etc. in order to avoid having to talk about the
    complex issues until after the students have gotten past the
    simplest stuff.
>
>To me, data design is an important part of any design, like algorithmic
>design. Any type you use has constraints, and you should choose a data type
>that matches the requirements. Note that you *may* choose a predefined type,
>provided it's a design decision, if your requirements are:
>  - No big constraints on range (or accuracy for floating-point types)
>  - You are actually happy that the type changes depending on how powerful
>the machine is (big ranges on big machines, small ranges on small machines)
>  - You want your type to match closely the hardware (for efficiency or
>interfacing reasons).
>Note that the types defined in System.Interfaces might be a better match
>than the predefined types in this case.
>
    Yeah. Sure. I agree here. Except that not everything needs to be
    "designed". Occasionally (and I'd think rather rarely) things can
    be organically grown. I've often hacked tiny pieces of code where
    the whole intent was simply to build a driver to test something
    else or to check out how some specific language feature actually
    worked, etc. The code simply needs to be built quickly, executed
    and then discarded. Here, predefined types are handy. As they
    might be in some other cases - including educational settings.

    I think you meant to type "Interfaces" - not "System.Interfaces"
    since the scope is Standard. Yes, you get some useful predefined
    types there - but I still think there ought to be a few more
    "intrinsic" types (scope Standard, so that you don't have to do a
    with/use and needn't explain it to the beginner) and corresponding
    pre-instantiations of the appropriate Text_IO packages. It's a
    convenience feature like power windows on a car: You don't really
    need it, eventually they will break down, but in the mean time
    they keep the kids amused.

>>
>>    (And, P.S.: Try explaining generic instantiation to a room full of
>>    non-programming engineers just so you can do simple I/O exercises
>>    with them and see how difficult this is!
>It's not. Just give it as a "cooking recipe". The first day, I explain that
>to get IO's on type Counter, they have to use the magic formula:
>   package Counter_IO is new Integer_IO (Counter);
>and that they will later discover why (I don't even tell it's a generic
>instanciation). People accept it without problems.
>
    Been there. Done that. Got the T-Shirt. The engineers are seldom
    happy with "Don't try to understand it - just put this into the
    code and everything will be O.K." Audiences can vary considerably
    in what they will accept without question.

    I guess my point is that while you can't argue that Ada lacks
    enough features to program anything you want, a case can be made
    that some "convenience" features might make it a little more "user
    friendly" in some domains.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-95, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
=============================================================================
    "A verbal contract isn't worth the paper it's written on."
        --  Samuel Goldwyn
=============================================================================




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Text_IO for other standard types
@ 1998-01-20  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  1998-01-21  0:00 ` Jean-Pierre Rosen
  0 siblings, 1 reply; 30+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1998-01-20  0:00 UTC (permalink / raw)



Robert Dewar <dewar@MERV.CS.NYU.EDU> writes:
>I strongly dislike the magic cooking recipe approach. Yes, you can get
>students to accept it, but in my opinion damage is done since you
>compromise the critical principle that people should understand what
>they are doing.
>
    When the students in question are a) engineers and/or b) have
    experience with some other language (usually Fortran or Basic, in
    my venue) they typically won't sit still for "just use this and
    don't question it." Hence you look for ways of avoiding discussing
    generic instantiation until you've gotten them comfortable with
    the basics.

>Fortunately, there is a perfectly comfortable way to deal with this, which
>is to use the Image attribute, so people can write
>
>        My_Type'Image (val)
>
>Sure, you don't get nice formatting that way, but you can leave nice
>formatting for later.

    I've used this approach for the really introductory part of my
    course. You don't have to explain anything more serious than "with
    Text_IO/use Test_IO" and the associated Get_Line/Put_Line calls.
    It seems to be acceptable and you can show your garden variety
    engineer how to code up a little program to compute Y = M * X + B
    and it is only slightly more complicated than a Fortran
    equivalent. Maybe less so since you've got to deal with Fortran's
    I/O and that isn't a whole lot simpler than Get/Put with 'Image
    and 'Value. In any case the attributes are a big help in getting
    the students familiar with the basics.

>
>Note that the extension of Image to cover floating-point types is a nice
>improvement for this style of teaching.
>
    Yeah Verrily and Forsooth! I am eternally grateful for getting the
    'Image attribute on floating-point types. I'd like to see it
    available for just about any type but I have no notion as to how
    tough it would be to implement for compound types. (This would be
    useful for quick&dirty data dumps when debugging or producing
    throwaway hacks)

>This is certainly not a big deal, but I see no reason for introducing
>magic cookbook formulae when it is unnecessary.
>
    I like using the attributes to get around cookbook rituals, but I
    still have a problem when I eventually have to get to explaining
    Text_IO. The usual reaction is that Text_IO is painful. (I won't
    argue technical merit - that's just the standard issue response:
    "Why does this have to hurt so bad?") What I would *like* to do is
    be able to explain Text_IO without having to simultaneously
    explain generic instantiation. So if you had a useful set of
    predefined types and predefined instantiations of the generic I/O
    packages for all the predefined types and this was standard Ada
    (to avoid "this only works in my class because I gave you some
    code") it would be a lot easier to explain. I could approach it
    from the standpoint of: with/use the appropriate packages for the data
    types in question and you will get the following I/O procedures
    available...

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-95, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
=============================================================================
    "A verbal contract isn't worth the paper it's written on."
        --  Samuel Goldwyn
=============================================================================




^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~1998-01-21  0:00 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-09  0:00 Text_IO for other standard types Marin David Condic, 561.796.8997, M/S 731-96
1998-01-10  0:00 ` Nick Roberts
1998-01-10  0:00 ` Tarjei T. Jensen
1998-01-10  0:00   ` Robert Dewar
1998-01-11  0:00     ` Tarjei T. Jensen
1998-01-11  0:00       ` Robert Dewar
1998-01-12  0:00         ` Tarjei T. Jensen
1998-01-11  0:00       ` Robert Dewar
1998-01-11  0:00 ` Jean-Pierre Rosen
1998-01-14  0:00   ` Dale Stanbrough
1998-01-14  0:00     ` Robert Dewar
1998-01-14  0:00       ` Tarjei T. Jensen
1998-01-14  0:00         ` Robert Dewar
1998-01-15  0:00           ` Speeding up Text_IO Nick Roberts
1998-01-16  0:00             ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1998-01-12  0:00 Text_IO for other standard types Marin David Condic, 561.796.8997, M/S 731-96
1998-01-15  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1998-01-15  0:00 ` Robert Dewar
1998-01-15  0:00 ` Robert Dewar
1998-01-16  0:00   ` Nick Roberts
1998-01-16  0:00     ` Robert Dewar
1998-01-17  0:00       ` Geert Bosch
1998-01-17  0:00         ` Robert Dewar
1998-01-15  0:00 ` Nick Roberts
1998-01-17  0:00 ` Jean-Pierre Rosen
1998-01-17  0:00   ` Robert Dewar
1998-01-18  0:00     ` Michael F Brenner
1998-01-19  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1998-01-20  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1998-01-21  0:00 ` Jean-Pierre Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox