|
|
|
12-10-2018, 02:13 PM
|
#1
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
JSFX: why not a compiler error for unassigned variable reference?
Maybe this is an old/common question...
I understand the power/utility/convenience of being able to assign variables in JSFX without any declaration syntax.
What I'm curious about is why there is no compiler error when referencing a variable that is never assigned anywhere in the code.
E.g.
myvar=1+1;
othervar=6/myvaar;
...at compile time, wouldn't it be pretty easy for the compiler to say "myvaar is referenced, but never assigned anywhere in the code"? I hesitate to guess that variable assignment and the building of an associated symbol table is a run-time thing, but wouldn't compilation need to know what variables might be assigned, and if so, wouldn't it be pretty simple to check variables references against that list?
Am I missing something about the utility of such references? Is it ever useful in some crafty hack where the unassigned variable is 0 until it's assigned somewhere else in the code?
I'm asking because I spend 50% of my time writing JSFX tracking down bugs that almost always come down to (nearly invisible) typos. :-) If the compiler (or even some kind of optional pre-compilation parsing) could do a quick check for this, it would be a huge help. (Even if it wasn't 100% accurate!)
Let me know if I'm missing something (or some other way to avoid this.)
|
|
|
12-10-2018, 06:57 PM
|
#2
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
I have my own .jsfx-lib file full of a lot of interrelated functions that reference for example this.channel, where it’s quite convenient that this.channel will evaluate to 0 if referenced in one of said functions without having been declared in another one.
|
|
|
12-10-2018, 07:01 PM
|
#3
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
That said, it shouldn’t be too hard (famous last words) to write your own linting script in another language that checks this stuff if it will save you that much trouble.
|
|
|
12-11-2018, 01:00 AM
|
#4
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
Quote:
Originally Posted by preferred.nomenclature
I have my own .jsfx-lib file full of a lot of interrelated functions that reference for example this.channel, where it’s quite convenient that this.channel will evaluate to 0 if referenced in one of said functions without having been declared in another one.
|
I see. It would still be handy to enable a warning; or perhaps the variable names could be highlighted red in the debugger on the right. I could do up a script, and have considered it, but it'd be much easier to have it integrated in the IDE...
|
|
|
12-11-2018, 01:05 AM
|
#5
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
You actually code directly in the IDE? You gotta try Sublime Text with the ReaSyntax package, it’s so much easier to read. Might cut down on those typos!
https://packagecontrol.io/packages/ReaSyntax
|
|
|
12-11-2018, 01:58 AM
|
#6
|
Human being with feelings
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
|
To find typos, I've learnt to scan down the variable list in the IDE and look for variables with only one reference. Also typos usually appear just above or below the correctly spelt variable in the list, so are not that hard to spot.
|
|
|
12-11-2018, 02:01 AM
|
#7
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
Quote:
Originally Posted by preferred.nomenclature
You gotta try Sublime Text with the ReaSyntax package
|
Thanks, I'll check that out!
Quote:
Originally Posted by Time Waster
To find typos, I've learnt to scan down the variable list
|
Thanks, I've been doing exactly that of late. It's just kind of a pain with many many variables in the list...
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 12:53 AM.
|