Skip to content

Explore required named parameters #52

Open

Description

@Zamua

In python a function can define defaults for parameters, and then have the caller assign values to those parameters in the call by referencing the parameter name.

An example:

def foo(paramA=1):
    return paramA + 1

>>> foo(paramA=20)
>>> 21

However, in python this is optional, and these named parameters can be left out during a call. They will just assume the default value in the function definition. We could make them implied in LJ with no default declarations in the function definition, but callers must pass all arguments by referencing the parameter names.

This would require the developer to know the names of the parameters, but it would take away all of the guesswork of parameter order. It perhaps goes against the terse philosophy of less java, but I think it might prove to be more user friendly. I haven't searched for any literature on this feature. If anybody knows of any off hand please reference it on this issue.

Discussion is welcome.

Activity

  1. Zamua commented on May 31, 2019

    @Zamua
    ContributorAuthor

    I created a proposal tag for this sort of issue. Feel free to delete it if you feel it's unnecessary @lam2mo

  2. lam2mo commented on Jun 1, 2019

    @lam2mo
    Member

    The proposal tag is a good idea--thanks! (I did change the color so that it doesn't look quite so much like the bug tag.)

    I'm not opposed to allowing right-most optional parameters w/ constant values as long as their initializations are incorporated during type inference. However, I think that keyword parameters would just make things more verbose without adding a ton of clarity in the target context (simple programs in an intro course). I suspect that learning the positional parameter system is preferable because it emphasizes the importance of having a clearly-defined contract/API between software components.

    In any case, I think its implementation and testing would also be a pretty low priority at this point. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions