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

Ruslan Shevchenko rssh at gradsoft.com.ua
Sun May 17 23:34:36 PDT 2009


I changed useful auto to be at least 7 symbols. Difference is still huge.
(It's not all data array yet;)

jetty:

all variable initializers       :       3687
initializers with type arguments or long type names     :       837
initializers with allocation and type arguments :       0

gwt-user:
all variable initializers       :       4208
initializers with type arguments or long type names     :       1673
nitializers with allocation and type arguments :       252

hibernate:
all variable initializers       :       10271
initializers with type arguments or long type names     :       4013
initializers with allocation and type arguments :       100


I will post more details with full report at evening/in GMT+2/.


> 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