Compilation errors explicitVariables & variable Shadowing
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 14
- Joined: Wed Apr 17, 2013 11:15 pm
Compilation errors explicitVariables & variable Shadowing
I finally moved over to my Full Commercial version of Livecode from the Community edition and now scripts that compiled fine when I clicked Apply in the Code Editor before throw loads of errors.
I have tried putting:
set the explicitVariables to false
At the head of my mainstack script but this seems to have no effect and may not be where to put it.
Even when I pre-declare all my variables explicitly it throws up duplicate or shadow variable name warning messages and searching reveals no variable conflicts and nothing in memory in the Message Box. Only Close and Remove from Memory gets past this but only for one edit iteration. This means in practice that I have to make an edit, save the file, Close it and Remove from Memory and then re-open it to run the edited script, make an edit and save and close all over again to test it...
Any ideas how to overcome this annoying problem?
I have tried putting:
set the explicitVariables to false
At the head of my mainstack script but this seems to have no effect and may not be where to put it.
Even when I pre-declare all my variables explicitly it throws up duplicate or shadow variable name warning messages and searching reveals no variable conflicts and nothing in memory in the Message Box. Only Close and Remove from Memory gets past this but only for one edit iteration. This means in practice that I have to make an edit, save the file, Close it and Remove from Memory and then re-open it to run the edited script, make an edit and save and close all over again to test it...
Any ideas how to overcome this annoying problem?
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Compilation errors explicitVariables & variable Shadowin
Do you have the Explicit Variables option set in Preferences?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Compilation errors explicitVariables & variable Shadowin
Hi Quentin
It does sound like the explicitVariables preference is on but if the last suggestion doesn't help please feel free to email me your stack and I'll take a look at it, elanor@runrev.com.
Kind regards
Elanor
It does sound like the explicitVariables preference is on but if the last suggestion doesn't help please feel free to email me your stack and I'll take a look at it, elanor@runrev.com.
Kind regards
Elanor
Elanor Buchanan
Software Developer
LiveCode
Software Developer
LiveCode
-
- VIP Livecode Opensource Backer
- Posts: 14
- Joined: Wed Apr 17, 2013 11:15 pm
Re: Compilation errors explicitVariables & variable Shadowin
Sorted it thanks guys, it seems the option in preferences/Script Editor for Strict Compilation Mode was on.
This does raise the question of best practises though. Presumably I should pre-declare variables really. What is the reason for this? Just ease of management i.e. put them all together at the top of a script and you can check what variables are in use in the script all in one place to avoid naming conflicts?
Also variable name shadowing popped up as a compile error - this seems to happen even when there is no other use or declaration of that variable name or very similar names anywhere in my Mainstack. Just a variable that has beeen active already due to running the stack in run mode to test seems to cause this even though it doesn't show up anywhere as being still in memory. Can I overcome this? It might be good practice for me to be able to leave Strict Compilation Mode on if it helps remind me to use best practises with my code.
This does raise the question of best practises though. Presumably I should pre-declare variables really. What is the reason for this? Just ease of management i.e. put them all together at the top of a script and you can check what variables are in use in the script all in one place to avoid naming conflicts?
Also variable name shadowing popped up as a compile error - this seems to happen even when there is no other use or declaration of that variable name or very similar names anywhere in my Mainstack. Just a variable that has beeen active already due to running the stack in run mode to test seems to cause this even though it doesn't show up anywhere as being still in memory. Can I overcome this? It might be good practice for me to be able to leave Strict Compilation Mode on if it helps remind me to use best practises with my code.
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Compilation errors explicitVariables & variable Shadowin
Some people prefer the Strict Compilation mode, some don't. There is no "best", just a matter of tastes.
For myself, I tend to sketch out algos in an iterative process in which I rarely know all the variables I'll need in advance, and will constantly revise a handler until I get it functional and efficient. In my workflow, Strict Compilation just means extra work for me, and since I tend to copy-and-paste variable names it solves I problem I rarely have. So I almost always work without it.
Others, however, very much prefer being able to instantly catch variable name issues, and prefer to work with it turned on.
Both are valid and productive ways of working.
For myself, I tend to sketch out algos in an iterative process in which I rarely know all the variables I'll need in advance, and will constantly revise a handler until I get it functional and efficient. In my workflow, Strict Compilation just means extra work for me, and since I tend to copy-and-paste variable names it solves I problem I rarely have. So I almost always work without it.
Others, however, very much prefer being able to instantly catch variable name issues, and prefer to work with it turned on.
Both are valid and productive ways of working.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 7239
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Compilation errors explicitVariables & variable Shadowin
Like Richard said, it's personal preference. I never use it, but some people have completely rewritten their entire code base to do so. The advantages are mostly to catch typos in variable names so you don't have to figure out why your code isn't working. It also checks for duplicate variable names, but the current engine bug is probably a good reason to avoid turning it on until that's fixed. I'd say if you rarely make typos, you probably don't need it, but that's just me.Quentin Brown wrote:It might be good practice for me to be able to leave Strict Compilation Mode on if it helps remind me to use best practises with my code.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com