J
Jon Slaughter
I was wondering if maybe allowing "fields" for methods. The reason is to
encapsulate the data that is mainly used by the method and to prevent the
need of having to create new variables every time the function is called if
you know they need not change within the method.
In a sense these would be equivilent to passing arguments to the method or
equivilent to local variables... but these arguments or variables always
have the same run-time values in the method's scope.
So we could have
public void SomeFunc(Some Params, object O)
{
....
}
public void SomeFunc(Some Params)
{
object O = new Object;
....
}
(would waste cycles because we allocate and deallocate O every function call
even if O if O is some constant value w.r.t to the method. )
object O;
public void SomeFunc(Some Params)
{
(uses object O)
....
}
etc..
But we know that 99% of the time object O does not change in the methods
call.
Why not have something like
public void SomeFunc(Some Params)
[Object O = some value]
{
(uses object O)
....
}
and we can access O by SomeFunc.O or SomeFunc().O or whatever. (I'm not
saying the syntax has to be strictly as I have shown).
One could even has getters and setters for O with an ability for default
initialization
public void SomeFunc(Some Params)
[ private Object o;
public Object O
{
init {o = initial value;}
get {return o;}
set {o = value;}
}
}
{
(uses object O)
....
}
or how ever one really wants to do this. I know you can use the above
methods to do this but it seems that one looses the ability to encapsulate.
Ofcourse with a lot of variables it could get messy quick.
In essense a method would be very similar to a class but we wouldn't have to
do something like
public static class MyFunc
{
public return value;
private Object o;
public Object O
{
init {o = initial value;}
get {return o;}
set {o = value;}
}
MyFunc(some Params)
{
(uses O)
return value;
}
}
which is essentially what the above would be equivilent to. Here we can use
MyFunc.O and call MyFunc just like a method but the return value is hard to
use(although maybe the ability to return it directly or indirectly like this
would be could so one could do MyFunc.Result or MyResult = MyFunc()... and
one has to declare the constructur and stuff so its a little extra work.
Just seems like there could be some room for improvement?
Any ideas?
Thanks,
Jon
encapsulate the data that is mainly used by the method and to prevent the
need of having to create new variables every time the function is called if
you know they need not change within the method.
In a sense these would be equivilent to passing arguments to the method or
equivilent to local variables... but these arguments or variables always
have the same run-time values in the method's scope.
So we could have
public void SomeFunc(Some Params, object O)
{
....
}
public void SomeFunc(Some Params)
{
object O = new Object;
....
}
(would waste cycles because we allocate and deallocate O every function call
even if O if O is some constant value w.r.t to the method. )
object O;
public void SomeFunc(Some Params)
{
(uses object O)
....
}
etc..
But we know that 99% of the time object O does not change in the methods
call.
Why not have something like
public void SomeFunc(Some Params)
[Object O = some value]
{
(uses object O)
....
}
and we can access O by SomeFunc.O or SomeFunc().O or whatever. (I'm not
saying the syntax has to be strictly as I have shown).
One could even has getters and setters for O with an ability for default
initialization
public void SomeFunc(Some Params)
[ private Object o;
public Object O
{
init {o = initial value;}
get {return o;}
set {o = value;}
}
}
{
(uses object O)
....
}
or how ever one really wants to do this. I know you can use the above
methods to do this but it seems that one looses the ability to encapsulate.
Ofcourse with a lot of variables it could get messy quick.
In essense a method would be very similar to a class but we wouldn't have to
do something like
public static class MyFunc
{
public return value;
private Object o;
public Object O
{
init {o = initial value;}
get {return o;}
set {o = value;}
}
MyFunc(some Params)
{
(uses O)
return value;
}
}
which is essentially what the above would be equivilent to. Here we can use
MyFunc.O and call MyFunc just like a method but the return value is hard to
use(although maybe the ability to return it directly or indirectly like this
would be could so one could do MyFunc.Result or MyResult = MyFunc()... and
one has to declare the constructur and stuff so its a little extra work.
Just seems like there could be some room for improvement?
Any ideas?
Thanks,
Jon