Explicit Variable Names, With A Compile Error If A Variable Doesn't Exist

Recommended Posts

By far, the most time I spend debugging is tracking down variable names with typos, or if I risk changing the name of a variable later to something more useful, like changing Duration to DurationHrs, making sure that all the instances have been updated is a huge issue.  I have to export all the sequences to a big text file, hunt for all the old name, find it, switch to the real sequence and update.  If I miss one anywhere, the program will just run and not set it. why won't either the compiler or the run time be made to fail for this:


global test1 = 0

global test2 = 0



   test1 = 1




   test3 = 1







this just runs with no indication that anything is wrong, and can be horribly hard to track down.  Of course it is harder if you have something like Duration and type Duraton somewhere.  really hard to see and no way to hunt it down.  Why again can't the compiler compalin (sic) that an assignment is being made to a non-existant (sic) symbol?

Link to comment
Share on other sites

The compiler doesn't complain because at compile time its possible you simply haven't created the symbol yet.  It would be annoying if the compiler was complaining about something you just hadn't gotten around to creating yet.  For example, you are writing some script, thinking about your logic and you realize you are going to need another input.  You code it up based on a channel you haven't created, save the sequence then add the channel.  Same, if you decided you needed a global variable and wanted to declare it in a start up sequence.  


Regular compilers, like C, can do full name checking because you have to create the complete app before you compile.  DAQFactory is always operational which is a huge benefit, but it means that the compiler doesn't know when things are going to exist.  This is actually very similar to JavaScript, and functions almost the same way.  You won't get errors when you write the code, and doing test3 = 1 won't generate an error when you run the code.  The difference is that in JavaScript, doing test3 = 1 will actually create a global variable called test3 if it can't find the symbol.  DAQFactory doesn't do anything.  That all said, generating an error at runtime for assignment would be a good improvement.  Note if you did:  test2 = test3 you would get an error.

Link to comment
Share on other sites

I understand, but the annoyance of an error message telling me to define a variable is very small compared to the annoyance of trying to track down a typo in thousands of lines of code by the operational failure symptom it causes.  As a coding practice, I could avoid that error message by defining the variable before I write code using it, not a bad idea anyway.  Back in the MS Access days, you could set "Option Explicit" to enable this behavior, which forced explicit definition of all variables.  You could leave the default operation for DAQFactory as is, to make it easy for the new guys.


I have spent many, many, many hours trying to track down a problem only to find it was a misspelled variable.  I hope this function will percolate to the top of the new features list!



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.