#137633 - 2005-04-08 11:17 PM
concept of namespace?
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
We already have a DIM that can scope variable explicitly. By default any instantiated variable is "Global" in scope. Functions are are Global.
What is missing is a way to maintain and address those specially defined variables that are currently out of scope by namespace or package. We could scope functions in different packages or namespaces.
Maybe...
@scriptname:$A or other similar convention
or an explicit KiXtart command that defines a namespace.
package Myfunctions function A()...Endfunction function B()...Endfunction
Package OtherFunctions function A()...Endfunction
If this construct was established then were could have functions and variable by the same name but stored in different scripts or sections of a script and called independently of each other.
ShawnsScript:functionA() MyFunctions:functionA()
Maintaining a function library would be greatly enhanced.
|
Top
|
|
|
|
#137635 - 2005-04-12 08:26 PM
Re: concept of namespace?
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I thought this would generate a few more responses than just one...
|
Top
|
|
|
|
#137636 - 2005-04-12 08:54 PM
Re: concept of namespace?
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
The only benefit I can see with this is testing variations of functions. Maybe I am not seeing the "whole picture?"
Kent
|
Top
|
|
|
|
#137638 - 2005-04-13 07:57 PM
Re: concept of namespace?
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If this namespace notion would be implemented, I think you could store your static vars there. Code:
package NetworkLib dim $counter function A($a, $b) dim $counter for = $counter = 0 + NetworkLib::$counter to 5 + NetworkLib::$counter ;do stuff next NetworkLib::$counter = $counter endfunction package Main ;more code NetworkLib::A($foo,$bar) ;print last record processed ? "the next record to process is record number: " + NetworkLib::$counter
This probably is not what you are looking for but I think it is better than globals.
|
Top
|
|
|
|
#137639 - 2005-04-13 08:13 PM
Re: concept of namespace?
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
As far as "file scope" if you 'Dim' a var at the beginning of a script "A" and call that script from script "B". Script "B" will not be able to see those script "A" vars because they are out of scope. Richard, is this type of action what you defined as "file scope"?
Test script for scopiing. Execute test.kic which calls test2.kix. Code:
Break on Global $TestA $TestA="a" Dim $TestE $TestE = "e" Call "test2.kix" ? "in test TestA ="+$TestA ? "in test Test2B="+$Test2B ? "in test Test2C="+$Test2C ? "in test Test2D="+$Test2D ? "in test TestE ="+$TestE Code:
Break ON Dim $Test2B $Test2B = "b"
Global $Test2D $Test2D = 2
if $Test2B="b" Dim $Test2C $Test2C="c" endif ? "in test2 TestA ="+$TestA ? "in test2 Test2B="+$Test2B ? "in test2 Test2C="+$Test2C ? "in test2 Test2D="+$Test2D ? "in test2 TestE ="+$TestE ?
|
Top
|
|
|
|
#137640 - 2005-04-14 10:18 AM
Re: concept of namespace?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
As far as "file scope" if you 'Dim' a var at the beginning of a script "A" and call that script from script "B". Script "B" will not be able to see those script "A" vars because they are out of scope. Richard, is this type of action what you defined as "file scope"?
Not quite. You have declared a local variable, so it is not visible within functions defined in the same file.
Consider a library where you want constants or variables which are visible to functions and code within the library but not outside the file scope. The constants or variables have to be global to be visible within the function. If they are global then they are also visible outside the file scope, which is not what you want. You will also get a clash with an already defined global of the same name.
Namespaces are pretty close to doing the job, as a "Global" variable restricted to a namespace would effectively be a static variable in the namespace scope.
For the sake of sanity I don't think namespaces should be inherited, as they'd get very nasty very quickly.
|
Top
|
|
|
|
#137641 - 2005-05-12 03:36 PM
Re: concept of namespace?
|
Sluice
Fresh Scripter
Registered: 2001-11-13
Posts: 19
Loc: Romsey, England
|
Is there any mileage in the idea of being able to drill down to a local constant or variable within a function/sub within a library, or is that going too far? This might allow the script to grab a variable from within a remote function and use it or modify it locally. I'm not sure how this might be used, or whether it's taking object programming too far.
|
Top
|
|
|
|
#137642 - 2005-05-12 04:06 PM
Re: concept of namespace?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Is there any mileage in the idea of being able to drill down to a local constant or variable within a function/sub within a library, or is that going too far? This might allow the script to grab a variable from within a remote function and use it or modify it locally. I'm not sure how this might be used, or whether it's taking object programming too far.
It's actually the complete reverse of object programming
The idea of an object is that the innards (code, data) is absolutely private and untouchable. The object might expose data as properties, but they are abstracts of what the real data is in the object.
Variables are not persistent - when a function exits they are destroyed so there is nothing to access or change.
If you can think of a useful application of accessing private function data that can't be met by other methods then post again. There's no point in adding functionality which will never be used
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 259 anonymous users online.
|
|
|