Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 12-10-2018, 02:13 PM   #1
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default 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.)
clepsydrae is offline   Reply With Quote
Old 12-10-2018, 06:57 PM   #2
preferred.nomenclature
Human being with feelings
 
Join Date: Dec 2014
Posts: 371
Default

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.
preferred.nomenclature is offline   Reply With Quote
Old 12-10-2018, 07:01 PM   #3
preferred.nomenclature
Human being with feelings
 
Join Date: Dec 2014
Posts: 371
Default

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.
preferred.nomenclature is offline   Reply With Quote
Old 12-11-2018, 01:00 AM   #4
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Quote:
Originally Posted by preferred.nomenclature View Post
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...
clepsydrae is offline   Reply With Quote
Old 12-11-2018, 01:05 AM   #5
preferred.nomenclature
Human being with feelings
 
Join Date: Dec 2014
Posts: 371
Default

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
preferred.nomenclature is offline   Reply With Quote
Old 12-11-2018, 01:58 AM   #6
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,638
Default

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.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 12-11-2018, 02:01 AM   #7
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Quote:
Originally Posted by preferred.nomenclature View Post
You gotta try Sublime Text with the ReaSyntax package
Thanks, I'll check that out!

Quote:
Originally Posted by Time Waster View Post
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...
clepsydrae is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.