Eclipse 5 years later – common formatter quest

It was 5 years ago when I compared IntelliJ IDEA and Eclipse IDE in a series of blog posts (links to all installments at the bottom of that post). I needed to migrate from IDEA to Eclipse, tried it for couple of months and then found out that I actually can go on with IDEA. More than that, couple of years later many other developers used IDEA – some in its free Community edition, others invested into the Ultimate (comparison here).

Today I have different needs – I just want to “develop” formatter for our project that would conform to what we already use in IDEA. I don’t know about any automatic solution. So I’ll install Eclipse, tune its formatter until reformat of the sources produces no differences in my local version of the project and then I’ll just add that formatter into the project for convenience of our Eclipse developers.

Importing Maven project in Eclipse

I went to their download page, downloaded, started the executable and followed the wizard. There were no surprises here, Eclipse Mars.2 started. With File/Import… I imported our Maven project – sure that wizard is overwhelming with all the options, but I handled. Eclipse went on with installing some Maven plugin support. This is unknown for IDEA users – but it’s more a problem of Maven model that doesn’t offer everything for IDE integration, especially when it comes to plugins. It also means that plugins without additional helper for Eclipse are still not properly supported anyway. In any case, it means that Eclipse will invade your POM with some org.eclipse.m2e plugins. Is it bad? Maybe not, Gradle builds also tend to support IDEs explicitly.

Eclipse definitely needed to restart after this step (but you can say no).

SVN support

We use Subversion to manage our sources. I remembered that this was not built-in – and it still is not. Eclipse still has this universal platform feeling, I’m surprised it knows Java and Maven out of the box.

But let’s say Subversion is not that essential. I wasn’t sure how to add this – so I googled. Subversive is the plugin you may try. How do I install it? Help/Install New Software… does the trick. I don’t know why it does not offer some reasonable default in Work with input – this chooses the software repository which is not clear to me at all from that “work with”. I chose an URL ending with releases/mars, typed “subv…” in the next filter field and – waited without any spinner or other notification.

Eventually it indeed found some Subversive plugin…s – many of them actually. I chose Subversive SVN Team Provider, which was the right thing to do. Confirm, OK, license, you know the drill… restart.

But this still does not give you any SVN options, I don’t remember how IDEA detects SVN on the project and just offers it, but I definitely don’t remember any of torturing like this. Let’s try Subversive documentation – I have no problem reading. Or watching Getting started video linked therein. 🙂

And here we go – perspectives! I wonder how other IDEs can do it without reshuffling your whole screen. Whatever, Eclipse == perspectives, let’s live with it. But why should I add repository when the URL to it is already somewhere in the .svn directory in the root of the project? Switching to SVN Repository Exploring perspective, Eclipse asked for SVN connector. Oh, so much flexibility. Let’s use SVN Kit 1.8.11, ok, ok, license, ok. Restart again? No, not this time, let’s wait until it installs more and do it at once. This was wrong decision this time.

I followed the video to add the SVN repository, but it failed not having the connector. Were I not writing this as I go, I’d probably remember I have installed one. 🙂 But I wasn’t sure, maybe I cancelled it, so let’s try SVN Kit, sounds good. It failed with “See error log for details.” Ok, I give up, let’s try Native JavaHL 1.8.14 (also by Polarion). This one works. Restart needed. Oh, … this time I rather really restarted as my mistake dawned on me.

I checked the list of installed software, but SVN plugins don’t seem to be there – this is rather confusing. But if you go to Windows/Preferences, in the tree choose Team/SVN, then tab SVN Connector – there you can find the connectors you can use. Sure I had both of them there. My fault, happy ending.

So I added SVN repository, but as the Getting started video went on, I knew I’m in trouble. It doesn’t say how to associate existing SVN project on my disk with a repo. I found the answer (stackoverflow of course). Where should I right click so that Team menu shows enabled Share project…? In Package explorer of course. I added one project, hooray! Now it shows SVN information next to it. But I noticed there is Share projects…, I don’t want to do it one by one, right? Especially when Eclipse does not show the projects in the natural directory structure (this sucks). I selected it all my projects but Team menu didn’t offer any Share at all now!

