📜 ⬆️ ⬇️

IDEA configuration for pure coders

I love two things: Intellij IDEA and Clean Code .
IDEA is created for clean code. Many default settings already stimulate you to write as it should.


But she is still not perfect.
When I install a new copy of IDEA, I run through the settings and set my favorite checkboxes.
I want to share them with you in the hope that someday they will become the standard.


')

Clean code is


To begin, let me remind you what pure code is in my understanding. The clean code is (including)


Let's take a look at what needs to be configured in IDEA so that it contributes to writing clean code.

My favorite checkboxes


Standard Headers


First of all, I always delete the largest bullshell in Intellij IDEA - the standard file header:


All information about authors and dates should be stored in a specially designated place - version control system. I do not want to litter with this code!

Similarly, I delete the standard headers for some languages:


Non-exclusive exceptions


About the same menu, I delete the annoying “throws Exception” in the JUnit templates:





They are not needed in most cases and only pollute the code.

The less code that does not carry useful logic, the better!

And where they are needed, IDEA will add them on time.

The purity of the tests must be monitored more closely than the purity of the code!


Automatic import


Next, I put a tick "auto import". When I write a new class name in the code, let IDEA import it instantly. Why should I worry about what a computer can do for me? Better I will not be distracted from really important thoughts.



This is a convenient feature, try it!

Working with tabs


Perhaps this is a matter of taste and depends on the project, but for me the restriction of 5 tabs is simply unacceptable. 20 at least! And when I close the C tab, I intuitively expect me to be in the penultimate place B (from where I went to C). And when I close B, it seems logical for me to return to A. Therefore, I tick the “Activate most recently used tab” box. The options "go left" and "go right" - just nonsense.
Dear Santa Claus, please remove them altogether from the IDEA settings, and I promise to behave well!




Show usages


Next, I will assign the Ctrl + F7 key combination to the action “Show usages”. This is a very convenient action, I use it, probably more often than anyone else! By default, he has some other key combination, not so convenient. And Ctrl + F7 by default does something else, not so useful.



And the action “Show Usages” shows all the places where this variable / method is used, right there, in a small pop-up window. It is damn convenient, no need to switch attention and move the view to another place! You can conveniently run up and down with arrows and close it with a simple ESC. Navigation at your fingertips!

Here’s what Show Usages looks like in action:


Camel Humps


An important option that not everyone knows about is CamelHumps. This option tells how IDEA should behave with words like AbstractStudentFactory, where there are several capital letters. I personally prefer to


That is, if the cursor is at the beginning of the word AbstractStudentFactory, and I press Ctrl + to the right, I want the cursor to jump to the beginning of the subword "Student", and not immediately to the end. In IDEA, the default is exactly the opposite.

The first item is regulated in Settings -> Editor (the very first tick):


And the second one there, in the “Smart keys” submenu:


Autosave files


Many people know (or guess) that IDEA automatically saves files when you switch to another program. Or when you run tests. It's great. No need to constantly press Ctrl + S.

You will not believe: I still can not get rid of the habit of constantly pressing Ctrl + S, although I moved from Eclipse to IDEA three years ago! Here is a bad habit.


But it would still be useful if IDEA would save files and just like that when I go for tea. Therefore, I tick "Save files automatically":


And thanks to this, I can safely put one more tick so that IDEA does not ask me "Do you want to exit IDEA"?


I do not need to ask again about this. I’m not afraid to close IDEA at any time, because I can always open it again, and there will be all my files safe and sound.

Inspections


Automatic code checks are a must for IDE in our time. In IDEA there are a lot of them, not very useful, I will not consider everything here. But I’m sure to put one in one, and strictly with the “Error” priority: this is “Missing @ Override annotation”.


Strictly speaking, this is not related to pure code. I just once spent several evenings searching for malicious non-repeatable bugs, which happened because someone accidentally wrote a method with the same name in the subclass as in the superclass (namely, the setUp method in the test). Since then, I have jealously put a check on the missing @ Override annotation.

Frequent commits


One of the good practices for proper programming is frequent small commits. Each commit should be atomic and make one change, not just a bunch of different ones.

When I follow these rules and commit 3 files out of 8 (the other 5 I’m going to immediately send by the next commit), IDEA offers to transfer the remaining 5 files to another “changeset”. Maybe it once seemed like a good idea, but in most cases I’m still going to commit the other 5 files soon. Therefore, disable this checkbox:


Further, when I made several small commits and I want to launch this business (git push), I face the problem that in IDEA there is no keyboard shortcut for Push, and it’s really awkward to search for this command in the menu. Make your shortcut Ctrl + Shift + K:


It is convenient to remember: Ctrl + K - commit, Ctrl + Shift + K - push.
Dear Santa, add Ctrl + Shift + K to IDEA by default?


Learn, learn and once again learn shortcuts!


IDEA is good because all the necessary plugins in it already have out of the box. For most daily needs, there is no need to search for and install something extra.

But one plugin I put necessarily. This Key Promoter plugin is an annoying prompter forcing me to learn shortcuts. Every time when I choose an action with a mouse, he immediately says to me: “But you could have done this with such a combination of keys!” He is so annoying that you willy-nilly start using these shortcuts, just not to see him once more


Feedback


And finally, the last tick. I want IDEA to analyze my work with it and send the collected information to JetBrains daily. This is my contribution to the development of the excellent product Intellij IDEA.



Dear guys from JetBrains, if this helps you to make IDEA even better - follow me, analyze me, take everything you need!

Clean code to you in the coming!

Source: https://habr.com/ru/post/206714/


All Articles