The X-Ray mode may prove to be particularly useful in this case, letting you see implicit hints only for a moment when you want to make sure what they are, and then they will disappear again. Implicit hints show information about implicit arguments and implicit conversions that the data in question will undergo during compilation – but given their nature, they may render the code less readable. However, this can also make it challenging to understand where values come from or how types are converted. Scala supports implicit conversions and parameters, which can significantly reduce boilerplate code. Method chain hints are a great way to learn intermediate data types as you write a chain of transformations and avoid mistakes. It might be particularly useful in Scala, where variable types are not always explicitly visible in the code.Ĭhaining methods is an idiomatic way of writing complex data transformations in Scala. Type hints are inlay hints showing inferred types of fields, parameters, as well as values created via destructuring, lambda expressions, or stream operations. If a given type of additional information is turned on permanently, it will be displayed regardless of your X-Ray settings. But remember that each type can also be turned on permanently in Settings | Editor | Inlay Hints and in Settings | Editor | General | Appearance for methods separators and indent guides. You can switch them on and off in Settings | Languages & Frameworks | Scala | X-Ray Mode. On top of that, types displayed in hints are navigable – while pressing Control / Command down, you can hover the cursor over them and click to go to the type’s declaration.īelow, we will go through the types of additional information that X-Ray can display. In both cases, instead of memorizing the shortcuts for the respective actions, you can press Control / Command. The X-Ray mode is also an alternative to two other actions: Show Implicit Hints and Type Info. With X-Ray, you can keep inlay hints and all the other additional information disabled or only partially enabled to the point where you feel comfortable, and then press down the Control / Command button two times and hold it – all the other hints will appear, and will be displayed only for the length of time you keep Control / Command down. The constant switching between too little and too much information displayed on the screen and the fact that disabling and re-enabling the hints snaps the developer out of the coding flow is a common problem. So you need to go to the settings and re-enable it. But it may happen after you do it that your work takes you to a place you don’t know so well, and now additional information displayed directly in the editor could be helpful again. So you decide to turn it off, and rightfully so. If you’re an experienced developer working on the code you already know, you may find little need for all that additional information displayed on the screen. Readability is a subjective issue, and instead of appreciating the help, you may feel that the editor is now too crowded and cluttered with unnecessary text. In such cases, inlay hints can improve readability and greatly help the developer.īut such functionality comes at a price. All that info doesn’t have to be typed explicitly in the Scala code – which is good because the code can be more concise, but on the other hand, if you read it for the first time, you might have trouble understanding what’s going on. You can see the line numbers, inferred result types, parameter names, indentation guidelines, and method separators. IntelliJ IDEA allows for displaying useful information directly in the editor, next to the code, in the form of inlay hints, that is, text that is slightly different from the actual code, but similar enough to be effortlessly read together with it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |