Copying and Renaming Classes

LabVIEW can exhibit some unexpected behavior regarding the class Localization string when copying and renaming classes.

Copying and Renaming Classes

I recently found a bug in a tool I maintain. It was due to some interesting behaviour that you may want to be aware of. I thought it was interesting so I thought I'd post about it here.

Background

I have a tool for moving and renaming classes. You can get it here: https://gitlab.com/sas_public/class_refactoring_tools/-/releases

💡
It also includes some Mock Object stuff. I don't really use that anymore, so you can kind of ignore that. If you need Mock Objects, I highly recommend LMock. It is a much better implementation - maybe I'll do a post about that in the future.

I also have my Blue Formatter. Recently I added a step to my blue formatter to edit the Localization String for classes to remove the .lvclass extension. The Localization string is used as the banner at the top of a property node. In that case, the lvclass is redundant - you can see the class wire going into the node, and it takes up space, which causes the node to be much wider than it needs to be. Removing the extension shrinks the node.

Why do we need a tool to rename/copy a class?

You might ask why we need a special tool for moving/copying classes, doesn't LabVIEW have that built in? Yes and No. Yes, there are save as and copy commands built in to LabVIEW, and no, they don't do everything we want.

The name of a class in LabVIEW is tied to many more things than just the filename. Generally, classes reside in a folder that has the same name as the class. Also all of the labels of each class input and output terminal on each method contain the name of the class. The built-in LabVIEW methods don't address any of this. You have to remember to manually update all the instances or you end up with inconsistencies with artifacts left over from previous renamings/copyings. Hence I made my own tool that updates all those things.

The Bug


Removing the .lvclass extension from the localization string (like Blue does) causes a subtle and unexpected change in LabVIEW's behaviour. Normally if you copy or rename a class, LabVIEW will update the Localization string for you - if you haven't edited it. If you have removed the .lvclass or edited the Localization string in any way, and then you copy or rename the class, LabVIEW no longer updates the localization string for you. The default is that the Localization string matches the class filename (extension and all). When it doesn't match (because the extension is missing in this case), LabVIEW doesn't try to update. Probably good behaviour because it doesn't want to stomp on the Localization string if you have edited it.

Solution

The solution was simple, just do a find and replace on the old class name with the new class name (without the extension). Now, if you need to copy or rename/move a class, you can use my tool and it will update everything for you accordingly ,including the Localization string, assuming you haven't made any edits other than removing the .lvclass extension.

Caution

Even if you don't use my tool, it is worth being aware of how LabVIEW treats the class Localization string when copying and renaming classes, particularly if you use class property nodes. If you use property nodes regularly, you are likely to already remove the .lvclass extension to save space. It is also likely that if you rename or copy a class you want the property node to reflect the new name of the class. That would be the expected behaviour.