Ok, this would throw me out of balance at 20, but now I know that what can go wrong goes wrong. That only project associated with SVN already – I had to deselect to let Eclipse understand what I want. Strictly speaking there is some logic in eliminating that menu item, but as a user I think otherwise. So now we are SVN ready after all!

I updated the project (not using other perspective), no information whether it did something or not – IDEA shows you updated files without getting into your way. Should have used synchronize, I know…

Oh, and it’s lunch time, perfect – I really need a break.

Quick Diff

This one is for free with IDEA, with Eclipse we have to turn it on. It’s that thing showing you changes in a sidebar (or gutter).

Windows/Preferences, filter for “quick” and there you see it under General/Editors/Text Editors. Well it says enabled, but you want to check Show differences in overview ruler too. In my case I want to change colours to IDEA-ish yellow/green/red. (Who came with these Sun/enterprise violetish colours for everything in Eclipse?) What to use as reference source? Well, with IDEA there is no sense for “version on disk” option. I chose SVN Working Copy Base in hope it does what I think it does (shows my actual outgoing changes that are to be committed).

Outgoing changes contain unmanaged files!

Ah yeah, I recall something like this. This is the most stupid aspect of SVN integration – it does not respect how SVN work. After seeing my outgoing changes in Team Synchronizing perspective (probably my least favourite and most confusing one for me) I was really afraid to click on Team/Commit… But as the three dots indicate, there is one more dialog before any damage is done – and only managed files are checked by default. So commit looks good, but disrespect of outgoing changes to the SVN underlying principles is terrible. Eclipse users will tell you to add files to ignore, but that is just workaround – you can then see in the repository all the files people needed to ignore for the sake of stupid team synchronization. Just don’t auto-add unmanaged files, show some respect!

Eclipse Code Style options

With quick diff ready I can finally start tuning my formatter. There are some good news and some bad news. Well, these are no news actually, nothing has changed since 2011. Code Style in IDEA is something you can set up for many languages in IDEA. It also includes imports. In Eclipse when you filter for “format” in Preferences you see Formatter under Java/Code Style and more options for XML/XML Files/Editor. These are completely separated parts and you cannot save them as one bunch. For Imports you have Java/Code Style/Organize Imports.

In my case it doesn’t make sense to use project specific settings. What I change now will become workspace specific, which is OK with me – but only because I don’t want to use Eclipse for any other projects with different settings (that would probably either kill me or I’d have to put them into separate workspaces).

And then we have Java/Code Style/Clean Up configuration (this is what Source/) and Java/Editor/Save Actions to configure and put into project(s) as well. Plenty of stuff you need to take care of separately.

Line wrapping and joining

One of the most important thing we do with our code in terms of readability is line wrapping – and one thing I expect from any formatter is an option that respects my line breaks. Eclipse offers “Never join lines” on Line Wrapping and Comment tab. It seems you have to combine them with “Wrap where necessary” option for most options on Line Wrapping tab, but it still does not allow you to split line arbitrarily – it joins the lines back on reformat, to be precise.

Sometimes I want to say “wrap it HERE” and keep it that way. In IDEA I can wrap before = in assignment or after – and it respects it. I don’t know about any specific line-break/wrapping option for this specific case. Eclipse respects the wrap after, but not the one before – it re-joins the lines in the latter case. Sure I don’t mind, I prefer the break after = as well. But obviously, Eclipse will not respect my line breaks that much as IDEA.

