comp.lang.ada
 help / color / mirror / Atom feed
From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe)
Subject: Re: Coding Standards
Date: 1996/05/17
Date: 1996-05-17T00:00:00+00:00	[thread overview]
Message-ID: <4nh3n7$55g@goanna.cs.rmit.EDU.AU> (raw)
In-Reply-To: 319B286E.3B2E@lmtas.lmco.com


I liked initialised variables a lot, but I get to see rather more
student code than my nerves can really cope with, and the 300th
time you see

	n: Integer := 1;		int n = 0;
	<two pages>			<three pages>
	while n <= max loop		while (n+1 <= max) {
	    <one page>			    { <one page>
	    n := n+1;			    ++n;
	end loop;			   }

(Yes, the C is strangely indented, that's what I see.)
you realise "it is important to group related things together",
and "being able to move the first assignment up into the declarative
region tempts many beginners to do it when they shouldn't".

I've been looking for some guidelines, and I think that these are good:

    - constants MUST be initialised where they are declared

	X: constant Integer := ....;
	int const X = ...;

	(of course this doesn't apply to Ada deferred constants; give me
	credit for some sense.)

    - ALL variables must be initialised before they are used,
	WHETHER THE LANGUAGE WILL INITIALISE THEM OR NOT.

	This means I don't _care_ what Ada initialises pointers to,
	and I don't care what C initialises top-level variables to
	either.

    - other things being equal, the initialisation of a variable
      should be as late as possible.

    - other things being equal, the initialisation of a variable
      should be as close to its uses in the text as possible,
      so that when looking at the uses, the initialisation is
      visible.

I understand why Ada initialises pointers to null, and I wouldn't want
that changed, but if I want to check that a variable is properly
initialised, I want to _see_ an initialisation.

I would also like to point out that in this year's C class, the second
biggest cause of run-time errors (after the obvious biggie: design errors)
was uninitialised variables.  The lucky students were the ones where this
resulted in a NULL pointers that were caught by the hardware.
Students keep on telling me their program "works" when they really mean
that Turbo C failed to notice the problem most of the time.  (They are
actually required to compile their programs on a SPARC/Solaris system,
which is when they start complaining that 'cc' or 'gcc' is "broken".)

For teaching purposes, at any rate, I am 
 *for* any tool that will help to detect uninitialised variable use
 *against* any "solution" to the problem that requires programmer
     intervention; if the students were savvy enough to use such a
     solution, they wouldn't need it so much.

For developing large long-lived software systems where performance is
an issue, the tradeoffs are different.
-- 
Fifty years of programming language research, and we end up with C++ ???
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.




  reply	other threads:[~1996-05-17  0:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-15  0:00 Coding Standards W. Wesley Groleau (Wes)
1996-05-15  0:00 ` Robert A Duff
1996-05-28  0:00   ` Ken Garlington
1996-05-28  0:00     ` Robert A Duff
1996-05-29  0:00       ` Ken Garlington
1996-05-30  0:00       ` Frank Manning
1996-05-28  0:00   ` Ken Garlington
1996-05-16  0:00 ` Ken Garlington
1996-05-17  0:00   ` Richard A. O'Keefe [this message]
1996-05-17  0:00     ` Ken Garlington
1996-05-20  0:00       ` Richard A. O'Keefe
1996-05-20  0:00         ` Ken Garlington
  -- strict thread matches above, loose matches on Subject: below --
1996-05-17  0:00 W. Wesley Groleau (Wes)
1996-05-28  0:00 ` Ken Garlington
1996-05-29  0:00 W. Wesley Groleau (Wes)
1996-05-29  0:00 ` Ken Garlington
1996-05-29  0:00 ` Robert A Duff
1997-09-17  0:00 Is there an ADA analogue to the C++ continue statement? Heath, Terry D.
1997-09-18  0:00 ` Pascal Obry
1997-09-19  0:00   ` Robert Dewar
     [not found]     ` <3422F037.41CA@lmco.com>
1997-09-20  0:00       ` dan13
1997-09-21  0:00         ` Robert Dewar
     [not found]           ` <3426B51E.7296@lmco.com>
1997-09-23  0:00             ` Coding Standards W. Wesley Groleau x4923
replies disabled

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