Bug? No warnings for unused variables declared as Public in Process_Globals

LucaMs

Expert
Licensed User
Longtime User
The long title says all :)

If you declare in Process_Globals variables not yet used writing Private or Dim, you get the warning (unused [VariableName]), but if you use Public no warnings will be shown.

A variable declared with Dim in Process_Globals is public, I know, but I prefer always to use Private or Public.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is by design. When you write a class or a module with public variables there is an assumption that it might be used in other cases. Maybe you are building a library or sharing the module with other projects. The public variable is part of the module interface.

Adding a warning for these variables will cause many modules to add false positive warnings.
 

LucaMs

Expert
Licensed User
Longtime User
Most likely I did not understand your post (except that it is a design choice).


If I use Dim, the variable will have the same scope that if I wrote Public and then the warning (shown or not shown) should be the same, or not?


[Quoting myself :D
"Most likely I did not understand your post"
I think that "you" (we all) should not expose public variables from libraries, only properties; but if you create a public variable to be used from outiside and it is not used inside your library/project it is anyway useless, or not?]
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
If I use Dim, the variable will have the same scope that if I wrote Public and then the warning (shown or not shown) should be the same, or not?
It is a mistake to use Dim with global variables. You will get a warning when using Dim. The warning engine treats it a bit differently than Public (also by design).

This is the same case as with subs. You will not get a warning for unused public subs. Think of a module such as HttpJob or DateUtils. There are many public methods and variables and none of them are used in the project.
 
Top