[Implemented] Eliminate changing default tpe in Define
[Implemented] Eliminate changing default tpe in Define
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.
sorry for my bad english
Re: Eliminate changing default tpe in Define
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Eliminate changing default tpe in Define
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.
BERESHEIT
Re: Eliminate changing default tpe in Define
Code: Select all
Define.b
a=1000
Debug a
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.Line 3: Overflow error: a 'byte' value (.b) must be between -128 and +255.
Re: Eliminate changing default tpe in Define
it is a documented feature, personally I alway declare the variable type, relying on defaults seems sloppy to me.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Eliminate changing default tpe in Define
Agreed, I don't see much upside to it either. I never use it.
BERESHEIT
Re: Eliminate changing default tpe in Define
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.
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: Eliminate changing default tpe in Define
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.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 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.
