Velocity Reviews > tool to check whether formal and actual parameters have similar names

# tool to check whether formal and actual parameters have similar names

Amir Michail
Guest
Posts: n/a

 08-10-2004
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. S. Hayes
Guest
Posts: n/a

 08-10-2004
"Amir Michail" <(E-Mail Removed)> wrote in message news:<cfa3hb\$(E-Mail Removed)>...
> 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(:
for row in range(:
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)

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.

Terry Reedy
Guest
Posts: n/a

 08-10-2004

"Amir Michail" <(E-Mail Removed)> wrote in message
news:cfa3hb\$(E-Mail Removed)...
> 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