I am one of the people using var, and this mostly comes from me doing “int” and 
having IntelliJ fix it (faster than typing out Future<List<Future<Map<String, 
TableMetadata.Builder>>>>)… so its a faster version for me…

Personally I find that while I am writing the code I like var, but as I hone it 
I tend to remove it to improve readability.  Some places seem fine to me such 
as loops [1], or when deconstructing stuff like Pair [2], but at least in my 
own writing I tend to avoid/limit it in the final patch.  Places I have found 
it hard to work with are stuff like saving the output of a method [3], this 
gets really hard to read and review.

Personally I don’t agree with flat out banning it, but do agree with advocating 
for limiting it to places where the type is easy for readers to handle.  We 
almost never add types to lambda, so if this isn’t a concern there then there 
are places where “var” also works.


Examples:

1: 
List<TableMetadata> tables = …
for (var table : tables) // honestly no different than tables.forEach(table -> 
…)
 …

2:
void consume(Pair<String, TableMetadata> pair)
{
  var name = pair.left;
  var metadata = pair.right;
  …

3:
var result = doWork(…);
If (result.pending) // what is the type of result?
  ...

> On Oct 29, 2024, at 11:19 AM, Štefan Miklošovič <smikloso...@apache.org> 
> wrote:
> 
> Yes, for now it is pretty much just in SAI. I wanted to know if this is a 
> thing from now on or where we are at with that ...
> 
> I am afraid that if we don't make this "right" then we will end up with a 
> codebase with inconsistent usage of that and it will be even worse to 
> navigate in it in the long term. 
> 
> I would either ban its usage or allow it only in strictly enumerated 
> situations. However, that is just hard to check upon reviews with 100% 
> accuracy and I don't think there is some "checker" to check allowed usages 
> for us. That being said and to be on the safe side of things I would just ban 
> it completely. 
> 
> Sometimes I am just reading the code from GitHub and it might be also tricky 
> to review PRs. Not absolutely every PR is reviewed in IDE, some reviews are 
> given without automatically checking it in IDE too and it would just make 
> life harder for reviewers if they had to figure out what the types are etc 
> ... 
> 
> On Tue, Oct 29, 2024 at 7:10 PM Brandon Williams <dri...@gmail.com 
> <mailto:dri...@gmail.com>> wrote:
>> On Tue, Oct 29, 2024 at 12:15 PM Štefan Miklošovič
>> <smikloso...@apache.org <mailto:smikloso...@apache.org>> wrote:
>> > I think this is a new concept here which was introduced recently with 
>> > support of Java 11 / Java 17 after we dropped 8.
>> 
>> To put a finer point on that, 4.1 has 3 hits, none of which are valid,
>> while 5.0 has 172.  If 'sai' is added to the 5.0 grep, 85% of them are
>> retained.
>> 
>> Kind Regards,
>> Brandon

Reply via email to