From C# to Java: Part 1
A couple weeks ago I started another one of my pet coding projects. My regular readers know that use C# for basically everything. However, for this project I decided to use Java and Eclipse.
I haven't written any Java code in several years. The JDK version number back then was 1.1.7. My coding environments were Symantec Café, Supercede, and emacs. Refactoring was little more than the topic of Bill Opdyke's dissertation (PostScript file). Eclipse was years away.
I figure it's time to refresh my perspective.
My younger daughter sleepwalks. Every so often she gets up in the middle of the night and starts wandering around. I'll find her downstairs in the family room babbling about zoo animals. I take her back up to bed. In the morning she doesn't remember a thing. Why does she do this? I don't know, but I assume anybody would have trouble with their REM sleep after watching two hours of The Suite Life of Zach and Cody.
Or maybe it's hereditary. Apparently last week I got up in the middle of the night, drove to O'Hare, flew to San Jose, took a cab to the Sun headquarters, spit on their front lawn, came home and got back in bed. I don't remember any of it.
What I do know is that the first thing I noticed about Java this time was that the curly braces are all on "the previous line", and my mental health started to deteriorate very quickly after that.
Everything got better when I opened the Eclipse preferences dialog and did this:
Oh, and this too:
These config changes made an amazing difference for me. Apparently the default style in the Java world is to put the curly brace on the same line as whatever precedes it. There's just no way I can get used to that. I'm not saying my style is objectively better. I'm just saying that I can't cope.
Luckily, the customization features of Eclipse are fantastic. After making the changes above, I simply press "Ctrl-Shift-F" and all my Java code looks a lot better to me.
I wish it worked outside the IDE. I've got Head First Java and Java in a Nutshell. Both are excellent books, but I keep finding my left hand doing the "Ctrl-Shift-F" motion hoping the page will reformat itself.
This morning on the way to work I saw somebody trying to make a turn from the wrong lane. My left hand did "Ctrl-Shift-F".
The excellent customization features of Eclipse came to the rescue again for the issue of key bindings. Between Visual Studio and Eclipse, everything is different.
For example, the three debugger commands I use most are Debug, Step Over, and Step Into.
- For Visual Studio, the default keys are F5, F10 and F11.
- For Eclipse, the default keys are F11, F6, and F5.
Truth be told, I had to look up the Visual Studio key bindings so I could type them above. I don't consciously know what they are. I just have them buried somewhere in my unconscious mind. They're automatic. And when I first tried debugging in Eclipse, things didn't work out so well.
In fact, all the key bindings in Visual Studio and Eclipse are so different that I've been wondering if they're not intentionally constructed that way for malevolent reasons. However, until I find a key that means "Go to Declaration" in one environment and "Reformat my Hard Disk" in the other, I'm going to set my suspicions aside and just assume that I'm being a little too paranoid.
Still, I wonder what "Ctrl-Shift-F" does in Visual Studio?
I normally don't like to do much customization of my work environment. I am, after all, a Windows user. All my custom settings get lost every time I repave. It's easier to just learn how to use things in their default mode.
But if I'm going to use both Visual Studio and Eclipse, I desperately need one of them to behave a bit more like the other.