Page 1 of 1

[Implemented] Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 8:08 am
by Josh
In my eyes the possibility to change the default type with define is a useless feature. Definitely it is a dangerous function, if you bring in this unintended in your code. In this case the problems can occur at a complete other place in your project. Have fun by finding your problem.

Re: Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 8:52 am
by Mistrel
Unless you're referring to something different than what is described in the documentation then I'm not following what it is you're suggesting.

Re: Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 10:05 pm
by netmaestro
Seems to be pointing out the possibility that after the default type is changed, procs could be called from includes that were written at different times and maybe not even connected to the current project, and the code in these procs could be blindsided by encountering an unexpected default type.

Re: Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 10:35 pm
by Mistrel

Code: Select all

Define.b

a=1000

Debug a
Reports:
Line 3: Overflow error: a 'byte' value (.b) must be between -128 and +255.
I wasn't aware that you could even do that. I would agree that this is a very odd use of Define and has the potential to do more hard than good.

Re: Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 10:40 pm
by jack
it is a documented feature, personally I alway declare the variable type, relying on defaults seems sloppy to me.

Re: Eliminate changing default tpe in Define

Posted: Sun Nov 20, 2016 10:57 pm
by netmaestro
Agreed, I don't see much upside to it either. I never use it.

Re: Eliminate changing default tpe in Define

Posted: Mon Nov 21, 2016 12:05 am
by davido
+1

Re: Eliminate changing default tpe in Define

Posted: Mon Nov 21, 2016 4:48 am
by Shield
It's from a time where there was no define and EnableExplicit, and it was called DefType back then. I'd be all for removing it. Fixing it is trivial and shouldn't break too much code.

Re: Eliminate changing default tpe in Define

Posted: Mon Nov 21, 2016 5:25 am
by Demivec
Josh wrote:In my eyes the possibility to change the default type with define is a useless feature. Definitely it is a dangerous function, if you bring in this unintended in your code. In this case the problems can occur at a complete other place in your project. Have fun by finding your problem.
I disagree that it's a dangerous function. It only affects variables with an undeclared type. As Mistrel pointed out, there are error and warning messages that may help point out a mismatched default type.

I do agree with netmaestro's observation and care needs to be taken with includes and I think that this default should be tracked separately for modules.

No one has mentioned a practical use for it yet. Let me be the first. It can be used as part of a macro to generate code that uses one of the default types. Within the macro all variables would have declared types except the ones that would need to be customized. A define would be used at the beginning of the macro to select the needed type. It would be reset to the standard default type at the conclusion of the macro.

I know the example is contrived but it is an example.

If the truth be told though I wouldn't miss it if it were removed. :)