Just to be absolutely clear, I don’t mind when a standalone { is joined to the previous line when rules say so. There are good cases when control structures should be reformatted even when wrapped – but these are cases revolving mostly around parentheses, braces or brackets.

When I investigated around “Never join lines” behaviour I also noticed that people complain about Eclipse Mars formatter when compared to Luna one. Do they rewrite them all the time or do they just make them better? Do they have good tests for them? I don’t know. Sure, formatters are beasts and we all want different things from them.

Exporting Eclipse settings

Let’s say you select top right corner link Configure Project Specific Settings… in particular settings (e.g. Organize Imports). This opens dialog Project Specific Configuration – but do I know what is the scope of it when I select my top-level project? Actually – I don’t even see my top level project (parent POM in our case), only subset of my open projects based on I don’t know what criteria. That is ridiculous.

I ended up exporting settings using Export All… button – but you have to do it separately for whatever section you want. In our case it’s Clean Up, Formatter, Organize Imports and Save Actions. I simply don’t know how to do it better. I’ll add these XML exported configs into SVN, but everybody has to import them manually.

IDEA with its project (where project is really a project in common sense) and modules (which may be Maven “project”, but in fact just a part of the main project) makes much more sense. Also, in IDEA when you copy the code style into the project you feel sure we’re talking about all of the code style. If I add it to our SVN everybody can use it.

You can also export Code Style as XML – but a single one. Or you can export all of IDE settings and choose (to a degree) what portions you want to import. While this is also manual solution you need to do it once with a single exported config.

(This situation is still not that bad as with keybinds where after all these years you still can’t create your own new Scheme in a normal fashion inside the Eclipse IDE.)

Conclusion

Maybe the way of Go language, where formatting is part of the standard toolchain, is the best way – although if it means joining lines anywhere I definitely wouldn’t like it either.

I can bash IDEA formatter a bit too. For me it’s perfectly logical to prefer annotations for fields and methods on separate line, but NOT wrapping them when they are on the same line. Just keep the damn lines a bit different when I want it this way! Something like soft format with prefered way how to do the new code. This is currently not possible all the way. I can set IDEA formatter in such a way that it keeps annotations on separate lines and respects them at the same line as well – but all the new code has annotations by default on the same line.

This concept combining “how I prefer it” with “what I want to keep preserved even if it’s not the way I’d do it” is generally not the way formatters work now. I believe it would be a great way how they should work. This can partially be solved by formatting only changed lines, but that has its own drawbacks – especially when the indentation is not unified yet.

Why to synchronize with SVN in Eclipse?

Today we had an interesting experience with SVN. I always thought SVN Update and Commit is safe way how to do stuff, that you have to either hit conflict or everything is merged without any losses. After so many years with SVN I was proved wrong. We create incremental diff files for our SQL model – and today both me and my colleague created the file with the same name. He committed first. I updated. I didn’t check that file (it was just one of many). I committed. And he complained I had overwritten his changes.

How could that happen? Why team synchronization in Eclipse helps? Why update didn’t complain in the first place?! Is SVN to blame? Why it never happened to me in Idea? Actually could it? Have I ever committed the same files created the same day along with my team-mate before? If not, can it happen in Idea too? (It doesn’t have the synchronization as you know it from Eclipse, remember.)

First test with Eclipse – we did it again. Synchronization warns you about conflicting incoming changes. But you can update without any punishment from SVN itself. You have to check the file. When you create a file in Eclipse it is not added locally to the repository (actually, many of Eclipse users don’t know SVN basics “thanks” to this). After the update it becomes locally added and you can clearly see the changes in quick diff – or in outgoing changes – IF you diff them that is. Why would you care when there is no warning, right? Normally it’s not expected two of you create the same file in the same time. The whole process looks like update without any problem followed by your modifications (like they were done afterwards).

This means you should avoid creating the same files (we actually don’t need daily SQL changes tracking – in the end we have to aggregate a lot of files when we’re about to release the next version) or be very careful – or use Synchronize feature before you update. Or check newly added files for differences (who would think about that!).

I check the behavior with Tortoise, just to be sure it’s SVN here cheating me and not Eclipse. I checked out the same project twice and added files to both versions. I didn’t add it locally to the repository in checkout A. Then I added it in the local version B, committed and updated local copy A. File showed differences against HEAD, but no conflict, no warning – except for info that the file was added (and came from the repository).

If you add the file locally to both copies, then conflict is detected and you have to resolve it. When you know your file will be committed sooner or later, that it indeed is part of the project, the best way is to add it locally as soon as possible. You can do this in Eclipse too with Team, Add to version control – but I didn’t find any preferences that would do it automatically.

You can safely rely on update and checkout with IntelliJ IDEA, because Idea typically adds the file locally right after the creation – unless you go against its suggestions, which is not rational (R is not capital :-)). Actually why should you? If you want to have the file in the SVN, there is no reason not to add it. Not to mention you can see nicely whether the file is “under control” or not.

