Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing 'argument lists' as a namedtuple in python
    primarykey
    data
    text
    <p>I created a namedtuple called Engine that holds most of the information I want to pass around my program. Inside of this tuple, are a couple of parameters and two instanced classes that are used by methods downstream. </p> <pre><code>Engine = namedtuple('Engine', 'website, browser, s, e') engine = Engine(website, browser, s(), e()) </code></pre> <p>i have a function, <code>download(engine)</code> that I pass <code>engine</code> into. Subfunctions in <code>download</code> pass <code>engine</code>-- some of them use <code>website</code>, some of them use <code>browser</code>, some of them use <code>s</code>, and some use <code>e</code>. </p> <p>Now, the cognitive overhead (of me as a programmer) goes down considerably, I no longer have to ensure that argument lists are up to date both downstream and upstream of a particular change that might happen-- I just pass <code>engine</code> downstream, and if I use an argument in a method, i use <code>engine.foo</code>. </p> <p>On the other, it feels like this is 'lazy' programming-- just wrapping everything up into an engine 'class' and having the variables as methods on the class seems to make everything almost too easy. Further, I'd swear that there was some kind of overhead I'm not seeing with this implementation. Is there any kind of precedent to this, cause it feels too useful to ignore. </p> <p>Should I be using namedtuples as replacement for arguments throughout my program to reduce the number of arguments that get passed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload