[Implemented] Eliminate changing default tpe in Define

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

[Implemented] Eliminate changing default tpe in Define

Post 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.
sorry for my bad english
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Eliminate changing default tpe in Define

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Eliminate changing default tpe in Define

Post 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.
BERESHEIT
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Eliminate changing default tpe in Define

Post 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.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Eliminate changing default tpe in Define

Post by jack »

it is a documented feature, personally I alway declare the variable type, relying on defaults seems sloppy to me.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Eliminate changing default tpe in Define

Post by netmaestro »

Agreed, I don't see much upside to it either. I never use it.
BERESHEIT
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Eliminate changing default tpe in Define

Post by davido »

+1
DE AA EB
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Eliminate changing default tpe in Define

Post 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.
Image
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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Eliminate changing default tpe in Define

Post 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. :)
Post Reply