Author |
Topic: Object Class library - CLASSLIB (Read 264 times) |
|
Andy Parkes
Developer
member is offline
Gender:
Posts: 25
|
|
Re: Object Class library - CLASSLIB
« Reply #15 on: Feb 13th, 2014, 11:25am » |
|
Quote:By 'in use' I mean after one or more PRIVATE statements have been executed but before the ENDPROC or end-of-function. In other words, whilst one or more PRIVATE variables are 'in scope'. |
|
Thank you, I wasn’t sure if it had meant simply after their declaration (in scope or otherwise), and so I could not see the logical reasons why the use of PRIVATE variables in specific situations, might result in code with a potential bug. While I do often use private variables, in my ignorance I have been cautious. In practice, this has mostly meant that I have tended to avoided their use in reusable/library code.
So, I have gladly removed the need to pass a structure variable pointer in CLASSLIBA, and have taken the opportunity to re-introduce PROC_new() for compatibility with CLASSLIB. Incompatibility will occur only if a class definition relies upon a contained-class-constructor being called when a new object is instantiated.
http://wiggio.com/yui/folder/stream_file.php?doc_key=/tcVC37nCLqGWtAobYPK4NgJeZvtKr1Det6E0IZGWNU=
Thanks again
Andy
|
|
Logged
|
|
|
|
admin
Administrator
member is offline
Posts: 1145
|
|
Re: Object Class library - CLASSLIB
« Reply #16 on: Feb 13th, 2014, 2:45pm » |
|
on Feb 13th, 2014, 11:25am, Andy Parkes wrote:have taken the opportunity to re-introduce PROC_new() for compatibility with CLASSLIB. |
|
At some point I may consider incorporating in the 'official' CLASSLIB some features similar to those you have added. But before doing that I would be interested to hear from other users whether they would find them useful.
In particular do people feel that being able to pass parameters to 'new' is a worthwhile enhancement compared with explicitly calling a constructor? In other words is there a significant advantage in doing:
Code: PROC(FN_new(myObject{}, myClass{}))(parameters) compared with the existing method:
Code: PROC_new(myObject{}, myClass{})
PROC(myObject.ctor)(parameters) My own feeling is that it's hard to justify the extra complexity in the library for what amounts to syntactic sugar, but as I'm not an OO programmer I'm not the best person to judge.
Richard.
|
|
Logged
|
|
|
|
Andy Parkes
Developer
member is offline
Gender:
Posts: 25
|
|
Re: Object Class library - CLASSLIB
« Reply #17 on: Feb 13th, 2014, 7:52pm » |
|
Many objects need just one constructor (with parameters), and so in those cases the existing syntax does not enforce the class API. It would be possible for someone to instantiate an object which requires a constructor, without calling that constructor, and it would be possible for different class designers to use different names for their constructor. Encapsulating the constructor is obviously a good idea. However, where more than one constructor is needed, the client will still have to be aware of which constructor to call, in which case there is no disadvantage to using the existing syntax.
So basically, the 'proposed' syntax provides encapsulation in one additional case relative to the existing syntax, i.e. when only one constructor with parameters is required.
I agree that it amounts to syntactic sugar, and I don't know if it was worth adding those bits-and-bobs. So I would also be interested to see what other people think.
It occurred to me that it might be possible to simulate polymorphism for constructors, but I have some very ugly code in mind (involving error trapping), that if it worked, would result in very sweet syntax, but it would be going against the grain of BB4W. I think CLASSLIB strikes such an excellent balance, and is so compact, that its right to carefully consider small changes.
Andy
|
|
Logged
|
|
|
|
Andy Parkes
Developer
member is offline
Gender:
Posts: 25
|
|
Re: Object Class library - CLASSLIB
« Reply #18 on: Mar 7th, 2014, 11:57am » |
|
Hi folks,
I have made another change to CLASSLIBA that is possibly worth mentioning:
http://wiggio.com/yui/folder/stream_file.php?doc_key=ck73Bdku6hyAO+SzuM5KN0kYaKtjKAlqhvXG7mwovhQ=
The change allows arrays to be passed as arguments to methods (as is normal for other functions and procedures). For example, the following code does not work with CLASSLIB:
Code:
INSTALL @lib$ + "CLASSLIB"
DIM Class{method1, method2}
PROC_class(Class{})
PROC_new(Obj{},Class{})
PROC(Obj.method1)
PROC_discard(Obj{})
END
DEF Class.method1
LOCAL a%(), A%
DIM a%(10)
FOR A%=1 TO 10
a%(A%) = A%
NEXT
PROC(Class.method2)(a%())
ENDPROC
DEF Class.method2 (a%())
LOCAL A%
FOR A%=1 TO DIM(a%(),1)
PRINT a%(A%)
NEXT
ENDPROC
I have also added a tiny bit more syntactic-sugar, but you can easily delete anything you find unnecessary.
Thanks
Andy
|
|
Logged
|
|
|
|
Andy Parkes
Developer
member is offline
Gender:
Posts: 25
|
|
Re: Object Class library - CLASSLIB
« Reply #19 on: Mar 7th, 2014, 12:08pm » |
|
Hi folks,
I found a bug immediately after uploading, so have deleted CLASSLIBA for the time being, and will upload it again later after its fixed.
Thanks
Andy
|
|
Logged
|
|
|
|
admin
Administrator
member is offline
Posts: 1145
|
|
Re: Object Class library - CLASSLIB
« Reply #20 on: Mar 7th, 2014, 1:32pm » |
|
on Mar 7th, 2014, 11:57am, Andy Parkes wrote:The change allows arrays to be passed as arguments to methods (as is normal for other functions and procedures). |
|
In case you thought otherwise, the inability to accept array parameters is a bug, not an intentional 'feature' of CLASSLIB! Clearly it needs to be rectified in the 'official' library, rather than being treated as an 'extension'.
I have therefore corrected CLASSLIB.BBC to accept arrays as formal parameters of methods. Version 0.95 may be downloaded from here.
Richard.
|
|
Logged
|
|
|
|
Andy Parkes
Developer
member is offline
Gender:
Posts: 25
|
|
Re: Object Class library - CLASSLIB
« Reply #21 on: Mar 7th, 2014, 3:25pm » |
|
Here is CLASSLIBA with it's spoonful syntactic-sugar:
http://wiggio.com/yui/folder/stream_file.php?doc_key=phUocicEhoLWSL0X5QClkwa8dRM+l0mRNT8+YQV1wfc=
Before uploading, I solved the issue with the same method, only implementing a FOR loop. Before that my failed attempt used INSTR thinking that I could achieve better performance, but it created some delicate situations. Now having now seen your solution, I have copied it as its more elegant, and it keeps CLASSLIBA fundamentally identical to CLASSLIB.
Many Thanks
Andy
|
|
Logged
|
|
|
|
|