Jump to content

Style Guide: Difference between revisions

From LabVIEW Wiki
No edit summary
Line 3: Line 3:
The following guidelines are provided as a reference for LabVIEW development. Individuals and organizations are encouraged to cater these to best serve their needs and preferences.  
The following guidelines are provided as a reference for LabVIEW development. Individuals and organizations are encouraged to cater these to best serve their needs and preferences.  


= Organization and Names of Directories, Projects, Libraries, Classes, and Files in General =
= Organization and Names of Files =
The following guidance is applicable to all the items and artifacts that are contained within a LabVIEW Project, including VIs and containers such as Projects, Libraries, and Classes.


== Organize all files logically ==
== Organize all files logically ==

Revision as of 17:13, 20 September 2024

The following guidelines are provided as a reference for LabVIEW development. Individuals and organizations are encouraged to cater these to best serve their needs and preferences.

Organization and Names of Files

The following guidance is applicable to all the items and artifacts that are contained within a LabVIEW Project, including VIs and containers such as Projects, Libraries, and Classes.

Organize all files logically

You should organize directories and files so that someone with a reasonable skill level is able to navigate the directory structure.

If you are consistently working on similar projects, you may want to come up with standards for your projects. The authors of this Guide have seen several different and reasonable directory organizations that were appropriate for different projects, which is why this Guide isn't detailed on this topic.

Naming Files and Directories

Choose names so they are easy to read and describe the purpose of the file or directory

- Create names that describe the purpose of the file or directory. - Use full words except where an abbreviation is well known by the intended audience, such as "USB Port" for "Universal Serial Bus Port". - Use book title case with single space characters between words. - You may use dashes in situations where dashes are ordinarily used, such as for “Real-Time”. - Make sure those names work in all relevant platforms.

Details: Refer to Appendix A: Book Title Case for definition and examples.

Windows file path length limitation

When coming up with file and directory names, keep in mind the Windows file path length limitation of 260 characters.

Avoid special characters in file names

For greatest cross-platform compatibility and to simplify reading of file names, avoid the use of special characters in file names such as:

- File separators like : (colon) / (forward-slash) \ (backward-slash). - Symbols like ¢™$®. - Punctuation marks, parentheses, quotation marks, brackets, and operators like . , [ ] { } ( ) ! ; " ' * ? < > |. - White space characters such as tabs, new lines, and embedded returns. Note: Spaces are acceptable for most applications.

Do not use camel-case, Pascal-case, or underscore characters for separation of adjacent words

Bad: - GRTC.lvproject - GenRTCntrl.lvproj

Good: - GenericRealTimeControl.lvproj - Generic Real-Time Control.lvproj - ExitAllOnErr.vi - Exit All on Error.vi

Use names of control VIs as labels

Use names of control VIs as labels for corresponding controls. For example, use the label alarm boolean as the label in Alarm Boolean.ctl.

Name polymorphic VI instances

Name polymorphic VI instances by using space-dash-space between the poly VI name and the specific instance designation. For example, if the poly VI is called Read My Special File.vi, then an instance VI may be called Read My Special File - I32.vi.

File and Directory Names for Examples, Templates, and Sample Projects

This subsection applies to the examples, templates, and sample projects installed in relevant directories within the LabVIEW directory structure.

Do not include the word "example" in any file or folder names

Add a prefix to all example names when developing for a specific driver or addon

Use the form `<Short Product Name><space><Example Name>`. E.g., NI-DAQmx Voltage - Continuous Input.vi.

Avoid deeply nested file folders

Ensure that none of your project’s file folders on disk are too deeply nested. If the user’s project contains a file with a path that exceeds 260 characters in length (for Windows), the project copy will fail. Aim for having a maximum path length of less than 150 characters so there is plenty of room to account for a user saving their project in a deeply-nested path.

Name your .lvproj file the same as the folder that contains it

For templates and sample projects, name your .lvproj file the same as the folder that contains it, e.g., the “PC USRP-RIO Streaming” template folder contains “PC USRP-RIO Streaming.lvproj”.

Project Organization

Place the top-level VIs for the project directly under appropriate targets

Place the top-level VIs directly under the appropriate targets. Because you cannot mark a VI as a top-level VI, placing the top-level VIs under the corresponding target helps clarify which VIs are top-level.

Organize VIs in a hierarchical directory

Organize VIs in a hierarchical directory with easily accessible top-level VIs and subVIs in subdirectories. Limit the number and level of directories in a project.

Place all VIs in libraries, classes, or virtual folders

Avoid using auto-populating folders unless you have a good reason to use them.

Remove all unused files

Details: - Remove all unused files both from the applicable projects/libraries and from the disk.

Tip: - Right-click the project root in the Project Explorer window and select Find Items with No Callers from the shortcut menu to display the Find Items with No Callers dialog box. This dialog box identifies all the items you can remove.

Libraries

Consider using virtual folders to delineate between public and private members of a library

(VI Analyzer) Consider using virtual folders to delineate between public and private members of a library.

Place APIs in a library

Place APIs in a library to improve organization.

Mark non-API VIs as private

Mark any VIs in a library as private if they are not part of the API.

LabVIEW Classes

Name all classes as nouns

Example: - Name an example class Waveform Reader.lvclass rather than Reads Waveforms.lvclass.

Name all member VIs of a LabVIEW class as verbs

Example: - Name an example member VI Read Value.vi rather than Value.vi.

Avoid including the name of the class in VI names

Example: - If we have a class Circle and it needs a VI to return the area, this VI should just be called Calculate Area as opposed to Calculate Circle Area or Circle Calculate Area. Note that LabVIEW provides a namespace for VIs in a library such that it is considered as Circle: Calculate Area.

Use "Read" for VIs that read data

Use the word "Read" to begin the name of any VI that strictly reads data from the private data of a class. Avoid using the word "Get" or any synonym of "Get."

Use "Write" for VIs that bundle data into the private data

Use the word "Write" to begin the name of any VI that strictly bundles data into the private data of a class. Avoid using the word "Set" or any synonym of "Set."

Use Book Title Case for class virtual folders and VI names

Use Book Title Case for all class virtual folders and VI names.

Details: - When auto-created by LV, the class property virtual folder name and the class property VI names may initially match the case of the control label in the class control. Since labels should follow the label guidelines listed in section 3.1.8, you may need to change the class property virtual folder and VI names to be Book Title Case. - The name of a class property virtual folder is used as the name in a class property node. - Because this is auto-generated by LV and may be tedious to change, this guideline is a recommendation at this time. - A LabVIEW Developer tool may be created that will correct the auto-generated virtual folder and VI names to match these guidelines.


External links