comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: What is your opinion on Global Objects?
Date: Thu, 20 Nov 2014 13:11:10 -0800 (PST)
Date: 2014-11-20T13:11:10-08:00	[thread overview]
Message-ID: <65f2470c-0828-4f97-9f0e-f11966896c06@googlegroups.com> (raw)
In-Reply-To: <8561e9omp7.fsf@stephe-leake.org>

On Thursday, November 20, 2014 8:34:31 AM UTC-8, Stephen Leake wrote:
> 
> > That basically is a vote for global objects. Whether they are accessed
> > through a global variable or some sort of getter function that returns
> > access, it means bypassing the parameters. Well from what I read here,
> > there are no strong opinions for either concept. Strange, I wasn't
> > able to find good arguments for or against the two concepts anywhere,
> 
> If you can really, truly, absolutely guarrantee that you will _never_
> need two different copies of the data structure, then the singleton
> pattern makes sense (data in a single variable in a package body).
> 
> If you ever need two different copies of the data structure, then you
> need to pass it around in parameters.
> 
> The symbol table for a compiler is a good candidate for a singleton.

This doesn't seem right to me.  

I haven't followed the whole discussion closely, so I might have missed something...  But in the case of a symbol table, an Ada compiler that implements generics by "macro instantiation" is an example of why a symbol table should *not* be a singleton.  If the compiler rescans the text of the generic, the entire context (i.e. what symbols are visible) will change while the generic is being instantiated, and then it will change back at the end.  And of course the generic can instantiate another generic.

This doesn't mean that any data structures are being copied.  The "symbol table" could be implemented as a single access object, or as a smallish record that contains an access object that points to the root of the symbol table and has some other housekeeping info.  But it still wouldn't be a singleton.  Making it a singleton (or global) would mean that any time the context has to change, some subprogram has to save the global value into a local, change the global value, call whatever other subprogram will be using the new context, then restore the global value from the local.  I've worked with this kind of arrangement and have suffered from numerous migraines as a result.  (That's one of the reasons I try not to use singleton objects in general; there have been too many times when it's seemed clear that there needs to be only one instance of something, and it's come back to bite me.)

In any case, though, I don't know what it has to do with "copies of a data structure".  That seems to be the wrong criterion, especially in a case like a compiler symbol table.  Perhaps I just view the world too differently from you, or you're just used to working with different examples than I am.

                                -- Adam


  reply	other threads:[~2014-11-20 21:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18  1:36 What is your opinion on Global Objects? Hubert
2014-11-18  2:52 ` Jeffrey Carter
2014-11-18  3:08   ` Hubert
2014-11-18  3:16     ` Shark8
2014-11-18  5:09     ` Jeffrey Carter
2014-11-18 11:23     ` Brian Drummond
2014-11-19  2:50       ` Hubert
2014-11-19  3:03         ` Jeffrey Carter
2014-11-19  9:13           ` Hubert
2014-11-19 10:22             ` J-P. Rosen
2014-11-19 17:37             ` Jeffrey Carter
2014-11-20 16:34         ` Stephen Leake
2014-11-20 21:11           ` Adam Beneschan [this message]
2014-11-21 15:25             ` Stephen Leake
2014-11-21 21:53             ` Randy Brukardt
2014-11-21  1:25           ` Hubert
2014-11-21  3:00           ` Brad Moore
2014-11-19 10:11   ` Jacob Sparre Andersen
2014-11-20  6:21     ` Hubert
2014-11-18  8:54 ` Dmitry A. Kazakov
2014-11-20 20:33 ` sbelmont700
2014-11-20 21:35   ` J-P. Rosen
2014-11-21  1:02     ` sbelmont700
2014-11-21  1:31       ` Hubert
2014-11-21  9:01     ` Dmitry A. Kazakov
2014-11-22  7:46       ` J-P. Rosen
2014-11-22  9:02         ` Dmitry A. Kazakov
replies disabled

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