Eclipse tries to handle it differently – I actually don’t like this way (with or without today’s incident, which I consider non-essential, really). I want to know which file is going to SVN and which one is not. Actually, not only know – I want to be the one in control. Of course, you are in control with Eclipse too – but much later. In Synchronization perspective you can remove the file from view. Again – none of my colleagues knows how to remove particular file from this view forever without using svn:ignore feature – which is (I hope you agree) stupid. You’re using SVN ignore (that is SVN’s mechanism) because Eclipse doesn’t make any difference between files locally added and files out of control.

I nearly wanted to finish – but now I realized that I haven’t specified the plugin we use for SVN in Eclipse! Subclipse was used – and if this problem is approached differently with the other plugin (can’t recall the name) let me know in comments and I’ll probably switch. Idea has SVN support fully built-in and you can have only single problem with that (from what I experienced). When we had some older Idea and I “upgraded” local repository version (using newer SVN client for instance) my Idea couldn’t commit or update anymore. But currently with Idea’s free community edition I don’t expect this problem to occur again. 🙂

Happy synchronizing, updating and committing with as few conflicts as possible. And even less wannabe-no-conflicts. 😉

Don’t miss other posts on this topic:
Eclipse vs IntelliJ IDEA
From IntelliJ IDEA to Eclipse (2)
From IntelliJ IDEA to Eclipse (3)
From IntelliJ IDEA to Eclipse (4)
From IntelliJ IDEA to Eclipse (5)

Eclipse vs IntelliJ IDEA

It’s official. This is just a rant. It always is, because even the most serious comparisons of these tools are always clear win for the one used originally and total dismiss of the newly adopted one. I’m Idea user – for almost 9 years or so. I remember a few let downs with Idea – the biggest one for me is clearly introduction of Modules and lack of some good Project view as a result. And also the need to reorganize your project because to get support for web you had to move sources out of the standalone java part of the application (for instance). And application.xml must go to another (module) directory too. And if you add module “All” with the real project root, you can’t see anything in module subdirectories. This was more or less fixed somehow after Idea 4, but still… However – most IDEs somehow forces you to do something with your project anyway. And if you start follow patterns like Maven (not a bad idea either) than you should be safe.

Another issue I have with Idea (and I reported it – but it’s probably not good idea for creators) is a new search bar (since 7? 8? not sure now). Thing is, Ctrl+F is ok, but Enter should work differently. When you write your search string, Enter works like F3 and arrow down – but focus stays in the bar. Not only too many keys do the same thing – but you’re also not in the code after Enter. You have to Enter and Escape to get there. Hell, you can even Ctrl+F, write the search string and Escape – that’s does what I want (and expect from Enter). However, highlighting is gone. So what you really need to do is Ctrl+F, write and click to the code – you have to touch the mouse! 🙂 Not to mention that if you press Ctrl+F, write, Enter, Enter… you go through your searches and then you need to do another search, Ctrl+F pulls down previous searches instead of giving you the fastest way how to start another search. Firefox selects all and you can search something else – great! Idea’s solution is just so silly that probably previous dialog using way worked better for me. But maybe I’m the only one here.

