comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@callnetuk.com>
Subject: Re: Ok sorry, it is just a book gives no feedback.
Date: Wed, 3 Jan 2001 06:24:10 -0000
Date: 2001-01-03T06:24:10+00:00	[thread overview]
Message-ID: <931r2l$4ai5t$2@ID-25716.news.dfncis.de> (raw)
In-Reply-To: t4ug0qb63j7e4e@corp.supernews.co.uk

My own opinion is that, generally, functions should have no side effects
(whereas procedures generally do).

Ada does not enforce this principle (rightly, since it would be difficult
and sometimes wrong to do so), but it does disallow parameters of mode 'out'
and 'in out' for functions.

What is a 'side effect'? If a subprogram (a function or procedure), when
called, changes something outside itself, that is a side effect. The 'thing'
outside could be anything: a variable; a display or printer; a hard disk
floppy disk; etc. The 'change' is any kind of change whatever: modification
of a value; output of a character or string; writing or modifying a file;
etc. To be crystal clear, when I say a function 'should have no side
effects', I mean it should be written so that it never causes a side effect.

Some people do not respect (or even recognise) this principle, although
there are good arguments for it. I would suggest you follow the principle
unless you have a very good reason not to.

Briefly, the main argument for functions not having side effects is that an
expression such as A+B, where A and B are both function calls, may be
compiled to execute A first and then B, or B first and then A (depending on
complex optimisation rules within the compiler). If both A and B could both
cause a side effect which interferes with the other, it might then become
unpredictable what this expression does or returns: often a particularly
pernicious type of bug! Keeping functions free of side effects avoids the
possibility of this type of bug.

It follows from the above that the kind of side effect in a function which
you can get away with most easily is the kind which is carefully designed
never to interfere with any other function.

Do keep up your hard work with Ada. How did you get on with 'hangman'?

My advice with regard to books is: try to have a go with as many as you can,
before purchasing if possible. Does your place have a good library? Might
your friends lend you theirs for a while? Often you can get nowhere with
many books, and then find one which just seems to 'click'. (Clearly, that's
the one to buy!) Sometimes one book will explain one thing well, and another
book something else. (In which case, a photocopier might be handy.)

Happy New Year!

--
Nick Roberts
http://www.AdaOS.org


"Mark Pagdin" <mark_pagdin@lineone.net> wrote in message
news:t4ug0qb63j7e4e@corp.supernews.co.uk...
> Hi ya,
>
> I am sorry to keep on asking qns, but my text book doesn't give answers,
> i.e. it says things like write a procedure to do ......., but it doesn't
> actually give the answer at the back, so that if you are a bit stuck then
> everything won't work and you get demoralised.
>
> I want to become good at programming and I am prepared to work hard, but I
> am not brilliant at maths and I don't think thsi helps my plight.
>
> I am sorry to ask newbie qns here, but I am in a catch 22, or I think I
am.
>
> Anyway,
> Have a fun New Years,






  parent reply	other threads:[~2001-01-03  6:24 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-31 14:18 Ok sorry, it is just a book gives no feedback Mark Pagdin
2000-12-31 16:56 ` Robert Dewar
2000-12-31 16:57 ` Robert Dewar
2001-01-01 11:03 ` Tarjei T. Jensen
2001-01-02  9:23 ` Newsgroup cla (was: Ok sorry, it is just a book gives no feedback.) Anders Wirzenius
2001-01-02 10:44   ` Florian Weimer
2001-01-02 13:21     ` Larry Kilgallen
2001-01-02 12:45   ` Andrew Hately
2001-01-02 13:25     ` Florian Weimer
2001-01-02 22:26 ` Ok sorry, it is just a book gives no feedback John English
2001-01-03  6:24 ` Nick Roberts [this message]
2001-01-04 13:14   ` Robert Dewar
2001-01-04 15:49     ` n_brunot
2001-01-04 17:09       ` Robert Dewar
2001-01-05  8:53         ` n_brunot
2001-01-05 13:45           ` Robert Dewar
2001-01-05 21:23             ` Randy Brukardt
2001-01-06  4:05               ` Larry Kilgallen
2001-01-06 17:11                 ` Robert Dewar
2001-01-06 20:26                   ` Larry Kilgallen
2001-01-06 22:40                     ` Robert Dewar
2001-01-07  1:12                       ` Larry Kilgallen
2001-01-07  4:19                         ` Robert Dewar
2001-01-07 17:12                           ` Larry Kilgallen
2001-01-08 12:26                             ` Marin David Condic
2001-01-08 12:57                             ` Larry Kilgallen
2001-01-08 15:01                     ` Stephen Leake
2001-01-08 15:58                       ` Ted Dennison
2001-01-09 21:13                       ` Jean-Pierre Rosen
2001-01-06 19:46               ` Laurent Guerby
2001-01-06 20:36                 ` Robert Dewar
2001-01-07 13:09                   ` Laurent Guerby
2001-01-07 15:56                     ` Robert Dewar
2001-01-07 16:25                       ` Laurent Guerby
2001-01-07 15:58                     ` Robert Dewar
2001-01-07 17:19                     ` Larry Kilgallen
2001-01-06  7:13           ` Simon Wright
2001-01-07 16:00             ` Robert Dewar
2001-01-07 17:16             ` Larry Kilgallen
2001-01-04 17:11       ` Robert Dewar
replies disabled

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