comp.lang.ada
 help / color / mirror / Atom feed
* Re: if statements
  2000-11-03 16:09 ` Larry Kilgallen
@ 2000-11-03  0:00   ` tmoran
  2000-11-03  0:00     ` Larry Kilgallen
                       ` (2 more replies)
  0 siblings, 3 replies; 64+ messages in thread
From: tmoran @ 2000-11-03  0:00 UTC (permalink / raw)


> > can anyone show me an if statement that will swap the values of A and B,
> > if A is the greater value
>
> Probably not without violating our policy of not doing people's homework.
  Are there really programming classes that, in early November, have
only just started discussing "if" statements!?




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

* Re: if statements
  2000-11-03  0:00   ` tmoran
@ 2000-11-03  0:00     ` Larry Kilgallen
  2000-11-06  0:00       ` Brian Orpin
  2000-11-03  0:00     ` David Starner
  2000-11-07  0:00     ` John English
  2 siblings, 1 reply; 64+ messages in thread
From: Larry Kilgallen @ 2000-11-03  0:00 UTC (permalink / raw)


In article <t1CM5.385302$i5.6461252@news1.frmt1.sfba.home.com>, tmoran@acm.org writes:
>> > can anyone show me an if statement that will swap the values of A and B,
>> > if A is the greater value
>>
>> Probably not without violating our policy of not doing people's homework.
>   Are there really programming classes that, in early November, have
> only just started discussing "if" statements!?

There are schools that allow it to be turned in late by those who are behind.




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

* Re: if statements
  2000-11-03 14:42 sc297
@ 2000-11-03  0:00 ` David Starner
  2000-11-07  0:00   ` John English
  2000-11-13  0:00   ` Dale Pontius
  2000-11-03 16:09 ` Larry Kilgallen
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 64+ messages in thread
From: David Starner @ 2000-11-03  0:00 UTC (permalink / raw)


On Fri, 03 Nov 2000 14:42:28 +0000, sc297 wrote:
>can anyone show me an if statement that will swap the values of A and B,
>if A is the greater value

Yes. I can, and I bet your teacher can too.

-- 
David Starner - dstarner98@aasaa.ofe.org
http://dvdeug.dhis.org
As centuries of pulp novels and late-night Christian broadcasting have taught 
us, anything we don't understand can be used for the purposes of Evil.
	-- Kenneth Hite, Suppressed Transmissions




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

* Re: if statements
  2000-11-03  0:00   ` tmoran
  2000-11-03  0:00     ` Larry Kilgallen
@ 2000-11-03  0:00     ` David Starner
  2000-11-05  0:00       ` tmoran
  2000-11-07  0:00     ` John English
  2 siblings, 1 reply; 64+ messages in thread
From: David Starner @ 2000-11-03  0:00 UTC (permalink / raw)


On Fri, 03 Nov 2000 16:50:33 GMT, tmoran@acm.org wrote:
>> > can anyone show me an if statement that will swap the values of A and B,
>> > if A is the greater value
>>
>> Probably not without violating our policy of not doing people's homework.
>  Are there really programming classes that, in early November, have
>only just started discussing "if" statements!?

Sure. Aren't there half-semester 'intense' programming classes? Or schools 
that don't run on the American semester system? Anyway, even if he isn't
an active student, it still isn't going to help him trying to learn 
programming via cla.

-- 
David Starner - dstarner98@aasaa.ofe.org
http://dvdeug.dhis.org
As centuries of pulp novels and late-night Christian broadcasting have taught 
us, anything we don't understand can be used for the purposes of Evil.
	-- Kenneth Hite, Suppressed Transmissions




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

* if statements
@ 2000-11-03 14:42 sc297
  2000-11-03  0:00 ` David Starner
                   ` (4 more replies)
  0 siblings, 5 replies; 64+ messages in thread
From: sc297 @ 2000-11-03 14:42 UTC (permalink / raw)


can anyone show me an if statement that will swap the values of A and B,
if A is the greater value




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

* Re: if statements
  2000-11-03 14:42 sc297
  2000-11-03  0:00 ` David Starner
@ 2000-11-03 16:09 ` Larry Kilgallen
  2000-11-03  0:00   ` tmoran
  2000-11-06  0:00 ` Daniel Allex
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 64+ messages in thread
From: Larry Kilgallen @ 2000-11-03 16:09 UTC (permalink / raw)


In article <3A02CED4.520C2768@brighton.ac.uk>, sc297 <sc297@brighton.ac.uk> writes:
> can anyone show me an if statement that will swap the values of A and B,
> if A is the greater value

Probably not without violating our policy of not doing people's homework.



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

* Re: if statements
  2000-11-03  0:00     ` David Starner
@ 2000-11-05  0:00       ` tmoran
  2000-11-06  0:00         ` David Starner
  2000-11-07  0:00         ` John English
  0 siblings, 2 replies; 64+ messages in thread
From: tmoran @ 2000-11-05  0:00 UTC (permalink / raw)


>Sure. Aren't there half-semester 'intense' programming classes? Or schools
>that don't run on the American semester system? Anyway, even if he isn't
>an active student, it still isn't going to help him trying to learn
>programming via cla.
  If it's an 8-hour/day intense programming class, it should be past "if"
statements by the time he gets home and uses the Internet.  In any case,
c.l.a. is going to be much too slow a source of answers.  Certainly
there exist other time schedules than Sept-Dec semesters, but I'd be
surprised to hear of any that start at the beginning of November.  The
"American semester system" is not a totally random set of times like the
date of someone's birthday or something.  If he isn't taking a class, but
is trying to learn by himself, and can't see the answer from his
available texts, and can't get answers from c.l.a., then just how is he
supposed to find such answers?  If he's an RPG programmer trying to
expand his repertoire, perhaps he'll find a different language than Ada
where c.l.x. is more helpful.  If he is in fact taking a (slow) class
and someone answered a homework question on "if" statements, how
serious is the damage that would be done to others than himself?
  Perhaps I'm just hopelessly naive in imagining innocence until
proven guilty.




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

* Re: if statements
  2000-11-03  0:00     ` Larry Kilgallen
@ 2000-11-06  0:00       ` Brian Orpin
  0 siblings, 0 replies; 64+ messages in thread
From: Brian Orpin @ 2000-11-06  0:00 UTC (permalink / raw)


On 3 Nov 2000 12:35:37 -0500, Kilgallen@eisner.decus.org.nospam (Larry
Kilgallen) wrote:

>In article <t1CM5.385302$i5.6461252@news1.frmt1.sfba.home.com>, tmoran@acm.org writes:
>>> > can anyone show me an if statement that will swap the values of A and B,
>>> > if A is the greater value
>>>
>>> Probably not without violating our policy of not doing people's homework.
>>   Are there really programming classes that, in early November, have
>> only just started discussing "if" statements!?
>
>There are schools that allow it to be turned in late by those who are behind.

From the headers 

From: sc297 <sc297@brighton.ac.uk>
Newsgroups: comp.lang.ada
Subject: if statements
Date: Fri, 03 Nov 2000 14:42:28 +0000

Is this one of David's (he is still there is he not?) students <VBG>

-- 
Brian Orpin    BAE SYSTEMS, Edinburgh
"If you really know C++, there isn't much you can't do with it, though it may 
not always be what you intended!"  Tucker Taft 1998 




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

* Re: if statements
  2000-11-05  0:00       ` tmoran
@ 2000-11-06  0:00         ` David Starner
  2000-11-08  0:14           ` Alejandro R. Mosteo
  2000-11-07  0:00         ` John English
  1 sibling, 1 reply; 64+ messages in thread
From: David Starner @ 2000-11-06  0:00 UTC (permalink / raw)


On Sun, 05 Nov 2000 23:37:57 GMT, tmoran@acm.org wrote:
>  If it's an 8-hour/day intense programming class, it should be past "if"
>statements by the time he gets home and uses the Internet.  In any case,
>c.l.a. is going to be much too slow a source of answers.  Certainly
>there exist other time schedules than Sept-Dec semesters, but I'd be
>surprised to hear of any that start at the beginning of November.  

I know of American universities with 15-18 hour semesters, but serial instead
of parellel classes, i.e. 3 hours a day of class with (in theory) 3 hours
a day of homework, with one starting about every three weeks.

>If he isn't taking a class, but
>is trying to learn by himself, and can't see the answer from his
>available texts, and can't get answers from c.l.a., then just how is he
>supposed to find such answers?  If he's an RPG programmer trying to
>expand his repertoire, perhaps he'll find a different language than Ada
>where c.l.x. is more helpful.  

When I first read the question, I wondered which university was teaching
basic programming with Ada. I remember when I first looked at Ada knowing
QBasic, and C (with no formal programming training), I would have regarded
that question as trivial. If he is learning Ada by himself, I fear that 
more questions like this will follow and few groups can accept the many
basic questions of a beginner who has found someone who can answer his
questions for him.

I am curious why, if you disagree with our approach, why you did not
just answer him yourself?

-- 
David Starner - dstarner98@aasaa.ofe.org
http://dvdeug.dhis.org
As centuries of pulp novels and late-night Christian broadcasting have taught 
us, anything we don't understand can be used for the purposes of Evil.
	-- Kenneth Hite, Suppressed Transmissions




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

* Re: if statements
  2000-11-03 14:42 sc297
  2000-11-03  0:00 ` David Starner
  2000-11-03 16:09 ` Larry Kilgallen
@ 2000-11-06  0:00 ` Daniel Allex
  2000-11-07  0:00   ` dmitry6243
                     ` (4 more replies)
  2000-11-07  0:00 ` John English
  2000-11-10  6:09 ` DJack143
  4 siblings, 5 replies; 64+ messages in thread
From: Daniel Allex @ 2000-11-06  0:00 UTC (permalink / raw)


procedure Swap ( A,     B : in out Integer ) is
      Temp : Integer := 0;
   begin
      if A <= B then
         Temp := A;
         A := B;
         B := Temp;
      end if;
   end;


sc297 wrote:

> can anyone show me an if statement that will swap the values of A and B,
> if A is the greater value





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

* Re: if statements
  2000-11-06  0:00 ` Daniel Allex
  2000-11-07  0:00   ` dmitry6243
  2000-11-07  0:00   ` Robert Dewar
