Function (File) Name Collision Warning

1 次查看(过去 30 天)
Is there a way to make MATLAB remind a developer or warn a user that several conflicting (same name) versions of specific function m-file exists in different directories currently present in the path? This would be useful for in large collaborative MATLAB projects.

回答(3 个)

Jan
Jan 2012-4-5
I'm using an expanded version, which compares the user-defined functions with lists of functions of different Matlab versions. As result I get the information, if my functions names collide with e.g. 2009a+SignalProcessing+Optimization+XYZ-toolbox. But I have only a very limited number of Matlab releases and toolboxes, such that this tool is not of general use currently. Because this FEX submission has been downloaded a few times only (10 to 20 in the last year), I do not think, that this tool is of general interest. But it is very important for me: When I share a large toolbox with another lab, it is fundamental to determine such collisions.
When I send a toolbox developped under Matlab 2009a+SPT to another lab, how should I know if the names collide with and function of Matlab 2011a+SPT+Aero+Opt+RealTime+IPT+Robotics+Financial ?! Should they add my folders before or behind the Matlab toolboxes in the path? There is no way to decide this statically, most of all because the function names of 2013a are not known today. But using UniqueFuncNames you can check this at least dynamically on the user machines, which is more robust due to the consideration of their user-defined functions.
  1 个评论
Daniel Shub
Daniel Shub 2012-4-5
I don't understand why TMW hasn't created a function like this. Even better would be one that could take an optional argument of the class of the first argument.

请先登录,再进行评论。


Honglei Chen
Honglei Chen 2012-4-4
This is probably not the best solution but if you want to write a function named foo and you want to check if there is something same name on the path, you can do
which foo -all
This will list all files named foo on the path.

Daniel Shub
Daniel Shub 2012-4-4
I don't think you can do it robustly. Crazy things like creating a file on the fly will cause obvious problems. Less obvious problems are from intentionally overloading functions for custom classes where you might want name conflicts. You would probably want to check variable name conflicts also. Functions like eval will cause obvious havoc.
Your best bet might be to use depfun on all of your functions and then parse the output for problematic collisions. Defining the problematic collision will be difficult.
  1 个评论
Jan
Jan 2012-4-5
It cannot be 100% robustly, but omitting an automatic test is definitely less robust.
There are a bunch of intented collisions inside toolbox folders: Contents.m, prefspanel.m, messageProductNameKey, \matlab\lang\function.m
and \toolbox\compiler\function.m, etc.
A robust program should avoid EVAL and the dynamic creation of M-files. For intentially overloaded functions a warning can be very helpful understanding, what's going on. Imagine I'm sharing a toolbox with another lab, and we have both overloaded the same Matlab function, but with different features. Then the collision test would remind us to move these functions to \private or \+ folders.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by