mbien commented on PR #4522:
URL: https://github.com/apache/netbeans/pull/4522#issuecomment-1230201487

   > -replacing `var` with an explicit type - even if we found a way to replace 
the views, it would still change the formatting, correct? For example, if we 
replace `var` with `Map<? extends String, ? extends String>`, the length of the 
text will be different?
   
   it would change the formatting too. The differences are in the other aspects 
as e.g. it doesn't incentivize overuse of var. Replacing var with the type via 
a toggle would purely work as reading aid, while inline hints change the syntax 
of the language and change how code is written / incentivize overuse.
   
   If var is used correctly, there is no reading aid needed, since:
    - it is used in places where the type truly doesn't matter to reduce 
ceremony as the JEP states
    - it can be used where the type is obvious or if its defined somewhere else
    - (..)
   
   e.g to use a Map of Maps with verbose generic types (maybe even with upper 
or lower bounds) you can simply use var and extract the elements later with the 
concrete type. Generic declarations can quickly get out of hand - var helps 
here a lot.
   
   while looking at:
   `Path root = manager.getRoot();`
   
   the jep would suggest to use a descriptive name when using var, since the 
type could be anything here:
   `var rootPath = manager.getRoot();`
   
   with hints this starting to get verbose again:
   `var rootPath : Path = manager.getRoot();`
   
   and a dev might ignore the advice and switch back to a short name since the 
IDE is providing this info anyway:
   `var root : Path = manager.getRoot();`
   
   first of all: this isn't java. Second: the initial version is the most 
compact and the easiest to read since var is used here in a completely 
unnecessary situation.
   `Path root = manager.getRoot();`
   
   Thats why I spoke out for not enabling it by default (in #4358), and maybe 
trying to find a better way of providing reading aid for code which overuses 
var, esp in a way which doesn't influence how the code is written / incentivize 
overuse. 
   
   E.g. having a toggle which replaces var with the type would not influence 
how devs write code - it would be a pure reading aid devs could enable it when 
needed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to