@ 2000-11-07  0:00   ` Wes Groleau
  2000-11-08  0:00     ` John English
  2000-11-07  0:00   ` Ken Garlington
  2000-11-07  0:00   ` John English
  4 siblings, 1 reply; 64+ messages in thread
From: Wes Groleau @ 2000-11-07  0:00 UTC (permalink / raw)


> procedure Swap ( A,     B : in out Integer ) is
>       Temp : Integer := 0;
>    begin
>       if A <= B then
>          Temp := A;
>          A := B;
>          B := Temp;
>       end if;
>    end;

Well, if we're going to do the guy's homework
for him, we might as well do it elegantly:

Temp := B;
B    := Integer'Min (A, B)
A    := Integer'Max (A, Temp);

Oops, the "if" he wanted is missing.  :-)


-- 
Wes Groleau for President of the U.S.A.
http://freepages.rootsweb.com/~wgroleau




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

* Re: if statements
  2000-11-06  0:00 ` Daniel Allex
  2000-11-07  0:00   ` dmitry6243
@ 2000-11-07  0:00   ` Robert Dewar
  2000-11-07  0:00     ` Larry Kilgallen
  2000-11-08  0:00     ` Alejandro Villanueva
  2000-11-07  0:00   ` Wes Groleau
                     ` (2 subsequent siblings)
  4 siblings, 2 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-07  0:00 UTC (permalink / raw)


In article <3A078B6F.D34B024B@erols.com>,
  Daniel Allex <dallex@erols.com> wrote:
> procedure Swap ( A,     B : in out Integer ) is
>       Temp : Integer := 0;
>    begin
>       if A <= B then
>          Temp := A;
>          A := B;
>          B := Temp;
>       end if;
>    end;


Finally he gets someone to do his homework for him, though
not very competently (this looks like another student
tackling the excercise for the first time :-)



Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-07  0:00     ` John English
@ 2000-11-07  0:00       ` Robert Dewar
  2000-11-08  0:00         ` John English
  2000-11-08  5:29       ` Ken Garlington
  1 sibling, 1 reply; 64+ messages in thread
From: Robert Dewar @ 2000-11-07  0:00 UTC (permalink / raw)


In article <3A0824BB.14ACCA12@bton.ac.uk>,
  John English <je@bton.ac.uk> wrote:
> Unfortunately this sort of question gets marked by an
> automated system, so the robotic instructor in question will,
> I'm afraid, be deeply unimpressed. ;-)

It's a shame when only a dumb answer is accepted. In particular
I assume your robot would not know about the xor solution,
which is in some sense the best. There are of course
interesting solutions at the machine language level that
do not require any jumps which are always fun :-)


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-07  0:00 ` John English
@ 2000-11-07  0:00   ` Robert Dewar
  0 siblings, 0 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-07  0:00 UTC (permalink / raw)


In article <3A080A66.2AEB25D2@bton.ac.uk>,
  John English <je@bton.ac.uk> wrote:
> sc297 wrote:
> > can anyone show me an if statement that will swap the values
of A and B,
> > if A is the greater value
>
> You could always ask your lecturers (either myself, or Richard
Byrne)
> if you're having trouble... ever thought of that?


Maybe next time one of your students asks CLA to do their
homework, you should provide an answer yourself, specially
identified so that your robot corrector will spit it out
with a complaint about getting CLA to do your homework :-)


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-07  0:00   ` Robert Dewar
@ 2000-11-07  0:00     ` Larry Kilgallen
  2000-11-08  0:00     ` Alejandro Villanueva
  1 sibling, 0 replies; 64+ messages in thread
From: Larry Kilgallen @ 2000-11-07  0:00 UTC (permalink / raw)


In article <8ua3m1$bru$1@nnrp1.deja.com>, Robert Dewar <robert_dewar@my-deja.com> writes:
> In article <3A078B6F.D34B024B@erols.com>,
>   Daniel Allex <dallex@erols.com> wrote:
>> procedure Swap ( A,     B : in out Integer ) is
>>       Temp : Integer := 0;
>>    begin
>>       if A <= B then
>>          Temp := A;
>>          A := B;
>>          B := Temp;
>>       end if;
>>    end;
> 
> 
> Finally he gets someone to do his homework for him, though
> not very competently (this looks like another student
> tackling the excercise for the first time :-)

Maybe the student's strength is spelling "exercise" :-)




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

* Re: if statements
  2000-11-06  0:00 ` Daniel Allex
@ 2000-11-07  0:00   ` dmitry6243
  2000-11-07  0:00     ` Jean-Pierre Rosen
  2000-11-07  0:00   ` Robert Dewar
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 64+ messages in thread
From: dmitry6243 @ 2000-11-07  0:00 UTC (permalink / raw)


In article <3A078B6F.D34B024B@erols.com>,
  Daniel Allex <dallex@erols.com> wrote:
> procedure Swap ( A,     B : in out Integer ) is
>       Temp : Integer := 0;
>    begin
>       if A <= B then
>          Temp := A;
>          A := B;
>          B := Temp;
>       end if;
>    end;

A funny version that does not require a temp variable:

procedure Swap (A, B : in out Integer) is
begin
   if A <= B then
      A := A + B;
      B := A - B;
      A := A - B;
   end if;
end Swap;

It works better if A, B are modular (:-))

--
Regards,
Dmitry Kazakov


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-06  0:00 ` Daniel Allex
                     ` (2 preceding siblings ...)
  2000-11-07  0:00   ` Wes Groleau
@ 2000-11-07  0:00   ` Ken Garlington
  2000-11-07  0:00     ` John English
  2000-11-07  0:00   ` John English
  4 siblings, 1 reply; 64+ messages in thread
From: Ken Garlington @ 2000-11-07  0:00 UTC (permalink / raw)


"Daniel Allex" <dallex@erols.com> wrote in message
news:3A078B6F.D34B024B@erols.com...
: procedure Swap ( A,     B : in out Integer ) is
:       Temp : Integer := 0;
:    begin
:       if A <= B then
:          Temp := A;
:          A := B;
:          B := Temp;
:       end if;
:    end;
:
:
: sc297 wrote:
:
: > can anyone show me an if statement that will swap the values of A and B,
: > if A is the greater value

Now *I* feel like a beginning Ada student! Doesn't the proposed solution
swap A and B if A is *not* the greater value? And why is Temp assigned an
initial value of 0?

Personally, I would have gone with something more along the lines of

generic
   type Value is private;
   with function ">"(A, B : Value) return Boolean is <>;
procedure Homework_Assignment(A, B : in out Value);

-- Exchange is defined in the Ada Reference Manual
with Exchange;
procedure Homework_Assignment(A, B : in out Value) is
   procedure Swap is new Exchange(Value);
begin
   if A > B then
      Swap(A,B);
   end if;
end Homework_Assignment;

Can't you imagine how pleased the instructor will be to find out that the
student has already mastered generics?






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

* Re: if statements
  2000-11-03 14:42 sc297
                   ` (2 preceding siblings ...)
  2000-11-06  0:00 ` Daniel Allex
@ 2000-11-07  0:00 ` John English
  2000-11-07  0:00   ` Robert Dewar
  2000-11-10  6:09 ` DJack143
  4 siblings, 1 reply; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


sc297 wrote:
> can anyone show me an if statement that will swap the values of A and B,
> if A is the greater value

You could always ask your lecturers (either myself, or Richard Byrne)
if you're having trouble... ever thought of that?

:-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-03  0:00   ` tmoran
  2000-11-03  0:00     ` Larry Kilgallen
  2000-11-03  0:00     ` David Starner
@ 2000-11-07  0:00     ` John English
  2000-11-08  5:22       ` Ken Garlington
  2 siblings, 1 reply; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


tmoran@acm.org wrote:
> 
> > > can anyone show me an if statement that will swap the values of A and B,
> > > if A is the greater value
> >
> > Probably not without violating our policy of not doing people's homework.
>   Are there really programming classes that, in early November, have
> only just started discussing "if" statements!?

The original post was presumably in response to this:
  "Exercise 4.1: Write an if statement which will swap the values of
   variables A and B if necessary so that the smaller value ends up in
   A and the larger value ends up in B."

The closing date for this was the 3rd of November; the question had
been made available at least 2 weeks earlier.

A similar question was also set 2 weeks prior to that:
  "Exercise 2.6: Write a set of assignment statements which will swap
   the values of two variables called A and B."

Presumably he didn't manage to solve that, or hadn't noticed the
similarity... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-05  0:00       ` tmoran
  2000-11-06  0:00         ` David Starner
@ 2000-11-07  0:00         ` John English
  1 sibling, 0 replies; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


tmoran@acm.org wrote:
> Certainly
> there exist other time schedules than Sept-Dec semesters, but I'd be
> surprised to hear of any that start at the beginning of November.

Our semesters have been retrofitted around the existing UK academic
year, so the first week of the course was October 9th. The question
originally posed was set at the end of week 2 of the course as part
of a set of questions with a submission deadline of the end of week
4 (Nov 3rd).

For the curious, our 1st semester cunningly breaks after 10 weeks
for a few weeks at Christmas, resumes for 3 weeks, stops for another
3 weeks (the "inter-semester gap") to allow time for marking, exams
and so on. Semester 2 then runs for 5 weeks before Easter, stops for
another 3 weeks, then starts up again for another 8 weeks. This is
what you get when you take a perfectly good working system of three
10-week terms and retrofit an American-inspired set of 2 semesters
within them... :-(

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-03  0:00 ` David Starner
@ 2000-11-07  0:00   ` John English
  2000-11-13  0:00   ` Dale Pontius
  1 sibling, 0 replies; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


David Starner wrote:
> 
> On Fri, 03 Nov 2000 14:42:28 +0000, sc297 wrote:
> >can anyone show me an if statement that will swap the values of A and B,
> >if A is the greater value
> 
> Yes. I can, and I bet your teacher can too.

I certainly could if he bothered to ask... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-06  0:00 ` Daniel Allex
                     ` (3 preceding siblings ...)
  2000-11-07  0:00   ` Ken Garlington
@ 2000-11-07  0:00   ` John English
  4 siblings, 0 replies; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


