Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Local scoop wish
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00720623
Message ID:
00721045
Views:
14
Not declaring variables is a bad programming practice, you are right ! The problem is that VFP let you do it.

In C# for example there is no such thing as private variables.

The _VFP.LanguageOption is useless, you should read my reponse to Jim Nelson about it in this tread.

>I don't agree with this new SYS () function as it would support not declaring all variables used by a given function which is a bad programming practice IMHO. You can use _VFP.LanguageOptions to force the declarations of variables.
>
Define Class Test As Session
>
>	Protected Function Init()
>		_VFP.LanguageOptions = 1
>	EndFunc
>
>	Function Test1
>		x = 1   && Error
>		? x
>		? This.Test2()
>	EndFunc
>
>	Function Test2
>		Return x && Error
>	EndFunc
>	
>EndDefine
>
>
Define Class Test As Session
>
>	Protected Function Init()
>		_VFP.LanguageOptions = 1
>	EndFunc
>
>	Function Test1
>                LOCAL x
>		x = 1   && OK
>		? x
>		? This.Test2()
>	EndFunc
>
>	Function Test2
>		Return x && Error
>	EndFunc
>	
>EndDefine
>
>>I don't beleive you got me right, my wish was to have a new sys() function to changed the default behavior of VFP from creating all undeclared variable as LOCAL to the function declaring it:
>>
>>Current behavior:
>>ox = CreateObject("Test")
>>=ox.Test1()
>>
>>Define Class Test As Session
>>
>>	Function Test1
>>		x = 1
>>		? x
>>		? This.Test2()
>>	EndFunc
>>
>>	Function Test2
>>		Return x && x is private so no error here
>>	EndFunc
>>	
>>EndDefine
>>
>>
>>New Sys() Option
>>
>>
>>ox = CreateObject("Test")
>>=ox.Test1()
>>
>>Define Class Test As Session
>>	
>>	Protected Function Init()
>>		=Sys(9999, 1)  && New sys function
>>	EndFunc
>>	
>>	Function Test1
>>		x = 1
>>		? x
>>		? This.Test2()
>>	EndFunc
>>
>>	Function Test2
>>		Return x && x an error here, x is local to test1()
>>	EndFunc
>>	
>>
>>EndDefine
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform