I second tinman's opinion.
It might not be obvious to everybody, but this helps organizing things, expecially
with big projects, or when reusing code a lot.
However, i would like this to be taken a step further, not just for constants.
My proposal would be a new compiletime command (like SizeOf() or OffsetOf())
Defined(Object [, Object [, Object [, ...]]])
This would simply replaced by a 1 if all given 'objects' are defined, and a 0 if not.
This way, you could use it in CompilerIf and such, and there is no need for
"IfDefined", "IfNotDefined", whatever...
'Object' could then be a Constant, a Structure, Interface, LinkedList, array
or a variable (in the main namespace only (ie Globals, Shareds or variables in the main code)), and in the future, maybe also with macros.
There would be many usefull applications for this. Imagine you have
some IncludeFiles, which all need a LinkedList, but as those files are used
a lot, you can't be sure, which ones are included in the actual projects,
and in which order.
So where do you put the NewList command then?
Well, with the above you could just do this:
Code: Select all
CompilerIf Defined(MyList()) = 0
Newlist MyList.l()
CompilerEndIf
Put this into every one of those includefiles, and the List will always be there,
no matter what of the files you use. And you won't get any errors.
Now, combined with another possible feature, (that i know tinman is requesting for a while now as well

)
You can do even more to prevent the common problems when reusing code:
CompilerError "Error Message"
Lets say you have a nice Includefile that you use a lot, but unfortunately, it
requires some Global variables. So what if you give some other variable in
the main code the same name? (happy bug-hunting is all I say

)
Well, for now we just give those variables a weird name and hope we won't
ever use that same weird name again.
So what could you do with this?
Code: Select all
CompilerIf Defined(MyGlobal1, MyGlobal2, MyGlobal3)
CompilerError "Global Variable reused!"
CompilerEndIf
Global MyGlobal1, MyGlobal2, MyGlobal3
Voilà , no more trouble!
And of course there is tinman's example with the constants, and many more.
As I said, some of this might not seem too usefull at first, but beleive me,
it helps coding in a way that rules out the sources for some errors right from the start.
I didn't have any use for such features in the past either, but right now i wish they were there.
Lets see if i can talk Fred into this...
Timo