Wednesday, November 19, 2008

Crosslinking, Namespaces, and Naming Conventions

A good feature of LabVIEW is the use of plain English names for VI’s. This makes it more programmer-friendly, particularly when one is reading someone else’s software. Crosslinking has been a historical problem in LabVIEW programs, as it can be in other languages. This happens because VI’s in two different sets of software are given the same name, for example “Initialize.vi.” If a project is loaded and that uses Initialize.vi, and then a second project opened that has different VI that also has the same name Initialize.vi, the second project will find Initialize.vi already in memory and link to it. Then if the second project is saved the link to the wrong Initialize.vi is saved.

Other languages use namespaces to try to prevent this kind of crosslinking. National Instruments addressed this with LabVIEW 8.x, which provides namespaces using the LabVIEW project. There can be an Initialize.vi in two different projects, but the LabVIEW Project effectively provide a separate namespace for each project, so there is less chance of crosslinking. We have ongoing projects in LabVIEW 7.1 because of test equipment constraints, so a convention has been adopted to reduce the chance of crosslinking. This is simply to add a prefix to each VI using the software part number and an underscore. Now instead of having VI’s in two different locations named Initialize.vi, we have a VI named CA789267_Initialize.vi and another named CA578923_Initialize.vi. Now we have little chance of crosslinking, because the VI’s have different names, and it is clear at glance which one belongs to which project.

Now, using Single Element Queue Object Oriented Programming, we also need to uniquely name each VI with the name of the class it is part of. We accomplish this with a suffix. If we had two DMM classes named HP34401 and Keithley2000, there would be a VI in each class to set the range, and they would be named Set Range_HP34401 and Set Range_Keithley2000. Again, the possibility of crosslinking has been reduced and it is obvious which class the VI belongs to. If these VI’s were part of a development project, they might be named NewProject_Set Range_HP34401.vi and NewProject_Set Range_Keithley2000 until the project has been assigned a software part number, then changed to CA678354_Set Range_HP34401.vi and CA678354_Set Range_Keithley2000.vi.

By the way, do not try to look up any of the above software part numbers. They are fictional and used just as examples.

How can all the above renaming be easily accomplished without individually opening and re-saving each VI? There is a tool to copy and rename the VI’s in entire hierarchies of folders on the LAVA forum at http://forums.lavag.org/GOOP-Tool-to-copy-classes-t1460.html.

No comments: