LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
AristosQueue (NI)

New VIs created in libraries should default to private scope

Status: New

This idea has come up repeatedly over the years: a new VI created in a library* should default to private scope. The point of private scope is to limit the number of callers of a subroutine so you can freely refactor the subroutine and know, without question, that the only callers that you can be affecting are the ones inside the library. This allows you to make API breaking changes freely because you can know you are updating all the callers. Note that if we did this, it would almost certainly have a Tools>>Options setting to change it, but the idea is to make "new VIs start in private scope" be the shipping default.

 

Each of the other scopes is more permissive in some way, with public being all the way open. For APIs intended for reuse and long-term stability, use of those other scopes ought to be a conscious decision.

 

The vast majority of VIs within most libraries should be private. There are some weird exceptions**, but most libraries have a few routines intended for the world to call and a bunch of subVIs that support the public ones. But going and setting the access scope to private is a lot of work, and many developers never think about it. For small shops, this isn't usually a big deal, but the larger the dev team, the greater the danger of highly interlocked libraries caused by someone reaching for some deep subroutine that just seems so useful, instead of doing the right thing and refactoring that VI out into its own shared library. 

 

I've seen some of our customers get really badly bitten by this, but it is an issue that takes years to build up, and then requires expensive refactoring projects to fix (or cloned code, which is sometimes worse in the long run).

 

C++ and C# default everything to private unless you declare public; I think that's true in most text languages.

 

But LV is a programming language for non-programmers, and not everyone needs to understand access scope, so creating new VIs as private by default would push yet another concept into the "you must learn this" category instead of "learn this when you hit a scale where it is useful" category.

 

In the end, I think access scope is a simple enough concept, one that most people using libraries get familiar with pretty quickly, and switching something to public is easy enough to do. Therefore, I think switching the default would do more good than harm. So that's what I'm proposing here.

 

* includes plain .lvlib libraries, XControls, LabVIEW classes, state charts, and any other type of library NI may introduce.

** such as the NI Analysis library, which is hundreds of VIs packaged together, mainly for licensing reasons, less because they have shared functionality.

5 Comments
kosist90
Active Participant

It will be for sure interesting and useful feature. But, if it will be implemented, wouldn't it be more logical to put this option not to Tools -> Options, but to library/class properties options? Because, if one will create library specifically for API - all API VIs will have public scope. Thus, one will change this option for particular library, and all created VIs of this library will have public scope, etc.

AristosQueue (NI)
NI Employee (retired)

kosist90: Assume that the options would be akin to the "save as source only" option*, where there would be a Tools>>Option to control how new libraries behave and a lib property option to control how a specific library behaves.

 

* or several other options we have that control new VIs.

wiebe@CARYA
Knight of NI

AFAIC, If the user makes a new dynamic dispatch VI, it should be protected (not private).

 

Other than that, I think it would be an improvement.

wiebe@CARYA
Knight of NI

AFAIC, If the user makes a new dynamic dispatch VI, it should be protected (not private).

I automatically read 'class' when I see 'library'... Still somewhat applicable, I hope.

AristosQueue (NI)
NI Employee (retired)

Weibe: Of course. (Private isn't a legal scope for dynamic dispatch. I just didn't get into all the fine-grain details in the idea generally.)