-
Notifications
You must be signed in to change notification settings - Fork 855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding inline type hint for 'var' variables #4522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code looks good - very compact for what it does which is great. There is probably going to be a need to toggle those inline features individually? Or is all-or-nothing ok for users which use it?
standard rant for features which modify the text:
not a fan of IDEs which display information inline which is not in the code, since it influences how code is written/formatted and makes it somewhat IDE dependent. Also worth noting that simply declaring the type takes less space than using var + inline hints in most cases (e.g in the example given above).
Removing information just to add it right back a few chars to the right via an IDE assisted feature is a bit weird to me :)
I don't think enabling it is a good default since it is too invasive (but the decision has been already made).
-0 on this for me. I agree with @mbien here -
In general inline hints serve a purpose, but I've definitely noticed their influence on writing / formatting - I think how we display the data might need some rethinking. Showing parameter names and other information that cannot (easily) be in the source makes more sense than showing the type information for |
just a thought: If the IDE is already changing the text, why not put the type where it belongs? A direct way of helping with readability of code which overuses This wouldn't change the syntax of the language and wouldn't incentivize overuse of var / change of formatting / create IDE dependence. Maybe there is a way to solve those use cases differently so that NB doesn't have to enable inline hints by default (even though the feature itself is probably required anyway since some users might want to have feature parity with other IDEs) |
Sorry for belated reply. A few comments: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks right. The discussion whether or not the var construct should be used and types should be shown is IMHO independent from this implementation. I personally don't user inline hints, BUT if I had to read code using var extensively, it could be helpful to activate inline hints temporary. It is IMHO in line with the other inline hints.
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:
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: the jep would suggest to use a descriptive name when using var, since the type could be anything here: with hints this starting to get verbose again: and a dev might ignore the advice and switch back to a short name since the IDE is providing this info anyway: 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. 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. |
I think this moves from a technical review to a philosophical question. I don't think the IDE should make decisions what is "a right way" to code. If a team/person decides, to use So from my POV it comes down to these questions:
We might indeed better configurability for the feature (for example to disable var type display and enable parameter name hints), but that is a different discussion. |
Yes! If the IDE shouldn't make the decision we should keep it disabled by default (it is enabled since NB 15). I approved this PR too - from a technical perspective I have no complains. "Good defaults" are very important, esp for NetBeans which has traditionally been an IDE which needed only a few clicks before it was ready to go. Having this fairly intrusive hint enabled by default, does already make a decision for the user how var should be used. To not make this decision ahead of time, we should reconsider having this enabled by default at the very least. (and maybe explore better ways how to aid with var-readability problems if there is demand) if var is used to reduce "ceremony" (again taking the words from the jep), having this inline hint enabled would make it an anti-feature. Since it displays the type in the exact situations where you truly don't care about the type or want to hide it due to verbosity. While at the same time incentivizing the use in trivial situations, like the The language feature was certainly not implemented with the intention that the IDEs would one day add the type right next to the keyword again (by default) - this negates it's purpose - its there to hide the type. If a team wants to use it that way, fine, but I don't think this is a good default that is all I am trying to say :) |
+1! And why I disagree with @matthiasblaesing that this is "philosophical" and doesn't belong in the review. Where else do we review usability?!
Firstly there may be a point to having different inline hint defaults in editable vs non-editable code. Not that that covers all bases. Secondly, could this particular hint be moved to the end of the line? Similar to #2365 (and the still open #2785). Direct use of |
This is what I have been desperately waiting for! |
The team I work in, decided to make extensive use of var, regardless of the context. As a result, I have to move my cursor to the method and hit The pragmatic objective should be the ease of reading and writing code and making the type always apparent, but not overly verbose. Therefore: As I see it:
In practice, the type hint would be shown only if:
it would look like: |
@jlahoda I can remember your implementation for virtual-text-prepend: #1247 (comment) so I also want to add some hints to other files than Java and I was searching not for prepending but for appending text, what you already add but I'm missing the point of finding the keyword virtual-text-append. All of your implementation (showing types of chaining collections and var implementation) looks like some hardcoded just for those things without having such a keyword. Is this correct? Shouldn't we add this also as a keyword (virtual-text-append) to make this more consistent with the other implementation to can be reused in other contexted. I know cases where we can have virtual-text-prepend, virtual-text-append and virtual-text-above. |
Merged via #5013 |
Adding inline type hint for 'var' variables:
^Add meaningful description above
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log
) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.