Daniel Allex wrote:
> 
> procedure Swap ( A,     B : in out Integer ) is
>       Temp : Integer := 0;
>    begin
>       if A <= B then
>          Temp := A;
>          A := B;
>          B := Temp;
>       end if;
>    end;
> 
> sc297 wrote:
> 
> > can anyone show me an if statement that will swap the values of A and B,
> > if A is the greater value

Too late, the deadline was last Friday... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-07  0:00   ` Ken Garlington
@ 2000-11-07  0:00     ` John English
  2000-11-07  0:00       ` Robert Dewar
  2000-11-08  5:29       ` Ken Garlington
  0 siblings, 2 replies; 64+ messages in thread
From: John English @ 2000-11-07  0:00 UTC (permalink / raw)


Ken Garlington wrote:
> Personally, I would have gone with something more along the lines of
> 
> generic
>    type Value is private;
>    with function ">"(A, B : Value) return Boolean is <>;
> procedure Homework_Assignment(A, B : in out Value);
> 
> -- Exchange is defined in the Ada Reference Manual
> with Exchange;
> procedure Homework_Assignment(A, B : in out Value) is
>    procedure Swap is new Exchange(Value);
> begin
>    if A > B then
>       Swap(A,B);
>    end if;
> end Homework_Assignment;
> 
> Can't you imagine how pleased the instructor will be to find out that the
> student has already mastered generics?

Unfortunately this sort of question gets marked by an automated
system, so the robotic instructor in question will, I'm afraid,
be deeply unimpressed. ;-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-07  0:00   ` dmitry6243
@ 2000-11-07  0:00     ` Jean-Pierre Rosen
  2000-11-08  0:00       ` dmitry6243
  0 siblings, 1 reply; 64+ messages in thread
From: Jean-Pierre Rosen @ 2000-11-07  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 429 bytes --]


<dmitry6243@my-deja.com> a �crit dans le message news: 8u8j99$2rk$1@nnrp1.deja.com...
> A funny version that does not require a temp variable:
>
> procedure Swap (A, B : in out Integer) is
> begin
>    if A <= B then
>       A := A + B;
>       B := A - B;
>       A := A - B;
>    end if;
> end Swap;
>
> It works better if A, B are modular (:-))
>
But then, you have :
   A:= A xor B;
   B := B xor A;
   A := A xor B;






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

* Re: if statements
  2000-11-08  0:00     ` John English
@ 2000-11-08  0:00       ` Wes Groleau
  2000-11-09  3:43         ` Ken Garlington
  0 siblings, 1 reply; 64+ messages in thread
From: Wes Groleau @ 2000-11-08  0:00 UTC (permalink / raw)


J
> > Temp := B;
> > B    := Integer'Min (A, B)
> > A    := Integer'Max (A, Temp);
> >
> > Oops, the "if" he wanted is missing.  :-)
> 
> Hmm. I'll change the test program to use a hidden record type
> instead of an Integer with smart people like you around... ;-)

But then you'd also have to change the words that say
"swap A and B if B is _larger_"

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau




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

* Re: if statements
  2000-11-08  0:00             ` Alejandro Villanueva
@ 2000-11-08  0:00               ` Georg Bauhaus
  2000-11-09  3:50               ` Ken Garlington
  1 sibling, 0 replies; 64+ messages in thread
From: Georg Bauhaus @ 2000-11-08  0:00 UTC (permalink / raw)


Alejandro Villanueva (190921@cepsz.unizar.es) wrote:

: please, we are here to help other people... isn't it????

But how?

I remember seeing a = a + 1 in a desk calculator's
BASIC and I was desperate, because I could not see
that this was not a declaration of equality, until
I found out that "=" was actually ":=". Now if
the problem had been "Swap"ping (like in this thread,
partly), and I had not yet
heard that you can't just exchange the values of
two variables in some programming language, ie without
a helper variable or one of the other ingenuities
presented earlier in this thread, I think I would have
found a reformulation of the problem that used more
familiar 'objects' quite useful to gain an understanding.
Something along:

"If, late at night at some party, you mistakenly put the rest
 of the beer into a glass suitable for wine, and the rest of
 the wine into a glass suitable for beer, what can you do
 to exchange the fluids?"

I can't say if this will actually help someone, but
it might, i think, help their imagination;
most people have two hands and can take up A and B in
either and are quite ready to say, 

A :=: B;

as is at least the x86. Isn't having to introduce additional
memory or calculation part of the new unfamiliar way of thinking
when programming, and isn't this much better explained 
with words (before formal training) than with
T: = A; A:= B; B:= T; alone?

I'm still thankful for exactly this happening on c.l.a with
"more advanced" data structures and tricks. (And should I
add that I do not think that John English doesn't
explain?)




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

* Re: if statements
  2000-11-07  0:00     ` Jean-Pierre Rosen
@ 2000-11-08  0:00       ` dmitry6243
  0 siblings, 0 replies; 64+ messages in thread
From: dmitry6243 @ 2000-11-08  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

In article <8u9r96$jmb$1@wanadoo.fr>,
  "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr> wrote:
>
> <dmitry6243@my-deja.com> a �crit dans le message news:
8u8j99$2rk$1@nnrp1.deja.com...
> > A funny version that does not require a temp variable:
> >
> > procedure Swap (A, B : in out Integer) is
> > begin
> >    if A <= B then
> >       A := A + B;
> >       B := A - B;
> >       A := A - B;
> >    end if;
> > end Swap;
> >
> > It works better if A, B are modular (:-))
> >
> But then, you have :
>    A:= A xor B;
>    B := B xor A;
>    A := A xor B;

It will work too, but for modulus 2**n only. +/- variant should work
always (:-))

--
Regards,
Dmitry Kazakov


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-08  0:00         ` John English
@ 2000-11-08  0:00           ` Ken Garlington
  0 siblings, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-08  0:00 UTC (permalink / raw)


"John English" <je@bton.ac.uk> wrote in message
news:3A094717.AAF0EB30@bton.ac.uk...

: >   "Exercise 4.1: Write an if statement which will swap the values of
: >    variables A and B if necessary so that the smaller value ends up in
: >    A and the larger value ends up in B."

: The only problem with your solution is that the question asks for
: a bare statement; your solution would be embedded inside a block,
: so it would fail to compile without some extra work...

If the "question" is the one above, I don't see the word "bare" (or
"fragment", etc.) anywhere. You asked for an if statement, I gave you an if
statement. The fact that I put it in a complete (and more expressive)
solution should be worth extra credit, not a failing grade!

P.S. I always like the Bohr story, no matter how many times I hear it:

http://www.snopes.com/college/exam/barometr.htm

P.P.S. Notice that I didn't even comment before on the difficulties in
putting the smaller value in A (via if statement or otherwise) if A = B....






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

* Re: if statements
  2000-11-08  0:00         ` John English
@ 2000-11-08  0:00           ` Georg Bauhaus
  2000-11-09  4:58           ` Robert Dewar
  1 sibling, 0 replies; 64+ messages in thread
From: Georg Bauhaus @ 2000-11-08  0:00 UTC (permalink / raw)


John English (je@bton.ac.uk) wrote:
: the robot being unimpressed is merely to do with the fact that I
: haven't yet managed to program a sense of aesthetics into it. If
: anyone has a solution to that, *I'd* be deeply impressed... :-)

Probably not that much to the point but still interesting:
http://www.cs.berkeley.edu/~aiken/moss.html




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

* Re: if statements
  2000-11-07  0:00       ` Robert Dewar
@ 2000-11-08  0:00         ` John English
  2000-11-08  0:00           ` Georg Bauhaus
  2000-11-09  4:58           ` Robert Dewar
  0 siblings, 2 replies; 64+ messages in thread
From: John English @ 2000-11-08  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> 
> In article <3A0824BB.14ACCA12@bton.ac.uk>,
>   John English <je@bton.ac.uk> wrote:
> > Unfortunately this sort of question gets marked by an
> > automated system, so the robotic instructor in question will,
> > I'm afraid, be deeply unimpressed. ;-)
> 
> It's a shame when only a dumb answer is accepted. In particular
> I assume your robot would not know about the xor solution,
> which is in some sense the best. There are of course
> interesting solutions at the machine language level that
> do not require any jumps which are always fun :-)

You misunderstand. The robot embeds submitted assignment statements
in a test program, runs the result against a set of test cases, and
checks that the output is correct wrt a standard solution. So it
would be quite happy with the xor solution, too. The reference to
the robot being unimpressed is merely to do with the fact that I
haven't yet managed to program a sense of aesthetics into it. If
anyone has a solution to that, *I'd* be deeply impressed... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-08  5:29       ` Ken Garlington
@ 2000-11-08  0:00         ` John English
  2000-11-08  0:00           ` Ken Garlington
  0 siblings, 1 reply; 64+ messages in thread
From: John English @ 2000-11-08  0:00 UTC (permalink / raw)


Ken Garlington wrote:
> 
> "John English" <je@bton.ac.uk> wrote in message
> news:3A0824BB.14ACCA12@bton.ac.uk...
> : Ken Garlington wrote:
> : > Personally, I would have gone with something more along the lines of
> : >
> : > generic
> : >    type Value is private;
> : >    with function ">"(A, B : Value) return Boolean is <>;
> : > procedure Homework_Assignment(A, B : in out Value);
> : >
> : > -- Exchange is defined in the Ada Reference Manual
> : > with Exchange;
> : > procedure Homework_Assignment(A, B : in out Value) is
> : >    procedure Swap is new Exchange(Value);
> : > begin
> : >    if A > B then
> : >       Swap(A,B);
> : >    end if;
> : > end Homework_Assignment;
> : >
> : > Can't you imagine how pleased the instructor will be to find out that
> the
> : > student has already mastered generics?
> :
> : Unfortunately this sort of question gets marked by an automated
> : system, so the robotic instructor in question will, I'm afraid,
> : be deeply unimpressed. ;-)
> 
> Would it mark it as correct? If the original question was
> 
>   "Exercise 4.1: Write an if statement which will swap the values of
>    variables A and B if necessary so that the smaller value ends up in
>    A and the larger value ends up in B."
> 
> I actually think my solution is a more excruciatingly correct answer,
> compared to the "obvious" solution. In particular, the types of the
> variables are not specified, so the solution shouldn't assume one - right?

The robot embeds the submitted solution in a skeletal test program
and runs it against a set of test data. The test program happens
to declare A, B and T as Integer, but that's irrelevant (any non-limited
type would do as well).

The only problem with your solution is that the question asks for
a bare statement; your solution would be embedded inside a block,
so it would fail to compile without some extra work...

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-07  0:00   ` Wes Groleau
@ 2000-11-08  0:00     ` John English
  2000-11-08  0:00       ` Wes Groleau
  0 siblings, 1 reply; 64+ messages in thread
From: John English @ 2000-11-08  0:00 UTC (permalink / raw)


Wes Groleau wrote:
> Well, if we're going to do the guy's homework
> for him, we might as well do it elegantly:
> 
> Temp := B;
> B    := Integer'Min (A, B)
> A    := Integer'Max (A, Temp);
> 
> Oops, the "if" he wanted is missing.  :-)

Hmm. I'll change the test program to use a hidden record type
instead of an Integer with smart people like you around... ;-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-08  0:14           ` Alejandro R. Mosteo
@ 2000-11-08  0:00             ` Alejandro Villanueva
  2000-11-08  0:00               ` Georg Bauhaus
  2000-11-09  3:50               ` Ken Garlington
  0 siblings, 2 replies; 64+ messages in thread
From: Alejandro Villanueva @ 2000-11-08  0:00 UTC (permalink / raw)


Alejandro R. Mosteo wrote:

> Hello. Here in Spain, my university (in Zaragoza) uses Ada as the
> programming languaje in several subjects (all of them half academic
> year duration):
>

Well, if you see my address you will see that I'm from the same Uni that you...

My final project is also with Ada95 running under RTEMS (the degree is
industrial engineering, 5-year long)

And now...

procedure Swap (A, B: in out Integer) is
   C: Integer;
begin
   if A > B then
      C := B;
      B := A;
      A := C;
   end if;
end Swap;

please, we are here to help other people... isn't it????

>
> Introducction to programming.
> Algorithm schemes. (Perhaps bad translating here...)
> Data structures and algorithms.
> Concurrent programming.
> Real time systems.
>
> Perhaps I forget even more (the career is computing engineering, five
> years long).
>
> Cheers,
>
> A. Mosteo.
>
> > When I first read the question, I wondered which university was teaching
> > basic programming with Ada. I remember when I first looked at Ada knowing
> > QBasic, and C (with no formal programming training), I would have regarded
> > that question as trivial. If he is learning Ada by himself, I fear that
> > more questions like this will follow and few groups can accept the many
> > basic questions of a beginner who has found someone who can answer his
> > questions for him.

--
------------------------------------------------------
�Quieres Cobrar por Navegar en Internet?
Visita: http://www.navegana.com/dinero/flintstone.html
------------------------------------------------------
Alejandro Villanueva
190921@cepsz.unizar.es
------------------------------------------------------







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

* Re: if statements
  2000-11-07  0:00   ` Robert Dewar
  2000-11-07  0:00     ` Larry Kilgallen
@ 2000-11-08  0:00     ` Alejandro Villanueva
  2000-11-08  0:00       ` Daniel Allex
                         ` (2 more replies)
  1 sibling, 3 replies; 64+ messages in thread
From: Alejandro Villanueva @ 2000-11-08  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> In article <3A078B6F.D34B024B@erols.com>,
>   Daniel Allex <dallex@erols.com> wrote:
> > procedure Swap ( A,     B : in out Integer ) is
> >       Temp : Integer := 0;
> >    begin
> >       if A <= B then
> >          Temp := A;
> >          A := B;
> >          B := Temp;
> >       end if;
> >    end;
>
> Finally he gets someone to do his homework for him, though
> not very competently (this looks like another student
> tackling the excercise for the first time :-)
>

Robert, you do always the same... why do you have to say that?
It IS a valid solution, and not the solution a geek will give after all.
And MOST important: it WORKS!

> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
------------------------------------------------------
�Quieres Cobrar por Navegar en Internet?
Visita: http://www.navegana.com/dinero/flintstone.html
------------------------------------------------------
Alejandro Villanueva
190921@cepsz.unizar.es
------------------------------------------------------







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

* Re: if statements
  2000-11-08  0:00     ` Alejandro Villanueva
@ 2000-11-08  0:00       ` Daniel Allex
  2000-11-09  3:54       ` Ken Garlington
  2000-11-09  5:24       ` Robert Dewar
  2 siblings, 0 replies; 64+ messages in thread
From: Daniel Allex @ 2000-11-08  0:00 UTC (permalink / raw)
  To: Alejandro Villanueva

Thanks!  The guy asked for help.  I gave a solution.  Period.  This group
sure spends a lot of time going in circles.

Alejandro Villanueva wrote:

> Robert Dewar wrote:
>
> > In article <3A078B6F.D34B024B@erols.com>,
> >   Daniel Allex <dallex@erols.com> wrote:
> > > procedure Swap ( A,     B : in out Integer ) is
> > >       Temp : Integer := 0;
> > >    begin
> > >       if A <= B then
> > >          Temp := A;
> > >          A := B;
> > >          B := Temp;
> > >       end if;
> > >    end;
> >
> > Finally he gets someone to do his homework for him, though
> > not very competently (this looks like another student
> > tackling the excercise for the first time :-)
> >
>
> Robert, you do always the same... why do you have to say that?
> It IS a valid solution, and not the solution a geek will give after all.
> And MOST important: it WORKS!
>
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> ------------------------------------------------------
> �Quieres Cobrar por Navegar en Internet?
> Visita: http://www.navegana.com/dinero/flintstone.html
> ------------------------------------------------------
> Alejandro Villanueva
> 190921@cepsz.unizar.es
> ------------------------------------------------------





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

* Re: if statements
  2000-11-06  0:00         ` David Starner
@ 2000-11-08  0:14           ` Alejandro R. Mosteo
  2000-11-08  0:00             ` Alejandro Villanueva
  0 siblings, 1 reply; 64+ messages in thread
From: Alejandro R. Mosteo @ 2000-11-08  0:14 UTC (permalink / raw)


Hello. Here in Spain, my university (in Zaragoza) uses Ada as the 
programming languaje in several subjects (all of them half academic 
year duration):

Introducction to programming.
Algorithm schemes. (Perhaps bad translating here...)
Data structures and algorithms.
Concurrent programming.
Real time systems.

Perhaps I forget even more (the career is computing engineering, five 
years long).

Cheers,

A. Mosteo.

> When I first read the question, I wondered which university was teaching
> basic programming with Ada. I remember when I first looked at Ada knowing
> QBasic, and C (with no formal programming training), I would have regarded
> that question as trivial. If he is learning Ada by himself, I fear that 
> more questions like this will follow and few groups can accept the many
> basic questions of a beginner who has found someone who can answer his
> questions for him.



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

* Re: if statements
  2000-11-07  0:00     ` John English
@ 2000-11-08  5:22       ` Ken Garlington
  0 siblings, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-08  5:22 UTC (permalink / raw)


"John English" <je@bton.ac.uk> wrote in message
news:3A081648.8E6FF536@bton.ac.uk...
: tmoran@acm.org wrote:
: >

: A similar question was also set 2 weeks prior to that:
:   "Exercise 2.6: Write a set of assignment statements which will swap
:    the values of two variables called A and B."

Given that this answer is in the Ada Reference Manual, I hope someone gave
the ARM paragraph as the answer :)





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

* Re: if statements
  2000-11-07  0:00     ` John English
  2000-11-07  0:00       ` Robert Dewar
@ 2000-11-08  5:29       ` Ken Garlington
  2000-11-08  0:00         ` John English
  1 sibling, 1 reply; 64+ messages in thread
From: Ken Garlington @ 2000-11-08  5:29 UTC (permalink / raw)


"John English" <je@bton.ac.uk> wrote in message
news:3A0824BB.14ACCA12@bton.ac.uk...
: Ken Garlington wrote:
: > Personally, I would have gone with something more along the lines of
: >
: > generic
: >    type Value is private;
: >    with function ">"(A, B : Value) return Boolean is <>;
: > procedure Homework_Assignment(A, B : in out Value);
: >
: > -- Exchange is defined in the Ada Reference Manual
: > with Exchange;
: > procedure Homework_Assignment(A, B : in out Value) is
: >    procedure Swap is new Exchange(Value);
: > begin
: >    if A > B then
: >       Swap(A,B);
: >    end if;
: > end Homework_Assignment;
: >
: > Can't you imagine how pleased the instructor will be to find out that
the
: > student has already mastered generics?
:
: Unfortunately this sort of question gets marked by an automated
: system, so the robotic instructor in question will, I'm afraid,
: be deeply unimpressed. ;-)

Would it mark it as correct? If the original question was

  "Exercise 4.1: Write an if statement which will swap the values of
   variables A and B if necessary so that the smaller value ends up in
   A and the larger value ends up in B."

I actually think my solution is a more excruciatingly correct answer,
compared to the "obvious" solution. In particular, the types of the
variables are not specified, so the solution shouldn't assume one - right?





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

* Re: if statements
  2000-11-09  0:00         ` Ken Garlington
