Page 1 of 1
manual restriction for UseModule
Posted: Mon Aug 19, 2013 7:45 pm
by Regenduft
I think it would be nice to implement a keyword, which can be used in the DeclareModule section to hide stuff when importing the module by UseModule.
A example code might explain best what I mean (using "Hide" as the new keyword, even though "Explicit" might be the better):
Code: Select all
DeclareModule Foo
Hide #Version = "1.0"
Hide Declare Init()
Declare DoSomething()
EndDeclareModule
Module Foo
; module code
EndModule
UseModule Foo
Debug #Version ; doesn't work
Init() ; doesn't work
DoSomething() ; works as usual
Debug Foo::#Version ; works as usual
Foo::Init() ; works as usual
Foo::DoSomething() ; works as usual
The benefit of this would be, e.g. that you can code standard functions like "Init()", which are rarely accessed from the main code, and still use "UseModule" without the need to take care of an unique name for "Init()". This would ease the work when trying to write reusable templates.
Alternative keyword names to "hide" might be: Explicit, Direct, Internal or what ever.
Re: manual restriction for UseModule
Posted: Mon Aug 19, 2013 8:04 pm
by Little John
That would probably cause more confusion than it's worth.
When UseModule as it works now is not well suited for a particular program, then you can completely do without it, and just use always Foo::#Version etc.
Re: manual restriction for UseModule
Posted: Mon Aug 19, 2013 8:31 pm
by Regenduft
Little John wrote:That would probably cause more confusion than it's worth.
What kind of confusion could there be? (no rhetorical question)
Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 12:28 am
by Demivec
Regenduft wrote:I think it would be nice to implement a keyword, which can be used in the DeclareModule section to hide stuff when importing the module by UseModule.
An interesting idea, kind of like making the items
unfriend
ly procedures and variables.
Aside from that I wouldn't be against such a feature. I do share Little John's opinion that it isn't really necessary though.
Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 4:41 pm
by Little John
Regenduft wrote:Little John wrote:That would probably cause more confusion than it's worth.
What kind of confusion could there be? (no rhetorical question)
There is a
message by freak about this topic, which is worth reading. The summary is:
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
Your suggestion would encourage people to mix both styles, and this would decrease the readability of the code. Additionally, new users might e.g. erroneously think that "Hide" also applies if the full name with :: is used. Let's not make things unnecessary unclear.

Better keep it simple and straightforward.
And for example something like
Init() is normally best called inside the
Module part, and not at all in the
DeclareModule part. The purpose of the new Modules is to help us write cleaner code. So we better should do so, rather than asking for new ways to write less clean or clear code.

Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 6:52 pm
by Regenduft
Don't get me wrong: The enumeration of your statements doesn't mean that I disrespect you! ...it looks somehow offensive...
Little John wrote:[1]Your suggestion would encourage people to mix both styles
[/1], and
[4] this would decrease the readability of the code.
[/4] [2]Additionally, new users might e.g. erroneously think that "Hide" also applies if the full name with :: is used
[/2].
[4]Let's not make things unnecessary unclear.

Better keep it simple and straightforward.
[/4]
[3]And for example something like Init() is normally best called inside the Module part, and not at all in the DeclareModule part.
[/3] [4]The purpose of the new Modules is to help us write cleaner code. So we better should do so, rather than asking for new ways to write less clean or clear code.
[/4]
- I agree. That's the major point: I think it would ease the creation of reusable templates.
- Yes, your are right that "Hide" is a stupid keyword. But in my humble opinion "confusing" new users is not a good argument, since you find a lot of notes in the PureBasic documentation stating "only for experienced users". If you would not understand the keyword or don't like it, your don't have to use it. The first error message or a look into the auto complete suggestions would make things clear, when getting lost.
- Thinking of commands like "InitKeyboard()", I would say this is not necessarily true.
- Now I'm confused. I think, that it would actually increase readability, it is more straightforward and it would add some flexibility. The introduction of the new keyword would not really bring a new feature. You can do it right now, too. But with a lot of "crazy" code! Read beyond for some examples.
The "Macro Method" (this doesn't work at the moment, due to a PureBasic bug):
Code: Select all
DeclareModule UseFoo
Macro DoSomething_()
Foo::DoSomething()
EndMacro
EndDeclareModule
DeclareModule Foo
#Version = "1.0"
Declare.s Init()
Declare.s DoSomething()
EndDeclareModule
Module UseFoo
; void
EndModule
Module Foo
Procedure.s Init()
ProcedureReturn "initializing"
EndProcedure
Procedure.s DoSomething()
ProcedureReturn "doing something"
EndProcedure
EndModule
UseModule UseFoo
Debug Foo::#Version
Debug Foo::Init()
Debug DoSomething_()
The "Procedure Method":
Code: Select all
DeclareModule UseFoo
Declare.s DoSomething()
EndDeclareModule
DeclareModule Foo
#Version = "1.0"
Declare.s Init()
Declare.s DoSomething()
EndDeclareModule
Module UseFoo
Procedure.s DoSomething()
ProcedureReturn Foo::DoSomething()
EndProcedure
EndModule
Module Foo
Procedure.s Init()
ProcedureReturn "initializing"
EndProcedure
Procedure.s DoSomething()
ProcedureReturn "doing something"
EndProcedure
EndModule
UseModule UseFoo
Debug Foo::#Version
Debug Foo::Init()
Debug DoSomething()
The "Prototype Method":
Code: Select all
DeclareModule UseFoo
Prototype.s DoSomething()
Define DoSomething.DoSomething
EndDeclareModule
DeclareModule Foo
#Version = "1.0"
Declare.s Init()
Declare.s DoSomething()
EndDeclareModule
Module UseFoo
Define ProtoInit
If ProtoInit = 0
DoSomething = Foo::@DoSomething()
EndIf
EndModule
Module Foo
Procedure.s Init()
ProcedureReturn "initializing"
EndProcedure
Procedure.s DoSomething()
ProcedureReturn "doing something"
EndProcedure
EndModule
UseModule UseFoo
Debug Foo::#Version
Debug Foo::Init()
Debug DoSomething()
Offtopic: Damn... so cliché german... discussing everything to the very end...

Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 7:42 pm
by davido
@Regenduft
Keep discussing: I'm learning. Great!

Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 8:40 pm
by Little John
@Regenduft
In my opinion, your suggestion would cause more problems than it's worth.
I can't explain it better than I already did.
Re: manual restriction for UseModule
Posted: Tue Aug 20, 2013 9:01 pm
by Regenduft
@davido:
I'm quite not sure what you are exactly referring to, but I hope you won't adopt my bad coding style.
@Little John:
I guess we're at the point personal taste and "design philosophy". Thanks for showing up the possible bad side effects of my request. ( Although I don't completely agree with you.

)