S
steve donovan
Hi everyone,
I was wondering if anybody had made a proposal for deducing variable
type in assigments. This is in effect exactly what is happening in
"Dim list As new ArrayList()" and a variant of this idea is being
considered for the new C++ standard (as a use for the obsolete 'auto'
keyword)
In effect, the idea is to reduce unnecessary typing. Rather than:
ArrayList list = new ArrayList()
we can say:
let list = new ArrayList() //(or 'dim','var', or whatever)
There is no serious magic involved here; the compiler must work out the
type of the initialization expression anyway, and will use that type
for the new variable 'list'. I've personally implemented for a C++
interpreter and it was not a difficult feature to add.
There are interesting complications when initializing a variable with
an expression, because it could return a derived class which is not
publically available, but I'm sure these issues could be worked out.
steve d.
I was wondering if anybody had made a proposal for deducing variable
type in assigments. This is in effect exactly what is happening in
"Dim list As new ArrayList()" and a variant of this idea is being
considered for the new C++ standard (as a use for the obsolete 'auto'
keyword)
In effect, the idea is to reduce unnecessary typing. Rather than:
ArrayList list = new ArrayList()
we can say:
let list = new ArrayList() //(or 'dim','var', or whatever)
There is no serious magic involved here; the compiler must work out the
type of the initialization expression anyway, and will use that type
for the new variable 'list'. I've personally implemented for a C++
interpreter and it was not a difficult feature to add.
There are interesting complications when initializing a variable with
an expression, because it could return a derived class which is not
publically available, but I'm sure these issues could be worked out.
steve d.