@ 2000-11-09  0:00           ` Robert Dewar
  2000-11-10  0:12             ` Ehud Lamm
                               ` (2 more replies)
  0 siblings, 3 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-09  0:00 UTC (permalink / raw)


In article <KsxO5.9249$pq3.738457@news.flash.net>,
  "Ken Garlington" <Ken.Garlington@computer.org> wrote:
> "Robert Dewar" <robert_dewar@my-deja.com> wrote in message
> news:8udce8$1qi$1@nnrp1.deja.com...
>
> : I would write the above as:
> :
> :    procedure Conditional_Swap (A, B : in out Integer) is
> :    begin
> :       if A < B then
> :          declare
> :             Temp : constant Integer := A;
> :          begin
> :             A := B;
> :             B := Temp;
> :          end;
> :       end if;
> :    end Conditional_Swap;
>
> This causes the *smaller* value to end up in A and the
*larger* value to end
> up in B? Now I REALLY feel like a beginning student!


Well this anomoly had already been pointed out, so there was
no point in repeating it, note that the above is advertised
as a rewriting of "the above code", and I did not want to
fix this problem since it would have confused the style
points I was making.

> Actually, I would also nitpick the choice of "Temp," when
> better options are available (Initial_A, or the really
> expressive Initial_Value_of_A).

I disagree, this is long-nameitis carried to absurd extremes.
Rewritten the way I had it the life time of Temp is three
lines and it is obvious that it is initialized with the value
of A. It merely obfuscates code to use long names where they
do not help the reader. I actually think a more appropriate
choice of name would have been T :-)



Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-09  0:00         ` Marin David Condic
@ 2000-11-09  0:00           ` Robert Dewar
  2000-11-10  0:00             ` Larry Kilgallen
  2000-11-10  1:58           ` Ken Garlington
  1 sibling, 1 reply; 64+ messages in thread
From: Robert Dewar @ 2000-11-09  0:00 UTC (permalink / raw)


In article <3A0ABE18.24CACAFB@acm.org>,
  Marin David Condic <mcondic.nospam@acm.org> wrote:
> I'd agree with the "Necessary/Not-Sufficient" part of this
> statement, but to say that "It Works" is not the MOST
> important thing, I think is a mistake.

Your pickup truck example is actually instructive, but you
mispresent it. Sure the pickup truck must run, but must it
work 100%? If you say yes, I am sorry to tell you that in
practice all trucks and cars are delivered with defects.
Hopefully not serious enough to stop them running, but
certainly they are not 100% "correct".

And that is an apt analogy. Software is almost never 100%
correct if it is of any complexity, it works well enough on
an initial delivery, but will undergo a long and labor
intensive history of bug fixing, modification and improvement.

Sure, the software must work reasonably well, but to focus on
correct function to the exclusion of maintainability will result
in software that does not necessarily work any better on initial
delivery, and for SURE will start to work worse as it is
maintained.

OK, if we are talking safety-critical certified software, then
correct function does indeed become paramount, but in most
applcations this is definitely a distortion.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-09  4:58           ` Robert Dewar
@ 2000-11-09  0:00             ` Ken Garlington
  2000-11-09  0:00             ` John English
  1 sibling, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-09  0:00 UTC (permalink / raw)


"Robert Dewar" <robert_dewar@my-deja.com> wrote in message
news:8udasq$kn$1@nnrp1.deja.com...

: I suppose one could at least introduce SOME notion of
: aesthetics, e.g. evaluate layout against precanned style
: rules, or evaluate complexity using established metrics.

Given the presumed use of Ada to support highly reliable systems, I'd
especially like to see a robot of this type attempt to "break" the solution
by feeding it invalid inputs, etc. It might not be possible for something
this simple, but once you get up to more complete solutions, I think bonus
points should be awarded to solutions that implement error recovery, etc.






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

* Re: if statements
  2000-11-09  5:24       ` Robert Dewar
  2000-11-09  0:00         ` Marin David Condic
@ 2000-11-09  0:00         ` Ken Garlington
  2000-11-09  0:00           ` Robert Dewar
  1 sibling, 1 reply; 64+ messages in thread
From: Ken Garlington @ 2000-11-09  0:00 UTC (permalink / raw)


"Robert Dewar" <robert_dewar@my-deja.com> wrote in message
news:8udce8$1qi$1@nnrp1.deja.com...

: I would write the above as:
:
:    procedure Conditional_Swap (A, B : in out Integer) is
:    begin
:       if A < B then
:          declare
:             Temp : constant Integer := A;
:          begin
:             A := B;
:             B := Temp;
:          end;
:       end if;
:    end Conditional_Swap;

This causes the *smaller* value to end up in A and the *larger* value to end
up in B? Now I REALLY feel like a beginning student!

Here's the problem statement as I understand it:

: >   "Exercise 4.1: Write an if statement which will swap the values of
: >    variables A and B if necessary so that the smaller value ends up in
: >    A and the larger value ends up in B."

I always thought that a test such as "A < B" was true only if A was
*already* smaller than B (in which case you shouldn't do a swap, right?).

: I don't think that will make the plane crash :-)

Well, if my requirement is to deploy a spin chute if the spin rate is larger
than X degrees/sec, and I write

  if Spin_Rate < X then
    Deploy_Chute;
  end if;

I certainly *might* crash a plane! :)

: Though it
: may be considered pedantic. As I say, bringing out the full
: weight of careful style considerations for such a simple
: program is overkill, but you have to start somewhere.

Actually, I would also nitpick the choice of "Temp," when better options are
available (Initial_A, or the really expressive Initial_Value_of_A).






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

* Re: if statements
  2000-11-09  4:58           ` Robert Dewar
  2000-11-09  0:00             ` Ken Garlington
@ 2000-11-09  0:00             ` John English
  1 sibling, 0 replies; 64+ messages in thread
From: John English @ 2000-11-09  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> I do wonder if we go about things the right way by emphasizing
> that the only criterion for a good program is that it works.
> I realize that grading programs is a huge pain, but imagine
> if we taught people to play the piano, and graded them merely
> by using a robot that figured out if they pressed the right
> keys :-)

Mmm. The reason we're doing it this way is to force the students
to do some work before the assignment deadline (after previous
painful instances where people have apparently opened a textbook
for the first time the night before -- ultimately their own problem,
but painful nevertheless) but without the avalanche of marking that
this would cause. The bulk of the marks are still awarded on the
basis of a manually-assessed submission at the end of the course.
It's not perfect, but dealing with groups of up to 200 never is.
Oh for the time to give one-to-one tuition... :-(

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: if statements
  2000-11-09  5:24       ` Robert Dewar
@ 2000-11-09  0:00         ` Marin David Condic
  2000-11-09  0:00           ` Robert Dewar
  2000-11-10  1:58           ` Ken Garlington
  2000-11-09  0:00         ` Ken Garlington
  1 sibling, 2 replies; 64+ messages in thread
From: Marin David Condic @ 2000-11-09  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> If there is one thing in the Ada world that one expects it is
> to get away from th idea that the MOST important thing about
> code is that "it WORKS". Ada is about building reliable,
> maintainable software, and the fact that it works is necessary
> but no where *near* sufficient.

I'd agree with the "Necessary/Not-Sufficient" part of this statement,
but to say that "It Works" is not the MOST important thing, I think is a
mistake. There are a lot of important qualities I excpect from my
pick-up truck. If I go out front, stick the key in it and it doesn't
start, then there isn't much point in having it take up all that space
in my driveway that could be occupied by nice, useful, air. "Works" is
the only excuse for having bothered to build it at all. Along the way,
we probably add things like "Looks Sharp", "Safe To Operate", "More
Power (argh! argh! argh!)" "Hold A Ton Of Bricks" as other valuable and
important requirements, but take away any of those things and having the
truck might still be justifiable.

I've seen lots of *REAL CRAP* software that had the quality of "Works"
and found it could still be profitable to use it. I've picked up
unbelievably (well, maybe believably) bad C code that reliably performed
some function and incorporated it into a product with the eye towards
freezing it there, never to be touched again - under penalty of law.
Should the programmer be spanked? Yup. Real hard and real often. "Bad
Programmer! No Cookie!" But the quality of "Works" was still there.

MDC
--
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

    "Giving money and power to Government is like giving whiskey
    and car keys to teenage boys."

        --   P. J. O'Rourke
======================================================================






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

* Re: if statements
@ 2000-11-09  0:00 James Hassett
  2000-11-10  0:02 ` Robert Dewar
  0 siblings, 1 reply; 64+ messages in thread
From: James Hassett @ 2000-11-09  0:00 UTC (permalink / raw)
  To: comp.lang.ada

Ken Garlington <Ken.Garlington@computer.org> wrote:
> "Robert Dewar" <robert_dewar@my-deja.com> wrote in message
> news:8udce8$1qi$1@nnrp1.deja.com...
> 
> : I would write the above as:
> :
> :    procedure Conditional_Swap (A, B : in out Integer) is
> :    begin
> :       if A < B then
> :          declare
> :             Temp : constant Integer := A;
> :          begin
> :             A := B;
> :             B := Temp;
> :          end;
> :       end if;
> :    end Conditional_Swap;
> 
> This causes the *smaller* value to end up in A and the *larger* value to end
> up in B? Now I REALLY feel like a beginning student!
> 
> Here's the problem statement as I understand it:
> 
> : >   "Exercise 4.1: Write an if statement which will swap the values of
> : >    variables A and B if necessary so that the smaller value ends up in
> : >    A and the larger value ends up in B."
> 
> I always thought that a test such as "A < B" was true only if A was
> *already* smaller than B (in which case you shouldn't do a swap, right?).

This defect has been carried forward in a surprising number of
posts, so I'm glad Ken caught it.  I believe it originated with
Daniel Allex, who wrote

> procedure Swap ( A,    B : in out Integer ) is
>      Temp : Integer := 0;
>    begin
>      if A <= B then
>          Temp := A;
>          A := B;
>          B := Temp;
>      end if;
>    end;

When I saw this "solution" offered, I thought maybe Daniel had
deliberately introduced the bug to ensure that if the student
simply handed in the offered solution, it would be wrong, but if he
bothered to try to understand it, he would likely find and correct
the error.  I thought about posting a correction, but decided that
maybe the correction was best left as an exercise for the student.

I was surprised that Robert didn't catch this defect, but the
discussion has drifted far from the original problem posed, and
it is easy to lose sight of such (critical) details as which way
the test ought to go.  We rarely need to forgive Robert for
technical errors, so I'm willing to cut him some slack here.

Another problem (as noted by some already) is that the original
problem asked for an if statement, not a procedure, so we would
need to trim Robert's solution down to the if statement.  (The
solution offered by Daniel doesn't trim down as neatly, because
the Temp declaration gets lost.)

Otherwise, I certainly agree with Robert's critique of Daniel's
solution.

- Jim Hassett





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

* Re: if statements
  2000-11-08  0:00       ` Wes Groleau
@ 2000-11-09  3:43         ` Ken Garlington
  0 siblings, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-09  3:43 UTC (permalink / raw)


"Wes Groleau" <wwgrol@ftw.rsc.raytheon.com> wrote in message
news:3A098A36.BEAB956A@ftw.rsc.raytheon.com...
: J
: > > Temp := B;
: > > B    := Integer'Min (A, B)
: > > A    := Integer'Max (A, Temp);
: > >
: > > Oops, the "if" he wanted is missing.  :-)
: >
: > Hmm. I'll change the test program to use a hidden record type
: > instead of an Integer with smart people like you around... ;-)
:
: But then you'd also have to change the words that say
: "swap A and B if B is _larger_"

Not if he defines ">"!





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

* Re: if statements
  2000-11-08  0:00             ` Alejandro Villanueva
  2000-11-08  0:00               ` Georg Bauhaus
@ 2000-11-09  3:50               ` Ken Garlington
  1 sibling, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-09  3:50 UTC (permalink / raw)


