Issue 1 - Global Values
Some years ago, I had a situation where
(a) I could supply low-level functions that carry out tasks,
(b) I needed those functions to communicate with each other, but
(c) I had no access to the module that invoked my functions.
I am now facing another situation where I am wanting to pass 6 or 7 >parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7 parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Having had the idea described above, I am considering using it again to
save all the parameter-and-results passing.
I see nothing wrong with doing that, but I may well be missing something!
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Some years ago, I had a situation where
(a) I could supply low-level functions that carry out tasks,
(b) I needed those functions to communicate with each other, but
(c) I had no access to the module that invoked my functions.
In order to achieve this, I hit on the idea that I also supply a
module
that I describe as a "global values" module. This module …
(i) … defines the values that the functions use to communicate with
each
other;
(ii) … is the subject of an import statement in each of my functions;
(iii) … initialises its values at the start of each run (since the
import
only carries out an actual import once per session);
(iv) … acts as a repository for the values thereafter.
This solution works well.
Given that I am not particularly concerned about efficiency,
(1) Is this a reasonable way to achieve this goal?
(2) Do you know of any better ways?
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7 parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Having had the idea described above, I am considering using it again
to
save all the parameter-and-results passing.
I see nothing wrong with doing that, but I may well be missing
something!
Comments, please!
Stephen Tucker.
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7 parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Some years ago, I had a situation where
(a) I could supply low-level functions that carry out tasks,
(b) I needed those functions to communicate with each other, but
(c) I had no access to the module that invoked my functions.
In order to achieve this, I hit on the idea that I also supply a module
that I describe as a "global values" module. This module …
(i) … defines the values that the functions use to communicate with each other;
(ii) … is the subject of an import statement in each of my functions;
(iii) … initialises its values at the start of each run (since the import only carries out an actual import once per session);
(iv) … acts as a repository for the values thereafter.
This solution works well.
Given that I am not particularly concerned about efficiency,
(1) Is this a reasonable way to achieve this goal?
(2) Do you know of any better ways?
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7 parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Having had the idea described above, I am considering using it again to
save all the parameter-and-results passing.
I see nothing wrong with doing that, but I may well be missing something!
Comments, please!
Stephen Tucker.
On 14 Nov 2022, at 22:06, Thomas Passin <list1@tompassin.net> wrote:
For parameter passing like your #2, I have packaged them into a dictionary and passed that around. It was easy enough, and worked well.
The only potential problem is in documenting the key/value pairs the dictionary is supposed to contain. You had better make sure it's made clear somewhere, preferable where it is consumed.if you want to go to that trouble.
For "global" values, sure, put them in a module and import them as needed. Just make sure that none of your code is going to mutate those values, or you will end up with mass confusion. I suppose you could make them be properties that have no setters,
On 11/14/2022 12:14 PM, Stephen Tucker wrote:
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Some years ago, I had a situation where
(a) I could supply low-level functions that carry out tasks,
(b) I needed those functions to communicate with each other, but
(c) I had no access to the module that invoked my functions.
In order to achieve this, I hit on the idea that I also supply a module
that I describe as a "global values" module. This module …
(i) … defines the values that the functions use to communicate with each >> other;
(ii) … is the subject of an import statement in each of my functions;
(iii) … initialises its values at the start of each run (since the import >> only carries out an actual import once per session);
(iv) … acts as a repository for the values thereafter.
This solution works well.
Given that I am not particularly concerned about efficiency,
(1) Is this a reasonable way to achieve this goal?
(2) Do you know of any better ways?
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7
parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Having had the idea described above, I am considering using it again to
save all the parameter-and-results passing.
I see nothing wrong with doing that, but I may well be missing something!
Comments, please!
Stephen Tucker.
--
https://mail.python.org/mailman/listinfo/python-list
On 14 Nov 2022, at 22:49, Chris Angelico <rosuav@gmail.com> wrote:
On Tue, 15 Nov 2022 at 09:38, Barry <barry@barrys-emacs.org> wrote:
I used to use a dict but having been burnt with issues now create a class. >>On 14 Nov 2022, at 22:06, Thomas Passin <list1@tompassin.net> wrote:
For parameter passing like your #2, I have packaged them into a dictionary and passed that around. It was easy enough, and worked well.
With a class you can add accessor methods that allow you to run debug code as values are changed. Also you can check that values being set are spelt correctly, have reasonable values etc.
TBH you could add accessor methods to a dict just as easily
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On 14 Nov 2022, at 22:06, Thomas Passin <list1@tompassin.net> wrote:
For parameter passing like your #2, I have packaged them into a dictionary and passed that around. It was easy enough, and worked well.
I used to use a dict but having been burnt with issues now create a class.
With a class you can add accessor methods that allow you to run debug code as values are changed. Also you can check that values being set are spelt correctly, have reasonable values etc.
On 14 Nov 2022, at 22:06, Thomas Passin <list1@tompassin.net> wrote:I used to use a dict but having been burnt with issues now create a class.
For parameter passing like your #2, I have packaged them into a dictionary and passed that around. It was easy enough, and worked well.
With a class you can add accessor methods that allow you to run debug code as values are changed. Also you can check that values being set are spelt correctly, have reasonable values etc.
Barry
setters, if you want to go to that trouble.The only potential problem is in documenting the key/value pairs the dictionary is supposed to contain. You had better make sure it's made clear somewhere, preferable where it is consumed.
For "global" values, sure, put them in a module and import them as needed. Just make sure that none of your code is going to mutate those values, or you will end up with mass confusion. I suppose you could make them be properties that have no
On 11/14/2022 12:14 PM, Stephen Tucker wrote:
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Some years ago, I had a situation where
(a) I could supply low-level functions that carry out tasks,
(b) I needed those functions to communicate with each other, but
(c) I had no access to the module that invoked my functions.
In order to achieve this, I hit on the idea that I also supply a module
that I describe as a "global values" module. This module …
(i) … defines the values that the functions use to communicate with each >>> other;
(ii) … is the subject of an import statement in each of my functions;
(iii) … initialises its values at the start of each run (since the import >>> only carries out an actual import once per session);
(iv) … acts as a repository for the values thereafter.
This solution works well.
Given that I am not particularly concerned about efficiency,
(1) Is this a reasonable way to achieve this goal?
(2) Do you know of any better ways?
Issue 2 - Passed Parameters
I am now facing another situation where I am wanting to pass 6 or 7
parameters down through several layers of logic (function A calling
function B calling ... ) and for results to be passed back.
Having had the idea described above, I am considering using it again to
save all the parameter-and-results passing.
I see nothing wrong with doing that, but I may well be missing something! >>> Comments, please!
Stephen Tucker.
--
https://mail.python.org/mailman/listinfo/python-list
On 14/11/2022 17:14, Stephen Tucker wrote:
Hi,
I have two related issues I'd like comments on.
Issue 1 - Global Values
Your "global variables" module acts exactly as a singleton class.
On Mon, Nov 14, 2022 at 11:33 AM Axy via Python-list
<python-list@python.org> wrote:
On 14/11/2022 17:14, Stephen Tucker wrote:
> Hi,
>
> I have two related issues I'd like comments on.
>
> Issue 1 - Global Values
Your "global variables" module acts exactly as a singleton class.
Which is apparently a design pattern that some now believe is regrettable.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 57:00:19 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,478 |