[ 
https://issues.apache.org/jira/browse/LUCENE-10136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17423895#comment-17423895
 ] 

Robert Muir commented on LUCENE-10136:
--------------------------------------

+1, we should use the latest language features. 

A lot of other language features (such as lambdas) can lead to 
horrible-to-understand code as well. But the general problem is usually the 
programmer who believes that the least amount of chars/lines as possible is 
best.

For example from my perspective, in TermQuery.java there is nowhere that this 
feature should be used.

In BooleanQuery.java, I think i'd only use it where we dedup clauses. The 
generics really just add unnecessary verbosity when looping over Map.Entry's. 
The {{entry}} local varname is a good one, so its a nice candidate to use the 
{{var}} keyword. 

{code}
for (Map.Entry<Occur, Collection<Query>> entry : clauseSets.entrySet()) {
  ...
}
{code}

But yeah, if the programmer writes {{var x}} instead of {{Query query}}, they 
are just unnecessarily obfuscating the code. Whenevr {{var}} is used, we should 
try to use good local variable names to increase readability. And certainly it 
should not be used to save 2 or 3 characters (e.g. "var" vs "Query"), that 
isn't helping anything.


> Lift the restriction on using 'var' variables
> ---------------------------------------------
>
>                 Key: LUCENE-10136
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10136
>             Project: Lucene - Core
>          Issue Type: Wish
>    Affects Versions: main (9.0)
>            Reporter: Dawid Weiss
>            Priority: Trivial
>
> Can we lift the restriction on using 'var' on the main branch? I know it's a 
> double-edged sword and sometimes it leads to unreadable code, especially when 
> you invoke a method, for example:
> {code}
> var foo = myMethodThatDoesSomething();
> {code}
> but in many, many, *many* cases the var keyword shortens the code and the 
> type is obvious from the context. This happens in loops, try-with-resources 
> and local variables. 
> {code}
> for (var it = array.iterator(); it.hasNext();) { ... }
> try (var foo = new MyFoo()) { ... }
> {code}
> I'd say - let's allow vars (and other language features) and use common 
> sense. If something is not clear in the context, type the variable. If 
> something is obvious, use shortcuts.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to