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.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site spp1.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!trwrb!trwspp!spp2!spp1!colbert From: colbert@spp1.UUCP Newsgroups: net.lang.mod2,net.lang.ada Subject: Re: Is Modula-2 superior to Ada? Message-ID: <120@spp1.UUCP> Date: Thu, 15-Nov-84 12:56:56 EST Article-I.D.: spp1.120 Posted: Thu Nov 15 12:56:56 1984 Date-Received: Sat, 17-Nov-84 08:02:16 EST References: <12@cavell.UUCP> Distribution: net Organization: TRW, Redondo Beach CA Xref: sdcsvax net.lang.mod2:138 net.lang.ada:119 List-Id: > > Recently I started reading about Ada and I was surprised > to a great extent that Modula-2 outshines Ada with respect > to interface specification of program units. > > Things in Ada that I feel, are inferior to Modula-2 are: > > 1) You can not have anything else in the specification > part other than the ones you are exporting. > This can result in cumbersome specification. I assume you are referring to a Package Specification. If so the your perspective is backwards. Its not that "You can not have anything else in the specification part....", its that anything you put in the Visible part of a package specification is exported. If you need something in your specification that you don't want to export then put it in the private part of the Package Specification (You can put anything you want in the Private part of a Package Specification). If this solution is not satisfactory then you probably should evaluate whether you should have furthur modularization of some part of your package into 2 or more packges. > 2) Packages can not selectively IMPORT objects from other packages. > It is either ALL or NONE situation. This will have severe > impact on the readability of the source code. > > I feel that Modula-2's SELECTIVE import and export mechanisms > contribute to better PROGRAM READABILITY AND SCOPE > CONTROL than Ada's import and export mechanisms. > This can be accomplished in Ada by creating a package containing renames of those items that you wish to import. For example the following is a Simple I/O package that I provide to my class when they are first starting out so that they can write programs that have I/O (useful capability) without needing to know the gory details of Text_IO. with text_io; use text_io; package simple_io is package int_io is new integer_io (integer); use int_io; procedure put (c: character) renames put; procedure put (i: integer; width: in field:= default_width; base: in number_base := default_base) renames int_io.put; procedure put (s: string) renames put; procedure put_line (s: string) renames put_line; procedure get (c: out character) renames get; procedure get (i: out integer; width: in field := 0) renames int_io.get; procedure get (s: out string) renames get; procedure new_line (spacing: in positive_count := 1) renames new_line; data_error: exception renames text_io.data_error; end_error: exception renames text_io.end_error; end simple_io; A program that only wants to do this Simple I/O only needs to import this package. > 3) For private and Limited private types you have to give > the full representation of the types in the specification part itself. > This is really annoying. Even at the specification stage > you are forced to take a decision on the representation which > may not always be possible. Also, it is a good idea to > hide the representation in addition to making it inaccessible outside > the package. The specification part usually serves as > a good documentation feature and why give other programmers some > details which are totally unnecessary. > The full representation of a private or limited private type in the PRIVATE PART of a package is information required by a Ada compiler to fully support separate compilation. Ada allows a compilation to import a package or subprogram from the library whose declaration has been compiled but whose body has not been compiled (maybe not even written). In order to generate the proper code for a call to a subprogram thats a library unit or thats part of a package thats a library unit, the compiler needs to know the for representation of the private or limited private type. While a user can read the PRIVATE PART and see how the private or limited private type is implemented, the rules of Ada prevent him from making use of that knowledge in his program (at least in theory. A user may make assumption about the processing based on what he has read). If you need/want to hide totally the defintion of the private/limited type from the eyes of a user of that package, Ada provides a means. To accomplish this you must use incomplete & access types. Ada says that the full type declaration of an incomplete type that is declared in the private part of a package can be deferred to the body of the package. Therefore you can do the following: package demo is type private_type is private; . . . private type my_hidden_type; type private_type is access my_hidden_type; end; package body demo is type my_hidden_type is ....; -- full declaration end; While I have used or read Modula from what I've heard both Ada and Modula have individual features that are better than the others, but I haven't heard of anything that made one of them overwhelmingly supperior to the other. Ed Colbert Ada Technology Group TRW