[Gambas-user] User Digest, Vol 36, Issue 1

John Rose john.aaron.rose at mailbox.org
Tue Sep 1 11:18:35 CEST 2020


On 01/09/2020 02:30, user-request at lists.gambas-basic.org wrote:
> On 8/31/20 4:08 AM, John Rose wrote:
>> Thanks Lee for the above. I've implemented the modifications from 
>> your diff file. Only problem is "Global variable hidden by local 
>> declaration : aEpisodeData" in ExtractEpisodes procedure. I guess 
>> that won't make any difference at runtime but it would be nice not to 
>> have it. I thought of using the idea (as per hData & hdataLocal in 
>> your diff file) of changing the Dim name from aEpisodeData to 
>> aEpisodeDataLocal in the procedure (together with its uses in the 
>> procedure) but that then causes changes to the definition & use in 
>> the SortEpisodeData procedure. Any better ideas to prevent the 
>> compilation message?
>
> Ah, yes, another of the issues with globals. It is difficult to change 
> individual procedures when they are dependent upon a global structure. 
> Keeping data structures, where possible, localized/compartmentalized 
> aids modularity and, therefore, debugging and future 
> maintenance/enhancement.
>
> The notice is not critical. It merely means that the global variable 
> is not accessible from within the subroutine since it is 'shadowed' by 
> the local variable.
>
> But if it bothers you (and it probably would me), the simplest way to 
> get rid of it would be to revert ExtractEpisodes, from effectively a 
> function, back to a procedure (in effective form) that receives no 
> argument nor returns any value, but instead works upon the global 
> variable. The less simple way is to convert SortEpisodeData into a 
> function that receives and returns a String[][] and, of course, 
> changing the local variable names eg. to aEpisodeDataLocal.

I've actually changed all my global variables to start with a $ sign 
e.g. $asEpisode for an array of strings. Obviously this means that there 
is no confusion between global & local variables, as well as not having 
to append 'local' to a local name which has the same name as a global 
variable. It still allows me to use procedures as 'effectively' 
functions (using the Return command).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20200901/10c929de/attachment.htm>


More information about the User mailing list