By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,369 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,369 IT Pros & Developers. It's quick & easy.

tool to check whether formal and actual parameters have similar names

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Amir Michail" <am******@gmail.com> wrote in message news:<cf********@odak26.prod.google.com>...
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.
Jul 18 '05 #2

P: n/a

"Amir Michail" <am******@gmail.com> wrote in message
news:cf********@odak26.prod.google.com...
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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.