Modules and name clashing.

Just starting out? Need help? Post your questions and find answers here.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Modules and name clashing.

Post by luis »

freak wrote: Imho, these are the two styles that are useful with Modules
- give descriptive names that stand on their own, use UseModule and only write the full name to avoid (rare) conflicts
- give shorter names for simplicity inside the module and write the full name outside to keep the meaning of the call clear

I agree those are the two sensible options.

I find the second option not particularly appealing because of the need to qualify every constant passed to the module:

Code: Select all

DeclareModule test
 #const1 = 10
 Declare proc(par)
EndDeclareModule

Module test
 Procedure proc(par)
  Debug "proc" + par
 EndProcedure
EndModule

test::proc(test::#const1)
I would really dislike the need of doing this for every constant associated to the library, at this point I can just use the old prefix method (three letters plus underscore in front of procs, macros, constants, etc.).

The discussion here was intended by me as worst case scenarios, when you already did what was sensible to do but wasn't enough to avoid conflicts.
I like to analyze the worst cases even when they can be avoided most of the time, to know what my options are when common good practices are not enough.
I'll have to experiment a little with a real lib to see what's the option I feel more comfortable with, if any.

Thanks for the suggestions
"Have you tried turning it off and on again ?"
A little PureBasic review
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Modules and name clashing.

Post by uwekel »

freak wrote:There is also a HideModule command which closes the module again.
I think EndUseModule would better fit into PB syntax.
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Modules and name clashing.

Post by User_Russian »

uwekel wrote:I think EndUseModule would better fit into PB syntax.
No, if you follow the PB syntax, it should be CloseModule.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Modules and name clashing.

Post by luis »

User_Russian wrote:
uwekel wrote:I think EndUseModule would better fit into PB syntax.
No, if you follow the PB syntax, it should be CloseModule.
In this very same thread
freak wrote: This is why the keyword is called "UseModule" and not "OpenModule": Opening something implies that it needs to be closed after use. But that is not the common use case here. You can just "use" the module and never "unuse" it.
And anyway has just been changed in B3 to "UnuseModule" (bleah :) )
"Have you tried turning it off and on again ?"
A little PureBasic review
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Modules and name clashing.

Post by uwekel »

luis wrote:And anyway has just been changed in B3 to "UnuseModule" (bleah :) )
Outch! :?
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Post Reply