Do we want to force named arguments when constructing Encoders using LinearCode.encode?

Issue #48 resolved
Johan Rosenkilde created an issue

Right now, if I have a code class TestCode with an encoder TestEnc whose constructor takes an argument T, then I have to write as follows to construct it

E = C.encoder("TestEnc", T=22)

where C is of type TestCode and "TestEnc" is the name registered for class TestEnc.

We could also allow the user to write

E = C.encoder("TestEnc", 22)

where the 22 is implicitly passed as first argument to TestEnc constructor, after C that is (the code is always passed as first argument).

Comments (4)

  1. David Lucas repo owner

    That's because of the **kwargs I use to pass optional arguments. It creates a dictionnary of arguments, with (continuing you example) T as a key and 22 as a value. For instance :

    myFunc(**kwargs):
        if 'test' in kwargs:
             print kwargs['test']
    

    It is also possible to use *args, which is just a list of arguments that can be accessed as any list.

    I suppose *args is enough for what we want, and will allow to get rid of this named argument problem.

  2. Johan Rosenkilde reporter

    Yes, this is true. What I was wondering was whether we should "encourage by allowing" such code. I mean, it's slightly confusing application of arguments, perhaps, since the code object is inserted as first argument to the constructor by LinearCode.encoder.

  3. Daniel Augot

    Well I prefer to discipline the user to type

    E = C.encoder("TestEnc", T=22)
    

    Imagine you have several arguments to the encoder.

    But may be I missed something, because the question does not appear very meaningful to me,

  4. Log in to comment