tool to check whether formal and actual parameters have similar names

Discussion in 'Python' started by Amir Michail, Aug 10, 2004.

  1. Amir  Michail

    Amir Michail Guest

    Hi,

    I was wondering if there is a tool that will perform some heuristic
    checking of actual and formal parameters to warn about likely errors.

    Such a tool could check that formal and actual parameters have similar
    names.

    For example:

    def plot(x,y): ...

    plot( x1, y1 ) # ok

    plot( y1, x1 ) # not ok, but this is ok: plot (x=y1, y=x1)

    plot (1, y) # not ok, but this is ok: plot(x=1, y)

    We can take this further:

    avg = x1 + x2
    plot( avg, y) # ok since avg gets name x from x1, x2

    Does this make any sense, even in a heuristic sense?
    Does such a tool already exist? Would it be useful?

    Amir
    Amir Michail, Aug 10, 2004
    #1
    1. Advertising

  2. Amir  Michail

    G. S. Hayes Guest

    "Amir Michail" <> wrote in message news:<cfa3hb$>...
    > I was wondering if there is a tool that will perform some heuristic
    > checking of actual and formal parameters to warn about likely errors.
    >
    > Such a tool could check that formal and actual parameters have similar
    > names.
    >
    > For example:
    >
    > def plot(x,y): ...
    >
    > plot( x1, y1 ) # ok
    >
    > plot( y1, x1 ) # not ok, but this is ok: plot (x=y1, y=x1)


    I'm not sure how generally useful this would be. There are just too
    many circumstances where the name in the definition and the name you
    call with are legitimately quite different:

    def plot(x, y):
    ....
    plot(square.width, square.height)
    for column in range(8):
    for row in range(8):
    move_pawn_to(column, row)
    plot(column, row)

    for i in range(10):
    for j in range(10):
    plot(i,j) #along with other stuff using the loop variables

    def write_log(string_to_send): # probably a log.write method in
    real life
    ....
    write_log(server.error_message)
    write_log(user.username)

    def wait_for_connection(socket):
    ....
    wait_for_connection(servers["yahoo"])

    It _might_ be somewhat useful to have something that detects ONLY when
    you are calling with similar names in a different order. Even that
    isn't necessarily useful, there might be non-trivial cases something
    like:

    class generic_tree():
    def insert_member(child, parent):
    class gui_window_tree(our_tree):
    class crypto_algorithms_tree(our_tree):
    ....
    (child, parent) = fork_wrapper()
    GUIWindows.insert_member(child, parent)
    EncryptionAlgorithms.insert_member(parent, child)

    where flip-flopping names made sense. Though this isn't a
    particularly great example, and it might generally be a decent lint
    warning.
    G. S. Hayes, Aug 10, 2004
    #2
    1. Advertising

  3. Amir  Michail

    Terry Reedy Guest

    Re: tool to check whether formal and actual parameters havesimilarnames

    "Amir Michail" <> wrote in message
    news:cfa3hb$...
    > def plot(x,y): ...
    >
    > plot( x1, y1 ) # ok
    >
    > plot( y1, x1 ) # not ok,


    Reversing args reflects plot about 45 degree line, which is a quite
    legitimate thing to do if that is what you want to do. Perhaps original
    coder got plot 'backwards' and editor want to reverse it without changes
    name throughout code.

    > but this is ok: plot (x=y1, y=x1)


    If *you* want to force yourself to jump thru hoops like this, go ahead, but
    don't expect anyone else to follow ;-)

    > Does this make any sense, even in a heuristic sense?


    Not really. I name things like age, weight, height, cholesteral_level with
    their proper names or abbreviations thereof. Your idea strikes me as an
    interesting brainstorm that on second thought would best be left behind.

    Terry J. Reedy
    Terry Reedy, Aug 10, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eadgbe
    Replies:
    3
    Views:
    560
    eadgbe
    Sep 11, 2003
  2. Olaf
    Replies:
    4
    Views:
    2,364
    Mike Treseler
    May 7, 2007
  3. bintom
    Replies:
    10
    Views:
    694
    Paul Bibbings
    Jun 27, 2010
  4. Jeff Cohen
    Replies:
    6
    Views:
    130
  5. Dmitry A. Soshnikov

    Formal parameters and arguments object sharing

    Dmitry A. Soshnikov, Aug 20, 2010, in forum: Javascript
    Replies:
    0
    Views:
    90
    Dmitry A. Soshnikov
    Aug 20, 2010
Loading...

Share This Page