comp.lang.ada
 help / color / mirror / Atom feed
* "Subtract C, add Ada"
@ 1995-01-23  8:49 R.A.L Williams
  1995-01-25 23:18 ` Charles H. Sampson
  0 siblings, 1 reply; 85+ messages in thread
From: R.A.L Williams @ 1995-01-23  8:49 UTC (permalink / raw)


In article <3feevh$615@gnat.cs.nyu.edu> Robert Dewar wrote:
: "Dennis Ritchie once said in an interview that there is *nothing* in the
:  C language that keeps compiler writers from issuing stringent warnings
:  about stuff that most Ada people take for granted."

: Dennis may have said this, but it is misleading. Yes, there is stuff that
: Ada people take for granted that C compilers could (and in some compilers
: *do*) check for.

: But there are lots of things that Ada people take for granted that cannot
: be checked in C, there just isn't enough information. C has no separation
: of scalar types, no ranges on scalar types, and the ubquitous use of
: pointers, and their similarity to arrays means that sophisticated aliasing
: analysis is required to even approximate the type checking that occurs
: in the context of access types in Ada. There are many other examples.

Ranges - no, but my Microsoft C compiler certainly *does* warn me when I
 - mix signed and unsigned integers (of course, Ada83 doesn't have unsigned)
 - assign the result of 'long' expressions to shorts or chars etc.
 - perform 'unchecked conversion' between integers and pointers

There are probably other things as well, but these are certainly some of the
gripes it comes up with when I try to port typical UNIX C code to WIN32.

I agree with Dennis Ritchie, If I go to the trouble of typedef'ing a new
type, there is nothing to stop the compiler from griping at me if I
do something inappropriate with it. This is mainly a compiler issue, not
a language issue.

Bill Williams



^ permalink raw reply	[flat|nested] 85+ messages in thread
* "Subtract C, add Ada"
@ 1995-02-10 13:49 R.A.L Williams
  0 siblings, 0 replies; 85+ messages in thread
From: R.A.L Williams @ 1995-02-10 13:49 UTC (permalink / raw)


In article <3h1lfl$lr4@Starbase.NeoSoft.COM> Samuel Mize wrote:
: In article <3gsr0e$oin@miranda.gmrc.gecm.com>,
: R.A.L Williams <bill@valiant> wrote:
: >Never mind all that code, the main feature of the C code was that, at
: >the termination of the loop, the variable 'c' contained the character
: >which caused the loop to terminate. Are you suggesting a 'LastChar'
: >function as well. 

: In the Ada rewrite I provided, "at the termination of the loop, the
: variable 'c' contained the character which caused the loop to
: terminate."  However, it's contained in the package Files_Like_C.

Yes, I'm sorry. You're absolutely write. In that case, I see nothing
wrong with the code, but, are you suggesting that that much code is
more 'readable' than the C equivalent. OK, this is a relatively trivial
example. Anyone who can't understand your code probably shouldn't be
reading it anyway! Nonetheless the point remains that Ada code is more
verbose than C, and this can IMO obscure, rather than enhance, readability.

: We're now discussing a difference in design philosophy in standard
: I/O packages, not a difference in the languages.  My point was that
: you could implement either I/O design philosophy in Ada.  Mr. Ichbia
: et al picked a different design for their standard I/O package,
: named Text_Io, so you will have to code your own replacement if you
: want to use C-style I/O.  Just as if you wanted to use C-style I/O
: in PL/I or Fortran.  You *can* do this.

I wasn't particularly concerned in my original postings about specific
features such as I/O libraries. I worry more about the structure of Ada
giving me more 'hoops to jump through' to the extent that code is
*less* readable. Having been involved in a fair number of code
walkthroughs recently, 'reviewer fatigue' is an important issue.

: Sam Mize - smize@starbase.neosoft.com

Bill Williams





^ permalink raw reply	[flat|nested] 85+ messages in thread
[parent not found: <3gsr0e$oin@miranda.gmrc.gecm.com>]
* "Subtract C, add Ada"
@ 1995-01-31  9:34 R.A.L Williams
  1995-02-01 16:45 ` Charles H. Sampson
  0 siblings, 1 reply; 85+ messages in thread
From: R.A.L Williams @ 1995-01-31  9:34 UTC (permalink / raw)


In article <1995Jan23.154631.6702@sei.cmu.edu> you wrote:
: In article <3fo2ot$su2@miranda.gmrc.gecm.com> bill@valiant (R.A.L Williams) writes:

: I guess I'm about to show my ignorance of C, but I'm very confused
: bt this post.

: > 1. It allows your code to be more compact.

: >    NB DONT confuse compactness with poor layout! I find that, for example:
: >
: >       while ((c = getchar()) == ' ')
: >       {
: >          /* count spaces */
: >       }
: >
: >    is clearer than the 'expanded' alternative (to *me* :-).

: Nope, I find this totally unclear.  Who's counting?  Unless I've missed
: an invisible declaration, initialisation, and increment, the above
: code *doesn't* count spaces, it skips them.  And if that is its
: purpose, what's the point of the variable 'c'?  Why not just say

OK, I'm sorry, I didn't think I needed to spell things out in gratuitous
detail, so I just indicated the position and sort of code that might be
used by a comment. I haven't shown code that replaces spaces in an output
stream with text from the Koran either, sorry!

: Note also that if there are *no more* non space characters, the C code
: dies in an infinite loop, while the Ada code automatically does the
: right thing, namely raises the END_ERROR exception.

I'm afraid you *are* showing your ignorance of C. On each iteration of the
loop if the next input character is not a space (and this includes EOF)
then the loop terminates cleanly.

: >[example deleted]

: Again, I don't see it.  The Ada code makes it clear that *corresponding*
: elements of the array Q are being copied into P - though, of course,
: a real Ada programmer (TM) would have written just P := Q.  The C code
: doesn't make that clear - you're going to have to ferret out the
: initialisations of p and q to determine that.  And if you worry about
: the correctness of the copy - for instance, whether P and Q are the
: same size - that's surely going to be a lot easier to establish in Ada.

Again, a simplified example to illustrate a principle. The point is that
the less I have to move my eyes, or flip over pages, when reading/reviewing 
code, the more likely I am to understand it and find any bugs. You're
quite right, P := Q is an event more compact representation and I approve
(the Bill Williams official statement of approval!).

Bill Williams




^ permalink raw reply	[flat|nested] 85+ messages in thread
* "Subtract C, add Ada"
@ 1995-01-20 10:20 R.A.L Williams
  1995-01-20 13:22 ` Renaud HEBERT
                   ` (3 more replies)
  0 siblings, 4 replies; 85+ messages in thread
From: R.A.L Williams @ 1995-01-20 10:20 UTC (permalink / raw)



In article <3f5s92$3id@info.epfl.ch> you wrote:
: In article <3f4mbe$rud@cronkite.seas.gwu.edu>, dobrien@seas.gwu.edu (David O'Brien) writes:
: |> R.A.L Williams (bill@valiant) wrote:
: |> : My experience of writing software and running software projects in C
: |> : highlights four common low-level C errors:
: |> :   1. = instead of == and vice versa
: |> 
: |> I have to wonder.  What if C defined the logical equals operator to be
: |> "=" and the assignment operator to be ":=" just like Ada, Algol, Pascal,
: |> Modula-x, etc?  Would this error still exist???

: The problem is in the language definition, not in the choic of symbols.
: C is one of the rare language I use to allow having an assignment after 
: the if statement.  All other languages only allow for a boolean test.

: I never saw a good reason for allowing this.

I think there are three reasons:
 1. It allows your code to be more compact. Many people think this is
    a disadvantage, and so it is if the code will be read by comparative
    novices, but it can improve readability to C experts who are 
    expecting such tricks.

    NB DONT confuse compactness with poor layout! I find that, for example:

       while ((c = getchar()) == ' ')
       {
          /* count spaces */
       }

    is clearer than the 'expanded' alternative (to *me* :-).

 2. All expressions in C have a value. Conditional tests succeed on 
    non-zero and fail on zero. Therefore, to maintain orthogonality, 
    as far as possible, there is no reason to exclude an assignment 
    expression from a condition.
   
 3. Finally, I suspect, this can simplify the optimisation algorithms 
    in the compiler.

Personally, the lack of this sort of compactness in Ada, and things like
pre- and post-increment/decrement are one of my minor gripes about the
language. OK, its no big thing to write:

    P(I) := Q(I);
    I := I + 1;

instead of
 
    *p++ = *q++;

but I actually *do* find the C representation easier/better etc. (perhaps
I'm wierd?)

: -- 
: Laurent Gasser (gasser@dma.epfl.ch)
: Computers do not solve problems, they execute solutions.

: I know very few ideas worth dying for, none is worth killing.

Very true, but quite a few are worth a pint in the pub.

Bill Williams




^ permalink raw reply	[flat|nested] 85+ messages in thread
* "Subtract C, add Ada"
@ 1995-01-20  9:33 R.A.L Williams
  0 siblings, 0 replies; 85+ messages in thread
From: R.A.L Williams @ 1995-01-20  9:33 UTC (permalink / raw)



[Our news system broke down earlier this week so I don't know
 whether this message got out. If it did I apologise for the
 wasted bandwidth.

 Bill Williams]

Robert Dewar wrote..
> Bill comments that for his points 3. and 4.
> 
>   3. uninitialised pointer access
>   4. pointer references to local variables in defunct procedures
> 
> "The syntax of Ada .. does not really address 3. or 4."
> 
> Taking point 3, it is impossible to have an uninitialized pointer in Ada,
> all pointers are initialized to null, and any attempt to use a null pointer,
> i.e. to dereference it, will cause a constraint error. Seems like pretty
> complete protection to me.

Yes, you're right, Ada *guarantees* a run time crash, in C/C++ it's just very
likely. It's still not a compile time check so you're relying on the
quality of your run time environment to tie down where the problem
occurs. Of course, in embedded systems you don't want *any* exceptions,
no matter how cleanly you handle them! I'm not saying that we necessarily
want to go to a language which either doesn't allow pointers (yuck!) or
constrains their use to such an extent that compile time checks are
feasible; I was just trying to point out that using Ada is no substitute
for good engineering practice in design and coding.

> With regard to point 4, ther is no way to get pointer references to local
> variables in Ada 83 (except use of 'Address, and non-portable maybe-works,
> maybe-doesn't unchecked conversion of the address to an access type, which
> really doesn't count). Certainly students (and most other Ada programmers)
> should be forbidden from using such constructs (the use of 'Address, and
> indeed of unchecked conversion of addresses to access types is permissible
> in some situations, but taking the 'Address of locals in a subprogram is
> pretty dubious).

Again, you're right BUT, 'ADDRESS is something you need to do fairly
often when interfacing to foreign languages. Sorry, don't want to start a
religious argument about libraries etc. it's just a fact of life.

I agree whole heartedly about restricting the constructs used by 'novice'
programmers or those coding for `critical' environments.

> In Ada 95, it is indeed possible to take the 'Access of local variables,
> provided they are marked aliased, but the accessibility rules make it
> impossible to have dangling pointers. Dangling pointers can be created
> by the use of Unchecked_Access, but this is in the same category as
> Unchecked_Conversion, to be used with great care in rare cases.

I'm looking forward to trying out Ada95. Got GNAT 2.0 up and going on
a SPARC station that I have occasional access to. I'm really looking
forward to the HP700 port because that's what our local network is.

Thanks for the feedback.

Bill Williams




^ permalink raw reply	[flat|nested] 85+ messages in thread
[parent not found: <3fgphd$sc3@rational.rational.com>]
[parent not found: <3fdcoi$chn@miranda.gmrc.gecm.com>]
[parent not found: <3etund$hnr@miranda.gmrc.gecm.com>]
* "Subtract C, add Ada"
@ 1994-12-30 16:06 Mitch Gart
  1995-01-03 19:04 ` whiting_ms@corning.com (Matt Whiting)
                   ` (2 more replies)
  0 siblings, 3 replies; 85+ messages in thread
From: Mitch Gart @ 1994-12-30 16:06 UTC (permalink / raw)


In the Dec. 12 PC Week, next to the review of Alsys ActivAda, 
was this sidebar by Peter Coffee:


Subtract C, add Ada: Results multiply
-------------------------------------

Few managers can afford to do a software project several times,
using teams with similar experience but different programming
tools, to see if anything yields consistent improvements in speed
or quality of work.  At the State University of New York, Plattsburgh,
though, Professor John McCormick has assigned the same project to
each of his classes for about nine years, but switched languages
in mid-decade.

Working in teams of three or four, McCormick's real-time-programming
students must write 15,000 lines of code to control a system that 
would need about 150 switches to operate using hardware alone.  In the 
five years students used C, no team completed the project - even when
more than half of the code was provided.  With Ada, however, half of
the teams completed the project before any support code had even been
written.  With some support code now provided, three out of four teams
finish the project.

Specific factors in this improvement, according to McCormick, include
both syntax and semantics.  Ada leaves less room for single-keystroke
errors, such as the common C error of using = (assignment) instead of
== (comparison); its type-abstraction facilities reduce the need for
error-prone pointer manipulation; and its modular facilities improve
teams' coordination of effort.

This experience, McCormick notes, "has convinced all my faculty
colleagues to support teaching Ada in our beginning courses.  This
spring semester, the first studentw with Ada as their mother tongue
will enroll in my course.  I can only imagine what these teams will
accomplish".



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

end of thread, other threads:[~1995-02-10 13:49 UTC | newest]

Thread overview: 85+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-01-23  8:49 "Subtract C, add Ada" R.A.L Williams
1995-01-25 23:18 ` Charles H. Sampson
  -- strict thread matches above, loose matches on Subject: below --
1995-02-10 13:49 R.A.L Williams
     [not found] <3gsr0e$oin@miranda.gmrc.gecm.com>
1995-02-07 16:58 ` Mark S. Hathaway
1995-02-08  7:39   ` Travis C. Porco
1995-02-08 16:07     ` Fred J. McCall
1995-02-08 21:30       ` Garlington KE
1995-01-31  9:34 R.A.L Williams
1995-02-01 16:45 ` Charles H. Sampson
1995-01-20 10:20 R.A.L Williams
1995-01-20 13:22 ` Renaud HEBERT
1995-01-24  3:35   ` David Moore
1995-01-25  5:38     ` Robert Dewar
1995-01-28 16:35     ` Jules
1995-01-29  8:06       ` Matt Kennel
1995-01-30  5:31       ` Michael Feldman
1995-01-31 22:22         ` David O'Brien
1995-01-24 20:23   ` N. Mellor
1995-01-25  8:50     ` Robb Nebbe
1995-01-25 14:19     ` John Volan
1995-01-26  5:07     ` Samuel Mize
1995-01-26 18:51       ` Mark A Biggar
1995-01-21 15:18 ` Robert Dewar
1995-01-21 21:03 ` David O'Brien
1995-01-23  3:09   ` Jay Martin
1995-01-23 12:50     ` Andrew McConnell
1995-01-24  0:54     ` Matt Kennel
1995-01-25 17:03       ` Norman H. Cohen
1995-01-26  1:13         ` Dr. Richard Botting
1995-01-26 14:32         ` Anders Juul Munch
1995-01-24  0:17   ` Bob Kitzberger
1995-01-23 20:46 ` Robert Firth
1995-01-24 14:25   ` Samuel Mize
1995-01-25  7:27     ` David O'Brien
1995-01-25 12:14     ` Robert A Duff
1995-01-25  5:57   ` David O'Brien
     [not found]     ` <3g9rf0$71k@Starbase.NeoSoft.COM>
1995-01-28 21:08       ` David O'Brien
1995-01-31 18:07         ` Samuel Mize
1995-02-01 10:23         ` Samuel Mize
1995-01-30  0:24     ` Mark S. Hathaway
1995-01-31  3:30       ` Jay Martin
1995-02-01 13:25         ` Jesper Kaagaard
1995-01-20  9:33 R.A.L Williams
     [not found] <3fgphd$sc3@rational.rational.com>
1995-01-20  5:51 ` RonaldS60
1995-02-07 13:55   ` Robert C. Soong
     [not found] <3fdcoi$chn@miranda.gmrc.gecm.com>
1995-01-20  5:01 ` Samuel Mize
1995-01-20 22:07   ` Garlington KE
1995-01-24  5:02     ` R_Tim_Coslet
     [not found] <3etund$hnr@miranda.gmrc.gecm.com>
1995-01-12  9:56 ` Erik Svensson
1995-01-12 14:44 ` Norman H. Cohen
1995-01-13  1:51 ` David O'Brien
1995-01-13 12:38   ` Laurent Gasser
1995-01-13 20:53     ` John DiCamillo
     [not found]       ` <3f8fnf$c8p@gamma.ois.com>
1995-01-16 11:02         ` Matt Kennel
     [not found]         ` <milodD2IFpG.329@netcom.com>
1995-01-17 21:39           ` R. William Beckwith
     [not found]       ` <3fa11q$sdh@gnat.cs.nyu.edu>
1995-01-16 20:20         ` David Moore
1995-01-14  0:24     ` David O'Brien
1995-01-20  4:43     ` Samuel Mize
1995-01-21 20:28       ` David O'Brien
1995-01-22 21:12         ` Robert Dewar
1995-01-23 18:35         ` Norman H. Cohen
1995-01-23 19:18         ` John Cosby - The Coz
1995-01-24 14:11         ` Samuel Mize
1995-01-14 10:37   ` Keith Thompson
     [not found]     ` <3fcjgt$b0v@cronkite.seas.gwu.edu>
1995-01-16 18:47       ` Robert Dewar
     [not found]   ` <D2It0r.4rp@inmet.camb.inmet.com>
1995-01-17 14:11     ` Norman H. Cohen
1994-12-30 16:06 Mitch Gart
1995-01-03 19:04 ` whiting_ms@corning.com (Matt Whiting)
1995-01-05  4:31   ` Michael Feldman
1995-01-04 21:40 ` Fred McCall
1995-01-05  4:30   ` Richard Pattis
1995-01-05 16:07   ` Kevin Weise
1995-01-06 13:06   ` Jahn Rentmeister
1995-01-06 16:47     ` Laurent Gasser
1995-01-06 17:29       ` David Weller
1995-01-06 17:30         ` David Weller
1995-01-10 18:28       ` Bob Kitzberger
1995-01-06 23:36   ` Kenneth Almquist
1995-01-04 22:45 ` Jay M. Martin
1995-01-05  4:37   ` Michael Feldman
1995-01-05 18:08     ` Jay Martin
1995-01-05 23:56       ` Robert Dewar
1995-01-08  8:04         ` Jay Martin
1995-01-06  0:07       ` Michael M. Bishop
1995-01-10 21:30         ` Jay Martin

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