But that’s it – otherwise I just love Idea. When I’m in code I can just feel it.

And then Eclipse. I’ve read someone complaining about how contextual (hence smart) Eclipse is and how difficult Idea shortcuts are. I can just say, that I’m going crazy when Eclipse offers different search depending on the file I’m in (is there EASY way how to full-text search the whole project – Ctrl+Shift+F in Idea?). Idea’s three different completions might be a bit problematic at the start, but much faster when you know what they do. And then – comparing Ctrl+N with Ctrl+Shift+T… well, I think it’s clear what is easier. I can always get faster to editor in Idea (and that’s actually what I do a lot) while in Eclipse it’s a real finger exercise.

Or Mark Occurrences – they are not sticky! I can’t choose and highlight this… and that… and go somewhere else. It just blinks like disco music all over the screen – or you can turn it off. There are so many features that were copied in much better fashion from Idea do Eclipse, but this one is just ridiculous. Sure I have to click Ctrl+Shift+F7 in Idea – but then – I can highlight any text, not just a type. And more of them. And obviously – I don’t need this Christmas lights turned on all the time (not to mention that the default colour is hardly highlighting – I was rather confused whether I selected something or what).

I also found that in many cases where Idea happily completes, Eclipse wants me to fix some braces first (took me some time to realize that) before he is capable to do so. And Idea goes to the next line after (un)commenting one, Eclipse not (by default at least).

Or SVN support – how can anyone compare SVN support in Idea and Eclipse? In Idea it just works out of the box (even in community edition). And Quick diff (that’s how it’s called in Eclipse, never needed to know the name in Idea) – it’s just far superior (and working right away) in Idea. Also colours are much more distinct (by default!), items in the outline on the right are easier to recognize, etc. In Eclipse all these things are rather greyish, often coloured with pattern instead of solid colour and always outlined instead of being nice thin (yet thick enough) line like in Idea. Deleted stuff in Idea’s diff shows as a triangle, not line nearly impossible to hit with a cursor.

And then commit! Lately I had to do my first “synchronization” and I was shocked how inferior the commit is in terms of my control over the process. Files that are not yet added can’t be told from those that are added to SVN – you have to right click them and check if Add option is available. Not to mention I don’t want to add them by default at all! It was also not that easy to find option to ignore white-spaces in diff view, not to mention I like three options offered by Idea more.

Rename refactoring in Idea selects the whole identifier and I can just write a new one – in Eclipse you have this feature if you switch to rename dialog, not in editor, you have to remember to select the stuff. On the other hand, sometimes it indeed is useful to have cursor on a specific place of the identifier. In Idea I actually miss easy way how to deselect the word without moving the caret – so let’s call it a draw here. Ad selecting – with Idea I can select a word in a string or part of dot separated property name – and then go on to the whole string, line, and on. In Eclipse I can’t select word from its middle in an easy way.

Eclipse is just like this. I don’t see things there, I need more perspectives to use it (never needed that in Idea), Console contains too many… well actually consoles – and there is yet another mechanism to switch between them (funny drop-down button instead of more tabs for instance). I just like Changes window and Run window separate! And that’s probably the point. We all love different things. And while both Idea and Eclipse are customizable to some extent, they can’t satisfy all developers. Even when both do the job (unless you want to sticky highlight thingies ;-)).

What I can’t deny to Eclipse – their plugin ecosystem is just absolutely awesome. And all these things like EMF or Xtext… many companies use their own plugins built on Eclipse. For a reason. Whether it’s because Idea wasn’t for free (as is Community Edition now) or not – it’s hard to say. But that probably helped a lot.

I’m now stuck with Eclipse and will probably learn to overcome some of the problems. But I can smell it right now, it will hardly grow on me as Idea did.

Don’t miss other posts on this topic:
From IntelliJ IDEA to Eclipse (2)
Why to synchronize with SVN in Eclipse?
From IntelliJ IDEA to Eclipse (3)
From IntelliJ IDEA to Eclipse (4)
From IntelliJ IDEA to Eclipse (5)

Personal Log (2): Leaving Linux, buying guitars

Not that I write continuation of the personal log every time Federer wins a Slam title, but after dramatic final of the Wimbledon it really happened. (Just another instant classic after last year final? :-)) Fifteen and counting so it seems.

I wanted to confess that I stopped using Linux on my computers. I still have out of date Ubuntu on my desktop, but I can’t remember last time I used it. I went for Windows XP after all those Linux years, because I play more games now than ever. Video and music processing is also better supported on Windows – more software to choose from, VST support, etc. Seriously, why to use Wine just to pretend I’m not using Windows, right? Of course – anytime I have to work in command line in Windows, it’s real pain in the ass. When I changed my old computer at work for Lenovo T500 (with some troubles though) I decided to go for Windows XP only and in order to have some Linux I searched for some virtual machine solution. Friend of mine recommended VirtualBox and I was satisfied! It worked nicely, there was some trick with virtual folder name (try different name then the directory name if you have problem, or something like that ;-)), but after just a few hours I had nice Ubuntu machine for development tasks that required Unix tools, strong command line and all the rest you don’t have in Windows for free. Of course, performance was… virtual. 🙂 But if you want to try some virtual machine software, I strongly recommend this one. Documentation is OK, not too much to drown in and I found everything important there.

What I can’t understand is SVN Tortoise client. It’s absolutely great tool, looks nice, integrates to contextual menus for files, etc. So far so good. But when you want to check modified files to find out what is not added to repository (and should be) or when you want to commit, the view shows you either only managed files or all files recursively – there is no way that non-managed directory is just reported without the complete sub-tree. Compare this to default CLI functionality of the svn st command. Man I miss that so much! But not that much that I plan to setup my system PATH and run the all-time-loser “cmd” to use it.

There is one more thing I dislike on Windows. I alt-tab a lot, I’m of those erratic guys. 🙂 And sometimes I alt-shift-tab back too. Sometimes, when I depress these keys in a wrong order, Windows is strongly convinced I wanted to switch the keyboard layout (alt-shift). Trouble is, there is limited amount of options (keyboard shortcuts) to do so, this one is clearly the best. I should probably download some tool just do switch between keyboard layouts. Slovak keyboard is not good for coding really. Enough Windows rant for now.

I bought a new guitar! I have infamous Behringer’s V-Tone pack – because it was cheap and I was young(er) and uninformed when I bought it. The price was good, amplifier is good, guitar is… well, it’s some kind of Strat and it is possible to play on it. Now I know there are better options in the same price tag (not too many though), but what’s done is done. To have at least semi-decent guitar I bought French LAG AM100:


Black beauty!

It looks cool, it’s Superstrat, it is something different than the Strat, so I might actually also learn more about guitars per se. It was priced 356€ but in a massive sale action I acquired it for 156€, why not? I actually didn’t know what to buy as I also wanted some Ovation, but I decided to buy the best value from whatever I wanted. Funny sale strategy when you learn prices only on site. 🙂 Even before I bought it I had started to learn some scales and other stuff to enhance my play. Chords, rhythm, no problem, but I wanted to go on after a long stagnation – and with better guitar it’s even more fun!

Is the guitar good? More people claim it’s a good value even for the original price, so I guess I wasn’t wrong with my buy. Quality is OK, but I honestly can’t judge guitar when I can’t compare it. Maybe later I’ll write more on the guitar, trouble with LAG is that they have no official English site (as a manufacturer, not as reseller), forums are dominated by French language, no real documentation for newbies like me. So I have to rely on other forums, other people and learn the rest by myself. Of course, when I just play on it, there is no problem, but you know… when you have a new toy, you want to play with it even more. Tune it (later probably, and I don’t mean just strings now), understand it. However, enough for this time – I need to practice!