Page 1 of 1
[PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:07 pm
by helpy
Now:
Code: Select all
DeclareModule mod
Structure PublicStructure
;...
EndStructure
#PublicConstant = 1
Global PublicVariable
Declare PublicProcedure()
EndDeclareModule
Module mod
Structure PrivateStructure
;...
EndStructure
#PrivateConstant = 2
Global PrivateVariable
Procedure PublicProcedure()
;...
EndProcedure
Procedure PrivateProcedure()
;...
EndProcedure
EndModule
The same with Public keyword:
Code: Select all
Module mod
Public Structure PublicStructure
;...
EndStructure
Structure PrivateStructure
;...
EndStructure
Public #PublicConstant = 1
#PrivateConstant = 2
Public Global PublicVariable
Global PrivateVariable
Public Procedure PublicProcedure()
;...
EndProcedure
Procedure PrivateProcedure()
;...
EndProcedure
EndModule
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:11 pm
by Little John
+1
Much better, great idea!
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:14 pm
by Bisonte
That sounds good.
And without an extra block like "DeclareModule/EndDeclareModule" IMHO easier to read and reuse...
+1
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:17 pm
by ts-soft
Fred wrote:I see what you mean. We have discussed this manner before going to this implementation, and splitting the module in 2 allows to clearly separate the public interface from the private implementation. Mixing "public" in the module can be hard to manage to have a clear overview of what is public. Also it allows to cross link 2 modules as you can write the declaration and the module somewhere else, for example:
Code: Select all
DeclareModule TestMap
EndDeclareModule
DeclareModule TestList
EndDeclareModule
Module TestMap
UseModule TestList
EndModule
Module TestList
UseModule TestMap
EndModule
It can be useful in some case.
-1 for public keyword!
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:27 pm
by uwekel
Yes, yes, yes +1 for Public keyword!
I hate the extra declarations where you have to copy code which has already been written elsewhere. Also it is more Basic standard

We could have both!
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:41 pm
by eddy
+1
DeclarePublic...
EndDeclarePublic section would be possible.
Code: Select all
Module PartTime
Structure JOB
time.i
EndStructure
Declare DoJob(*job.JOB)
DeclarePublic
Procedure FinishJob(time)
DoJob(job.JOB)
job\time=time
EndProcedure
EndDeclarePublic
Procedure DoJob(*job.JOB)
EndProcedure
EndModule
PartTime::FinishJob(0)
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 7:58 pm
by helpy
@ts-soft:
OK! I understand this argument.
Because of one-pass-compiler it would not possible to cross-use modules without pre-declaration.
But I am not sure, if cross-use of modules will be of much usefulness.
Cross-use of modules will cause
circualr dependencies.
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 8:05 pm
by Franky
I think, Fred has a point in what he sais, this might lead to Headerfiles like .h for C-Projects.
Public looks great for the first view, I wanted to post "Why not add Public and still have DeclareModule available?". But while writing I realized, that this would make the PureBasic-Codes very heterogen, less readable and less disciplinated.
Short: -1 for Public, sorry guys
Best regards
Franky
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 8:34 pm
by Fred
Why ? It works as you have a declaration with no implementation, so it's self sufficient:
Code: Select all
DeclareModule String
Declare StringOutput(Message$)
EndDeclareModule
DeclareModule Memory
Declare Allocate(Size)
EndDeclareModule
Module Memory
UseModule String
Procedure Allocate(Size)
*Buffer = AllocateMemory(Size)
If *Buffer = 0
StringOutput("Allocate failed")
Else
StringOutput("Allocate success")
EndIf
ProcedureReturn *Buffer
EndProcedure
EndModule
Module String
UseModule Memory
*NewString = Memory::Allocate(1000)
Debug "*NewString = " + *NewString
Procedure StringOutput(Message$)
Debug Message$
EndProcedure
EndModule
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 10:14 pm
by helpy
Hi Fred,
Fred wrote:Why ? It works as you have a declaration with no implementation, so it's self sufficient...
I did not say that circular dependencies would not work.
It could (not will) cause problems.
Definition of circular dependency (wikipedia):
In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly.
In your example one module needs the orther one to function.
Therefore there is a circular dependency.
But I understand your point.
Module is a great feature for PureBasic and I will use it!
... independet of the implementation of this feature!
Thank you (and also thanks to your team) for your work.
cu,
guido
Re: [PB 5.20] Public keyword instead of DeclareModule
Posted: Sat Jun 22, 2013 11:33 pm
by BorisTheOld
A few more milli-seconds of compile time would more than compensate for the extra coding, and propensity for errors, that a single-pass compiler causes.
In a large application, PB requires vast amounts of manual declaration code to do what a compile is better able to do in two passes. Unfortunately, we're stuck with a single-pass compiler, so this means a simple "public" attribute won't work.
I think the secret to using PB modules is to treat all module data as private, and to have a minimum of public procedures. Global modules would be written to share data between the other modules. This global data would be private to the global module, but would be accessible via public procedures. This is similar in concept to class get/set methods.
This technique works best if all code is contained in modules.