Friday, April 4, 2008

Catch all those spelling errors +eclipse

spelling errors. I think we all make them - I know I do anyway.
After typing these tips on a near daily basis I've begun to recognize
that no matter how good you think you are at spelling, stupid mistakes
show up, and a lot of times you get a bad spelling habit stuck in your
head and continually put too many c's in necessary or something. I
would be surprised if a spelling error didn't find its way in to this
very tip, as I'm usually too lazy to put a lot of effort into spell
checking these :).


Spelling errors in documentation can mean the difference between life and death. Really?! No... not really - but spelling
is
important. Bugs are opened in large frameworks when spelling and
grammatical errors are in the documentation. Really, it happens! In
addition, people immediately take you more seriously when you spend the
time to ensure that your spelling is accurate. Finally, it is
definitely possible that spelling errors can convey a different meaning
than intended. (Deprecate and Depreciate anyone?)

Thankfully, Eclipse has a little hidden gem that makes quick
work of spelling errors. The spelling support in Eclipse has actually
been around for a while now (if I'm not mistaken, it was enabled in
3.0), and recently (3.1 M4) it was enabled in the properties file
editor in addition to the already supported Java editor. So, how do you
enable it?

Well, the first step is to find the preference for it. That's a
relatively simple process as I already know, and I am going to tell you
;) - just go to
Window->Preferences->Editors[+]->Text Editors[+]->Spelling
and check
Enable Spelling
.




Oops, wait a minute... it has a section to provide a 'User defined
dictionary'. Is this mandatory? What format does it need to be in? Do
we have to type all the words by hand? This could take a while! For
spell checking to work, it is currently mandatory for you to provide a
dictionary. Thankfully it's not that hard to find a word-list Eclipse
can use. Eclipse supports a fairly standard one-word-per-line format
for the 'dictionary' file, so we just have to find one of those. The
best branching off point for that is probably Kevin's Word List on Sourceforge.net
. Seem too hard? Ok, fair enough. I've compiled my own word list
off of an amalgum of lists (I honestly can't remember which ones,
otherwise I would be sure to give credit where credit is due), and I
have uploaded it here
. Fair warning! This file is substantial in size - so substantial
that I couldn't attach it to this message in the conventional Javalobby
'Attach File' way (around 1.5 megabytes).

Ok, so now let's enable our spell-checking. I like to drop the
dictionary file in the folder with my Eclipse installation, and then
reference it in the preferences, as seen here:



Then all you have to do is use it. Spell checking shows up in
one of two ways - first as squiggly warnings in your documentation and
strings, and second as a preemptive auto-complete for content assist
(assuming you have enabled that option in the advanced section seen in
the screenshot above). Here is what the spelling error marker looks
like (and what happens when I press Ctrl+1 with my cursor adjacent to
the error):




Here is what it looks like using the auto-complete feature (Ctrl+Space):



Unfortunately, spelling support still needs a little work in
some areas; it is no panacea. So, what would I like to see in the
future? For one thing, there is no way yet to control what elements are
spell-checked, and which ones aren't. What I mean by that is whether
javadocs, regular comments, string literals, and/or type/method/field
names are spell-checked. Currently all documentation and string
literals are checked, but that's it. Frankly, my string literals need
checking less often than my types and fields and methods - and in my
string literals, it is more often the spell-checker would be wrong. In
addition, the algorithm used for finding words of a closest match
doesn't always seem the most appropriate - when using the word-list for
auto-complete, if I were to type 'spell' and then press Ctrl+Space, I
would like 'spelling' come up in the list before 'spew' - since that is
the main benefit of an auto-complete feature - completing the word!

No comments: