Proposal: Type inference for variable definition/initialization using the 'auto' keyword.

Tim Lebedkov tim.lebedkov at googlemail.com
Sun May 17 12:17:12 PDT 2009


Hello Ruslan,

It would be really helpful if you could check the patterns on a larger
code base.
Not only to my proposal, but there is also one for using "final" like in:
final m = new JTable().getModel(); // m is automatically typed *and* final.

>  pattern for auto          : any variable definition.
some examples:
int a = t.getColumn();
for (int a: columns)...
class A {
   auto a = "asldfkjsdlfj";
}

>  pattern for 'usefull' auto: any variable definition with
> templates^H^H^H^H^H type parameters on left side.
Let's define "useful" as "with type name longer than 4 characters"
auto a = 5; // not useful because longer than "int a = 5;"
auto m = new JTable().getModel(); // useful because shorter than
TableModel m = new JTable().getModel()

>  pattern for diamond       : any variable definition with allocation
> expression at right side.
I'd say (I hope I understand the proposal right) any variable
definition with template based allocation like
List<String> a = new ArrayList<String>(); becomes
List<String> a = new ArrayList<>();

Thank You for the offer
--Tim

2009/5/16 Ruslan Shevchenko <rssh at gradsoft.com.ua>:
>
>
> Sorry, can I ask what exactly patterns you mean.
>
> I. e. is such approximation is correct (?)
>
>  pattern for auto          : any variable definition.
>  pattern for 'usefull' auto: any variable definition with
> templates^H^H^H^H^H type parameters on left side.
>  pattern for diamond       : any variable definition with allocation
> expression at right side.
>
>
> If this is correct, I will add one to set of coin patterns.
>
>>
>> You're right. These two classes are not statistically significant, but:
>> - number of lines where "auto" can be used is always >= the number of
>> lines where "diamond" can be used
>> - you have probably written many thousands of lines in Java. Don't you
>> have at least the feeling that there are at least 3-5 times more
>>   variable definitions without object creation than with it?
>> - (in case you do not have such feeling :-) I'd try to count lines on
>> a larger source base.
>>
>
>
>



More information about the coin-dev mailing list