tool to check whether formal and actual parameters have similar names

A

Amir Michail

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
 
G

G. S. Hayes

Amir Michail said:
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.
 
T

Terry Reedy

Amir Michail said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top