TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ada Marketing <[log in to unmask]>
Reply To:
Ada Marketing <[log in to unmask]>
Date:
Mon, 4 Dec 2000 09:43:31 -0500
Content-Type:
multipart/mixed
Parts/Attachments:
text/plain (2404 bytes) , adamark.vcf (171 bytes)
Stephane,

I agree with the general points about it being bad to have global variables.

My approach here has always been to try and encapsulate the global data.  Then it
isn't global.  Thus if you have a data type that must be shared across multiple
packages, declare a package for the data, make the data private (or limited if has
access types), then export operations to act on the data (an array in this case).
This localizes the control over the data so classic global data access problems are
eliminated.  E.g.


generic
  Data_Type is private;
package My_Data is

type Global_Data is private;

function Get(Data : in Global_Data) return Data_Type;
procedure Put(Data : in out Global_Data; Item : in Data_Type);
procedure Do_Other_Things;
private
 .....
end My_Data;



Stephane Richard wrote:

> Hi Jeff,
>
> Thank you very much for these somewhat insighful words of wisdom.
>
> Now I have spent the last 2 weeks assessing the possible means I had to
> acheive my goals, trust me when I say that global variable was far from the
> first on my list of alternatives. But the fact of the matter remains, I need
> lists of data, an array or a linked list, whichever, and I need that list
> available throughout the rest of the packages somehow.
>
> Now instead of stopping your comment at telling me that this design is
> bad, that global variables bring global famine, let me assure you that list I
> am talking about is NOT a food shopping list :-). Why dont you detail
> yourself and bring me the other alternatives and possible solutions.  If you know
> of a way to obtain this availability without the use of global variables then
> please, by all means, do let me know so that I may do this the right way.
>
> In other words, dont stop at telling me this is a bad design.  Contrary to
> popular belief global variables are a bad design pretty much in any
> programming language.  Tell me why it is bad, and how to make it better.
>
> Thank you,
>
> Stephane Richard
> Software Developer
>
> > What you are talking about is a global variable. Global variables cause
> > disease, famine, and war, not to mention really badly designed,
> > impossible-to-debug software. The first rule of software engineering is
> > modularize and never use global variables. The first two rules of
> > software engineering ...
> >
> > --
> > Jeff Carter
> > "Nobody expects the Spanish Inquisition!"
> > Monty Python's Flying Circus
> >
>
> --
> Stephane Richard
> Software Developer
> [log in to unmask]
>
> Sent through GMX FreeMail - http://www.gmx.net


ATOM RSS1 RSS2