Allow redefinition of PureBasic functions within modules

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Allow redefinition of PureBasic functions within modules

Post by Tenaja »

luis wrote: Wed Sep 15, 2021 12:10 pm
I wouldn't call that "elegant" by any stretch of imagination, but in an emergency it can at least solve a conflict by hiding it.
It seems, to me, useful for temporary testing... But the maintenance nightmare would be evident the first time an editor, unaware of the macro, posted on here that there was a bug in the PB ReadData command. Oops. Narrow that down to it's minimum code example!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Allow redefinition of PureBasic functions within modules

Post by Mistrel »

It's fine as long as you don't UseModule with a module that has such a macro. I don't recommend this keyword except for very small blocks of code where it can improve readability. This isn't an issue with modules but rather a side effect of macros in general. There's nothing to stop you from redefining all of PureBasic internal functions at your leisure.

Code: Select all

Macro MessageRequester(a, b, c=0)
  Debug "I do nothing!"
EndMacro

MessageRequester("","")
This is actually a GOOD thing and allows macros to be used in this way to fix bugs with immediate results. But I agree that overriding internal functions globally can be dangerous when caught unaware. That is why being able to redefine internal functions within a module is safer than what would be possible otherwise.

But this request isn't about overriding internal functions for that purpose. This feature request is pointing out the problem of scope within modules. The fact that we have to use macros to do this at all is the point. We just shouldn't have to.

The workaround is cool. But it's also super gross to use in practice and makes unreadable code.
Post Reply