"Alejandro Villanueva" <190921@cepsz.unizar.es> wrote in message
news:3A09A13F.CE7DF6EF@cepsz.unizar.es...
: Alejandro R. Mosteo wrote:
:
: > Hello. Here in Spain, my university (in Zaragoza) uses Ada as the
: > programming languaje in several subjects (all of them half academic
: > year duration):
: >
:
: Well, if you see my address you will see that I'm from the same Uni that
you...
:
: My final project is also with Ada95 running under RTEMS (the degree is
: industrial engineering, 5-year long)
:
: And now...
:
: procedure Swap (A, B: in out Integer) is
:    C: Integer;
: begin
:    if A > B then
:       C := B;
:       B := A;
:       A := C;
:    end if;
: end Swap;

Of course, this would violate the implied requirement that no code surround
the "if" statement. How about (assuming A and B are Integer):

if A > B then
  declare
    Original_B : constant Integer := B;
  begin
    B := A;
    A := Original_B;
  end;
end if;





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

* Re: if statements
  2000-11-08  0:00     ` Alejandro Villanueva
  2000-11-08  0:00       ` Daniel Allex
@ 2000-11-09  3:54       ` Ken Garlington
  2000-11-09  5:24       ` Robert Dewar
  2 siblings, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-09  3:54 UTC (permalink / raw)


"Alejandro Villanueva" <190921@cepsz.unizar.es> wrote in message
news:3A09A39F.2822C01B@cepsz.unizar.es...
: Robert Dewar wrote:
:
: > In article <3A078B6F.D34B024B@erols.com>,
: >   Daniel Allex <dallex@erols.com> wrote:
: > > procedure Swap ( A,     B : in out Integer ) is
: > >       Temp : Integer := 0;
: > >    begin
: > >       if A <= B then
: > >          Temp := A;
: > >          A := B;
: > >          B := Temp;
: > >       end if;
: > >    end;
: >
: > Finally he gets someone to do his homework for him, though
: > not very competently (this looks like another student
: > tackling the excercise for the first time :-)
:
: Robert, you do always the same... why do you have to say that?
: It IS a valid solution, and not the solution a geek will give after all.
: And MOST important: it WORKS!

Well, actually, it *doesn't* work for the stated problem:

: >   "Exercise 4.1: Write an if statement which will swap the values of
: >    variables A and B if necessary so that the smaller value ends up in
: >    A and the larger value ends up in B."

It also does one or more unnecessary things (this will be left as an
exercise for the student :)





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

* Re: if statements
  2000-11-08  0:00         ` John English
  2000-11-08  0:00           ` Georg Bauhaus
@ 2000-11-09  4:58           ` Robert Dewar
  2000-11-09  0:00             ` Ken Garlington
  2000-11-09  0:00             ` John English
  1 sibling, 2 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-09  4:58 UTC (permalink / raw)


In article <3A09456E.D1F1D3A2@bton.ac.uk>,
  John English <je@bton.ac.uk> wrote:
> You misunderstand. The robot embeds submitted assignment
> statements in a test program, runs the result against a set of
> test cases, and checks that the output is correct wrt a
> standard solution. So it would be quite happy with the xor
> solution, too. The reference to the robot being unimpressed is
> merely to do with the fact that I haven't yet managed to
> program a sense of aesthetics into it. If anyone has a
> solution to that, *I'd* be deeply impressed... :-)

OK, yes, I did misunderstand. I thought "deeply unimpressed"
was a code phrase for "completely confused" :-)

I do wonder if we go about things the right way by emphasizing
that the only criterion for a good program is that it works.
I realize that grading programs is a huge pain, but imagine
if we taught people to play the piano, and graded them merely
by using a robot that figured out if they pressed the right
keys :-)

I suppose one could at least introduce SOME notion of
aesthetics, e.g. evaluate layout against precanned style
rules, or evaluate complexity using established metrics.


Sent via Deja.com http://www.deja.com/
Before you buy.



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

* Re: if statements
  2000-11-08  0:00     ` Alejandro Villanueva
  2000-11-08  0:00       ` Daniel Allex
  2000-11-09  3:54       ` Ken Garlington
@ 2000-11-09  5:24       ` Robert Dewar
  2000-11-09  0:00         ` Marin David Condic
  2000-11-09  0:00         ` Ken Garlington
  2 siblings, 2 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-09  5:24 UTC (permalink / raw)


In article <3A09A39F.2822C01B@cepsz.unizar.es>,
  Alejandro Villanueva <190921@cepsz.unizar.es> wrote:
> Robert Dewar wrote:
>
> > In article <3A078B6F.D34B024B@erols.com>,
> >   Daniel Allex <dallex@erols.com> wrote:
> > > procedure Swap ( A,     B : in out Integer ) is
> > >       Temp : Integer := 0;
> > >    begin
> > >       if A <= B then
> > >          Temp := A;
> > >          A := B;
> > >          B := Temp;
> > >       end if;
> > >    end;
> >
> > Finally he gets someone to do his homework for him, though
> > not very competently (this looks like another student
> > tackling the excercise for the first time :-)
> >
>
> Robert, you do always the same... why do you have to say that?
> It IS a valid solution, and not the solution a geek will give
> after all. And MOST important: it WORKS!

If there is one thing in the Ada world that one expects it is
to get away from th idea that the MOST important thing about
code is that "it WORKS". Ada is about building reliable,
maintainable software, and the fact that it works is necessary
but no where *near* sufficient.

Let's look at the example above and see what's wrong with it

> > > procedure Swap ( A,     B : in out Integer ) is
> > >       Temp : Integer := 0;
> > >    begin
> > >       if A <= B then
> > >          Temp := A;
> > >          A := B;
> > >          B := Temp;
> > >       end if;
> > >    end;

First, the big chunk of white space between A, and B seems
quite gratuitous, I cannot think of any good excuse for it.

Second, the initialization of Temp is confusing and unnecessary.

Third, the indentation is non-standard. The RM suggests a
standard indentation, it should be used almost always.

Fourth, it is good practice to always put end labels for
procedures.

Fifth, Temp is a variable, when it should be a constant. People
very much overuse variables.

Sixth, Temp is defined too globally, you want to be easily
able to see that Temp is just a local variable for the Swap
and that its value is dead on exit.

Seventh, the name Swap is a very poor choice for the procedure,
since this is not what it does.

Eighth, why on earth swap the elements if they are equal, that
seems silly!

I would write the above as:

   procedure Conditional_Swap (A, B : in out Integer) is
   begin
      if A < B then
         declare
            Temp : constant Integer := A;
         begin
            A := B;
            B := Temp;
         end;
      end if;
   end Conditional_Swap;

I actually would prefer as a matter of style to introduce
a separate procedure called Swap, so that the guts of the
procedure would look like

    if A < B then
       Swap (A, B);
    end if;

Well all this is of course overkill for such a trivial
statement (one must wonder why anyone who finds it less
trouble to write a message to CLA than to solve such a
trivial problem themselves), but in fact the lesson to
be learned even at a very trivial level is precisely the
sort of attitudes to correct style that can then hopefully
scale up to larger examples.

So there you are, Robert's complete solution to the problem
first posed (after the deadline unfortunately :-)

I don't think that will make the plane crash :-) Though it
may be considered pedantic. As I say, bringing out the full
weight of careful style considerations for such a simple
program is overkill, but you have to start somewhere.


Sent via Deja.com http://www.deja.com/
Before you buy.



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

* Re: if statements
  2000-11-09  0:00           ` Robert Dewar
@ 2000-11-10  0:00             ` Larry Kilgallen
  0 siblings, 0 replies; 64+ messages in thread
From: Larry Kilgallen @ 2000-11-10  0:00 UTC (permalink / raw)


In article <8ufde1$ogf$1@nnrp1.deja.com>, Robert Dewar <robert_dewar@my-deja.com> writes:
> In article <3A0ABE18.24CACAFB@acm.org>,
>   Marin David Condic <mcondic.nospam@acm.org> wrote:
>> I'd agree with the "Necessary/Not-Sufficient" part of this
>> statement, but to say that "It Works" is not the MOST
>> important thing, I think is a mistake.
> 
> Your pickup truck example is actually instructive, but you

> Sure, the software must work reasonably well, but to focus on
> correct function to the exclusion of maintainability will result
> in software that does not necessarily work any better on initial
> delivery, and for SURE will start to work worse as it is
> maintained.

Don't worry, Robert.  Marin will no longer take an absolutist
position regarding maintainability being of secondary interest
once he finds that he has to remove the engine from the truck
to refill the fuel tank :-)




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

* Re: if statements
  2000-11-09  0:00 James Hassett
@ 2000-11-10  0:02 ` Robert Dewar
  0 siblings, 0 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-10  0:02 UTC (permalink / raw)


In article <200011091641.KAA05352@alonzo.tds-eagan.lmco.com>,
  comp.lang.ada@ada.eu.org wrote:

> We rarely need to forgive Robert for
> technical errors, so I'm willing to cut him some slack here.

Ahem! Message 22/77 in my newsreader (posted by Ken Garlington
two days ago, first pointed out this obvious error). Not only
do I of course notice an error like this, but I also read the
entire thread before answering :-) :-)

As I made clear, I was showing how to rewrite the offered
solution (I quoted the original, and referred to the "above").
Since I was talking about style changes, I did not want to
confuse things by making a substantive change since I assumed
that everyone reading the thread was fully aware of it given
Ken's post!

By the way, you started a new thread (at least that's what
my newsreader says) instead of following up the previous
thread with this title (perhaps you are trying to foil those
of us who do use threaded newsreaders, and are careful to
read all messages in a thread before replying .... :-)

So, no slack needed!

> Another problem (as noted by some already) is that the
> original problem asked for an if statement, not a procedure,
> so we would need to trim Robert's solution down to the if
> statement.

Again, I was not trying to convince the doubting CLA hoardes
that Robert Dewar could have successfully handed in a correct
solution to this complex assignment, but rather I was making
style comments on the particular procedure previously posted :-)


Sent via Deja.com http://www.deja.com/
Before you buy.



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

* Re: if statements
  2000-11-09  0:00           ` Robert Dewar
@ 2000-11-10  0:12             ` Ehud Lamm
  2000-11-10  2:09             ` Ken Garlington
  2000-11-20  0:00             ` Wes Groleau
  2 siblings, 0 replies; 64+ messages in thread
From: Ehud Lamm @ 2000-11-10  0:12 UTC (permalink / raw)



Robert Dewar <robert_dewar@my-deja.com> wrote
> I disagree, this is long-nameitis carried to absurd extremes.
> Rewritten the way I had it the life time of Temp is three
> lines and it is obvious that it is initialized with the value
> of A. It merely obfuscates code to use long names where they
> do not help the reader. I actually think a more appropriate
> choice of name would have been T :-)
>

Sometimes I just love you!

Please help us get rid of names like
long_name_instead_of_temp_which_R_Dewar_would_have_called_T

What's important is readbility. Meaningful names are important. Long length
is really not a substitute for good names. Most often, the reverse.


--
Ehud Lamm   mslamm@mscc.huji.ac.il
http://www.cafepress.com/ehudlamm <==  Some art








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

* Re: if statements
  2000-11-09  0:00         ` Marin David Condic
  2000-11-09  0:00           ` Robert Dewar
@ 2000-11-10  1:58           ` Ken Garlington
  2000-11-10  3:53             ` Robert Dewar
  1 sibling, 1 reply; 64+ messages in thread
From: Ken Garlington @ 2000-11-10  1:58 UTC (permalink / raw)


"Marin David Condic" <mcondic.nospam@acm.org> wrote in message
news:3A0ABE18.24CACAFB@acm.org...
: Robert Dewar wrote:
:
: > If there is one thing in the Ada world that one expects it is
: > to get away from th idea that the MOST important thing about
: > code is that "it WORKS". Ada is about building reliable,
: > maintainable software, and the fact that it works is necessary
: > but no where *near* sufficient.
:
: I'd agree with the "Necessary/Not-Sufficient" part of this statement,
: but to say that "It Works" is not the MOST important thing, I think is a
: mistake. There are a lot of important qualities I excpect from my
: pick-up truck. If I go out front, stick the key in it and it doesn't
: start, then there isn't much point in having it take up all that space
: in my driveway that could be occupied by nice, useful, air.

What if your choice was

(a) Occasionally doesn't work (i.e. doesn't start on cold days)
(b) Works (starts) every time, but occasionally the tires fail, you flip
over and die?

: "Works" is
: the only excuse for having bothered to build it at all. Along the way,
: we probably add things like "Looks Sharp", "Safe To Operate", "More
: Power (argh! argh! argh!)" "Hold A Ton Of Bricks" as other valuable and
: important requirements, but take away any of those things and having the
: truck might still be justifiable.
:
: I've seen lots of *REAL CRAP* software that had the quality of "Works"
: and found it could still be profitable to use it. I've picked up
: unbelievably (well, maybe believably) bad C code that reliably performed
: some function and incorporated it into a product with the eye towards
: freezing it there, never to be touched again - under penalty of law.
: Should the programmer be spanked? Yup. Real hard and real often. "Bad
: Programmer! No Cookie!" But the quality of "Works" was still there.
:
: MDC
: --
: ======================================================================
: Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
: Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
: Visit my web site at:  http://www.mcondic.com/
:
:     "Giving money and power to Government is like giving whiskey
:     and car keys to teenage boys."
:
:         --   P. J. O'Rourke
: ======================================================================
:
:





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

* Re: if statements
  2000-11-09  0:00           ` Robert Dewar
  2000-11-10  0:12             ` Ehud Lamm
@ 2000-11-10  2:09             ` Ken Garlington
  2000-11-20  0:00               ` Wes Groleau
  2000-11-20  0:00             ` Wes Groleau
  2 siblings, 1 reply; 64+ messages in thread
From: Ken Garlington @ 2000-11-10  2:09 UTC (permalink / raw)


"Robert Dewar" <robert_dewar@my-deja.com> wrote in message
news:8ufd4n$obj$1@nnrp1.deja.com...

: > Actually, I would also nitpick the choice of "Temp," when
: > better options are available (Initial_A, or the really
: > expressive Initial_Value_of_A).
:
: I disagree, this is long-nameitis carried to absurd extremes.
: Rewritten the way I had it the life time of Temp is three
: lines and it is obvious that it is initialized with the value
: of A. It merely obfuscates code to use long names where they
: do not help the reader. I actually think a more appropriate
: choice of name would have been T :-)

However, it's obvious it's "temporary" (i.e. has a limited scope) just from
where it's declared. The name doesn't add any value. I think what you may
actually be saying is that "everyone understands the pattern for swapping
two variables, so there's no point in worrying about the name." I would have
agreed with this, EXCEPT for the earlier post in this thread* that indicated
that beginning students DIDN'T always grasp the "obviousness" of this
pattern. Therefore, for those people, Initial_A may be worth the five extra
keystrokes.

* I'm referring to the discussion about wine and beer, which for some reason
I was able to remember :)

P. S. Here's how I would explain the swap pattern: "Imagine picking up two
very large steins of beer. Now, think about having to exchange the two
steins between your left and right hands. You probably have to put one of
the steins on the table, move the other stein from one hand to the
(now-empty) other hand, then pick back up the first stein from the table.
'A' and 'B' are your hands, 'Temp' is the table."





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

* Re: if statements
  2000-11-10  1:58           ` Ken Garlington
@ 2000-11-10  3:53             ` Robert Dewar
  0 siblings, 0 replies; 64+ messages in thread
From: Robert Dewar @ 2000-11-10  3:53 UTC (permalink / raw)


In article <RCIO5.9726$pq3.778108@news.flash.net>,
  "Ken Garlington" <Ken.Garlington@computer.org> wrote:

> What if your choice was
>
> (a) Occasionally doesn't work (i.e. doesn't start on cold
>     days)
> (b) Works (starts) every time, but occasionally the tires
>     fail, you flip over and die?

to choose a far-fetched example :-) :-)

very nice Ken!



Sent via Deja.com http://www.deja.com/
Before you buy.



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

* Re: if statements
  2000-11-03 14:42 sc297
                   ` (3 preceding siblings ...)
  2000-11-07  0:00 ` John English
@ 2000-11-10  6:09 ` DJack143
  4 siblings, 0 replies; 64+ messages in thread
From: DJack143 @ 2000-11-10  6:09 UTC (permalink / raw)


if you have not gotten a reply yet:

Make the declaration:

a, b, temp : type -- whatever you type is

begin
   ---your code here
   if  a > b then
      temp =: a;
      a := b; 
      b := temp;
   end if;
... -- more code here
end;

--this will work but a procedure would probably be better.

good luck

don





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

* Re: if statements
  2000-11-03  0:00 ` David Starner
  2000-11-07  0:00   ` John English
@ 2000-11-13  0:00   ` Dale Pontius
  1 sibling, 0 replies; 64+ messages in thread
From: Dale Pontius @ 2000-11-13  0:00 UTC (permalink / raw)


In article <8tup70$9281@news.cis.okstate.edu>,
        dvdeug@x8b4e516e.dhcp.okstate.edu (David Starner) writes:
> On Fri, 03 Nov 2000 14:42:28 +0000, sc297 wrote:
>>can anyone show me an if statement that will swap the values of A and B,
>>if A is the greater value
>
> Yes. I can, and I bet your teacher can too.
>
Over in comp.arch they treat 'homework' questions a little differently
than here. It seems to be an invitation to come up with the most
reasonable, yet outlandish answers possible. Makes for fun reading.

Dale Pontius
NOT speaking for IBM




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

* Re: if statements
  2000-11-14  0:00 if statements Duncan Sands
@ 2000-11-14  0:00 ` Ken Garlington
  0 siblings, 0 replies; 64+ messages in thread
From: Ken Garlington @ 2000-11-14  0:00 UTC (permalink / raw)


"Duncan Sands" <sands@topo.math.u-psud.fr> wrote in message
news:E13vbW9-0000DP-00@Baldrick...

: Here
: is a code snippet using the Beer oriented methodology (which naturally
: reflects the life style of many students) that swaps the values of two
: integers A and B if A is the greater value.  It uses an if statement.

Well, this doesn't seem right. In particular:

:       type Beer is new Integer;
-- this should be Natural; the -1 trick is no excuse (see below).

:       type Hand is (Left_Hand, Right_Hand);
-- this should be type What_I_Call_My_Hands
-- there should be a type Hand which is an access to Beer_Mug (see below)
-- there should be a type Hands which is an array (What_I_Call_My_Hands) of
Hand.

:       Mugs : array (Hand) of Beer_Mug;
-- this should be two separate mugs, since a particular mug is not
intrinsically tied to a particular Hand

:       type Table is record
:          Mug : Beer_Mug;
:       end record;
-- clearly, Table should be an array (or set) of Beer_Mugs, since a Table
could
-- hold more than one Beer_Mug.

:       procedure Move_Mug (From, To : Hand) is
:       begin
:          if From = To or Mugs (From).Refreshing_Fluid = -1 then
-- Ack! Arbitrary constants! Much better to allow a Hand to be set to null
-- explicitly when it isn't accessing anything.
-- Also, need to check that To is empty.

:             raise Tasking_Error;
-- should really declare a new Drunken_Fool exception rather than using
-- predefined exception







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

* Re: if statements
@ 2000-11-14  0:00 Duncan Sands
  2000-11-14  0:00 ` Ken Garlington
  0 siblings, 1 reply; 64+ messages in thread
From: Duncan Sands @ 2000-11-14  0:00 UTC (permalink / raw)
  To: comp.lang.ada

David Starner (speaking for IBM) writes:
>> On Fri, 03 Nov 2000 14:42:28 +0000, sc297 wrote:
>>>can anyone show me an if statement that will swap the values of A and B,
>>>if A is the greater value
>>
>> Yes. I can, and I bet your teacher can too.
>>
>Over in comp.arch they treat 'homework' questions a little differently
>than here. It seems to be an invitation to come up with the most
>reasonable, yet outlandish answers possible. Makes for fun reading.

That is an irresponsable attitude, and we should all blow our noses
at it.  We should instead show how the use of ADA allows us to write
a solution in a way that naturally reflects the problem domain.  Here
is a code snippet using the Beer oriented methodology (which naturally
reflects the life style of many students) that swaps the values of two
integers A and B if A is the greater value.  It uses an if statement.

if True then
   declare
      type Beer is new Integer;

      type Beer_Mug is record
         Refreshing_Fluid : Beer;
      end record;

      procedure Put_Beer_Into_Mug (
        Fluid : in     Beer;
        Mug   : in out Beer_Mug
      ) is
      begin
         Mug.Refreshing_Fluid := Fluid;
      end;

      function Make_Beer (X : Integer) return Beer is
      begin
         return Beer (X);
      end;

      procedure Burp_At_Wimpy_C_Programmers is
         task type Int_Swapper (X, Y : access Integer);
         task body Int_Swapper is
            type Int_Pointer is access all Integer;
            Z_Value : aliased Integer;
            Z : Int_Pointer := Z_Value'Access;
         begin
            Z.all := X.all;
            X.all := Y.all;
            Y.all := Z.all;
            A := X.all;
            B := Y.all;
         end;
         Swapper : Int_Swapper (new Integer' (A), new Integer' (B));
      begin
         null;
      end;

      procedure Drink_Beer (Fluid : in out Beer) is
      begin
         Fluid := 0;
         Burp_At_Wimpy_C_Programmers;
      end;

      type Hand is (Left_Hand, Right_Hand);

      Mugs : array (Hand) of Beer_Mug;

      Right_Hand_Mug : Beer_Mug renames Mugs (Left_Hand);
      Left_Hand_Mug  : Beer_Mug renames Mugs (Right_Hand);

      type Table is record
         Mug : Beer_Mug;
      end record;

      A_Convenient_Table : Table;

      procedure Move_Mug (From, To : Hand) is
      begin
         if From = To or Mugs (From).Refreshing_Fluid = -1 then
            raise Tasking_Error;
         else
            Mugs (To) := Mugs (From);
            Mugs (From).Refreshing_Fluid := -1; -- Null mug
         end if;
      end;

      procedure Move_Mug_To_Table (Member : Hand) is
      begin
         A_Convenient_Table.Mug := Mugs (Member);
         Mugs (Member).Refreshing_Fluid := -1;
      end;

      procedure Pick_Up_Mug (Member : Hand) is
      begin
         Mugs (Member) := A_Convenient_Table.Mug;
         A_Convenient_Table.Mug.Refreshing_Fluid := -1;
      end Pick_Up_Mug;

      procedure Pour_Beer (
        From : in out Beer_Mug;
        To   :    out Integer
      ) is
      begin
         To := Integer (From.Refreshing_Fluid);
         From.Refreshing_Fluid := 0;
      end;

      function Weight (Member : Hand) return Float is
         Density_Of_Beer : constant Float := 3.799237428472040235723029;
         Weight_Of_Hand  : constant Float := 2.369000038490274207765490;
      begin
         return Density_Of_Beer * Float (Mugs (Member).Refreshing_Fluid) +
           Weight_Of_Hand;
      end;
      
      subtype Excess is Float range 0.0 .. Float'Last;

      Excess_Weight : Excess;
   begin
      Put_Beer_Into_Mug (
        Fluid => Make_Beer (A),
        Mug   => Left_Hand_Mug
      );

      Put_Beer_Into_Mug (
        Fluid => Make_Beer (B),
        Mug   => Right_Hand_Mug
      );
      
      -- Round to one decimal place to compensate for experimental error
      -- in weighing the beer
      Excess_Weight := Float (
        Integer (100.0 * (Weight (Left_Hand) - Weight (Right_Hand)))
      ) / 100.0;
      Drink_Beer (Left_Hand_Mug.Refreshing_Fluid);
      Drink_Beer (Right_Hand_Mug.Refreshing_Fluid);
   exception
      when Constraint_Error => -- Beer off?  Swap mugs and try again
         Move_Mug_To_Table (Left_Hand);
         Move_Mug (
           From => Right_Hand,
           To   => Left_Hand
         );
         Pick_Up_Mug (Right_Hand);
         Excess_Weight := Float (
           Integer (100.0 * (Weight (Left_Hand) - Weight (Right_Hand)))
         ) / 100.0;
         Pour_Beer (
           From => Mugs (Right_Hand),
           To   => A
         );
         Pour_Beer (
           From => Mugs (Left_Hand),
           To   => B
         );
   end;
else
   -- Memory corruption due to solar radiation
   raise Storage_Error;
end if;





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

* Re: if statements
  2000-11-10  2:09             ` Ken Garlington
@ 2000-11-20  0:00               ` Wes Groleau
  0 siblings, 0 replies; 64+ messages in thread
From: Wes Groleau @ 2000-11-20  0:00 UTC (permalink / raw)



> 'A' and 'B' are your hands, 'Temp' is the table."

So we should have written  Table : xxxx := A;

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau




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

* Re: if statements
  2000-11-09  0:00           ` Robert Dewar
  2000-11-10  0:12             ` Ehud Lamm
  2000-11-10  2:09             ` Ken Garlington
@ 2000-11-20  0:00             ` Wes Groleau
  2000-11-21  0:00               ` Robert Dewar
  2 siblings, 1 reply; 64+ messages in thread
From: Wes Groleau @ 2000-11-20  0:00 UTC (permalink / raw)



> I disagree, this is long-nameitis carried to absurd extremes.

My turn to get pedantic.  -itis means "inflammation of"
-osis means "presence of"


-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau




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

* Re: if statements
  2000-11-20  0:00             ` Wes Groleau
@ 2000-11-21  0:00               ` Robert Dewar
  2000-11-22  0:00                 ` Wes Groleau
  0 siblings, 1 reply; 64+ messages in thread
From: Robert Dewar @ 2000-11-21  0:00 UTC (permalink / raw)


In article <3A196194.6D3B2D8C@ftw.rsc.raytheon.com>,
  Wes Groleau <wwgrol@ftw.rsc.raytheon.com> wrote:
>
> > I disagree, this is long-nameitis carried to absurd
extremes.
>
> My turn to get pedantic.  -itis means "inflammation of"
> -osis means "presence of"


I definitely regard long-nameitis as an infectious disease, and
choose that suffix to express my opinion :-)


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: if statements
  2000-11-21  0:00               ` Robert Dewar
@ 2000-11-22  0:00                 ` Wes Groleau
  0 siblings, 0 replies; 64+ messages in thread
From: Wes Groleau @ 2000-11-22  0:00 UTC (permalink / raw)


> > My turn to get pedantic.  -itis means "inflammation of"
> > -osis means "presence of"
> 
> I definitely regard long-nameitis as an infectious disease, and
> choose that suffix to express my opinion :-)

But it's not the long name that's inflamed, it's the reader.
:-) :-)


-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau




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

end of thread, other threads:[~2000-11-22  0:00 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-14  0:00 if statements Duncan Sands
2000-11-14  0:00 ` Ken Garlington
  -- strict thread matches above, loose matches on Subject: below --
2000-11-09  0:00 James Hassett
2000-11-10  0:02 ` Robert Dewar
2000-11-03 14:42 sc297
2000-11-03  0:00 ` David Starner
2000-11-07  0:00   ` John English
2000-11-13  0:00   ` Dale Pontius
2000-11-03 16:09 ` Larry Kilgallen
2000-11-03  0:00   ` tmoran
2000-11-03  0:00     ` Larry Kilgallen
2000-11-06  0:00       ` Brian Orpin
2000-11-03  0:00     ` David Starner
2000-11-05  0:00       ` tmoran
2000-11-06  0:00         ` David Starner
2000-11-08  0:14           ` Alejandro R. Mosteo
2000-11-08  0:00             ` Alejandro Villanueva
2000-11-08  0:00               ` Georg Bauhaus
2000-11-09  3:50               ` Ken Garlington
2000-11-07  0:00         ` John English
2000-11-07  0:00     ` John English
2000-11-08  5:22       ` Ken Garlington
2000-11-06  0:00 ` Daniel Allex
2000-11-07  0:00   ` dmitry6243
2000-11-07  0:00     ` Jean-Pierre Rosen
2000-11-08  0:00       ` dmitry6243
2000-11-07  0:00   ` Robert Dewar
2000-11-07  0:00     ` Larry Kilgallen
2000-11-08  0:00     ` Alejandro Villanueva
2000-11-08  0:00       ` Daniel Allex
2000-11-09  3:54       ` Ken Garlington
2000-11-09  5:24       ` Robert Dewar
2000-11-09  0:00         ` Marin David Condic
2000-11-09  0:00           ` Robert Dewar
2000-11-10  0:00             ` Larry Kilgallen
2000-11-10  1:58           ` Ken Garlington
2000-11-10  3:53             ` Robert Dewar
2000-11-09  0:00         ` Ken Garlington
2000-11-09  0:00           ` Robert Dewar
2000-11-10  0:12             ` Ehud Lamm
2000-11-10  2:09             ` Ken Garlington
2000-11-20  0:00               ` Wes Groleau
2000-11-20  0:00             ` Wes Groleau
2000-11-21  0:00               ` Robert Dewar
2000-11-22  0:00                 ` Wes Groleau
2000-11-07  0:00   ` Wes Groleau
2000-11-08  0:00     ` John English
2000-11-08  0:00       ` Wes Groleau
2000-11-09  3:43         ` Ken Garlington
2000-11-07  0:00   ` Ken Garlington
2000-11-07  0:00     ` John English
2000-11-07  0:00       ` Robert Dewar
2000-11-08  0:00         ` John English
2000-11-08  0:00           ` Georg Bauhaus
2000-11-09  4:58           ` Robert Dewar
2000-11-09  0:00             ` Ken Garlington
2000-11-09  0:00             ` John English
2000-11-08  5:29       ` Ken Garlington
2000-11-08  0:00         ` John English
2000-11-08  0:00           ` Ken Garlington
2000-11-07  0:00   ` John English
2000-11-07  0:00 ` John English
2000-11-07  0:00   ` Robert Dewar
2000-11-10  6:09 ` DJack143

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