Modules - Optional Prefix / Suffix for UseModule

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Modules - Optional Prefix / Suffix for UseModule

Post by c4s »

There is a high chance that the public procedure/variable/constant names of different modules clash when using UseModule. In that situation Fred and Freak suggest to already use prefixes in the module.
In my opinion this isn't the best solution at all: In a module about e.g. animation I know what it's all about, so there is no need to call the only creation procedure "CreateAnimation()" etc. Isn't even not having to take care of unique names (which can get pretty long most times) one of the great advantages of modules?!

So why not simply introduce a straightforward "workaround"? My suggestion is an optional Prefix / Suffix parameter for UseModule. It could look like this:

Code: Select all

DeclareModule ImagePNG
  Load()
EndDeclareModule

DeclareModule ImageJPG
  Load()
EndDeclareModule

DeclareModule ImageBMP
  Load()
EndDeclareModule

UseModule ImagePNG Prefix PNG_
UseModule ImageJPG Suffix JPG
UseModule ImageBMP

PNG_Load()  ; Load() from ImagePNG
LoadJPG()  ; Load() from ImageJPG
Load()  ; Load() from ImageBMP
This would also help converting existing code to modules. ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!