Visual Studio Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Visual Studio Hacks [Electronic resources] - نسخه متنی

Andrew Lockhart

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 94. Spellcheck Your Code and Comments

While there are definitely exceptions to the
rule, virtually all computer programs are rife with spelling errors.
Ensure that the comments and string literals in your code are free
from spelling errors.

Programmers, it seems, are not the
world's best spellers, in large part because
compilers are kind enough to overlook any spelling snafus. While it
may be hard to get worked up over source code dotted with spelling
mistakes, it is important to realize that these grammatical errors
can incur a real cost. When working in a team, a developer can be
slowed down by misspelled comments and variable names in
another's code. A spelling mistake in a string
literalsuch as a misspelled menu option or error
messagereflects poorly on your company and software.

Spelling has become a lost art over the past couple of decades, as
word processors have evolved from little to no spellchecking support
to today's programs that will correct your spelling
automatically as you type. While spellcheckers have become ubiquitous
in word processors, email clients, and a bevy of other computer
programs, they are still sorely missing from IDEs. Fortunately, Dean
Giovanelli has created a free spellchecker add-in for Visual Studio
.NET 2003. Armed with this spellchecker, you can quickly check the
spelling of your source code, comments, and string literals, all from
within Visual Studio.


13.4.1. Download and Install the Spellchecker Add-in


At the
time of this writing, this add-in
works only for Visual Studio .NET 2003 and requires that Microsoft
Word 2000 or later be installed as well. Assuming your system meets
these two requirements, you can get started with spellchecking your
code in Visual Studio by downloading the free add-in from http://www.devx.com/vb2themax/CodeDownload/19810.
The download contains a setup file that will install the add-in.

Once the add-in has been installed, launch Visual Studio. By default,
this add-in is not loaded. To load it, go to the Tools menu and
select the Add-In Manager option. This will list the add-ins
currently installed on your system, which should include the Spell
Checker for VS.NET 2003 Version 1.0 Add-In. To enable this add-in,
check its checkbox (see Figure 13-9). You can also
opt to have it loaded on each startup by checking the Startup
checkbox.


Figure 13-9. Check the Spell Checker for VS.NET 2003 Version 1.0 checkbox

Once you have checked the add-in's checkbox, click
OK. You should, at this point, see a spellchecking icon in the
toolbar. Additionally, there should be a new option in the Tools menu
titled Spell Checker for VS.NET.


13.4.2. Configure the Spellchecker Options


Before you run the spellchecker for the first
time, take a moment to configure the options. To configure the
options, start the spellchecker add-in by clicking on the appropriate
toolbar icon or menu option. Doing so will display the Spell Checker
for VS.NET dialog, which contains an assortment of tabs. The first
tab, Code/Text, contains the results of the spellcheck. The remaining
tabs contain the assorted spellchecker options.
Let's examine these tabs.

13.4.2.1 Specify what types of content to search


The first options-related tab is named, aptly
enough, Options, and is shown in Figure 13-10.


Figure 13-10. Select the portions of code to spellcheck

From the Options tab, you can indicate what content your source code
should search:

Comments and Strings


Selecting this option will cause the add-in to spellcheck all
comments and string literals.


Double Quoted Strings


This option causes only string literals to be spellchecked.


Comments


With this choice, only comments will be spellchecked.


All


Checks all content, including comments, string
literals, variable names, methodsthe complete source code.



From this tab, you can also specify which characters should be
considered word separators. For example, the +
character is, by default, added in the word separator character
list. If you leave this as a word separator character, the code
salary+dividends would be considered two words:
salary and dividends. If,
however, you excluded the + from the word
separator character list, salary+dividends would
be interpreted as one word.

The Show Suggestions checkbox is pretty self-explanatory. If it is
checked, the spellchecker will provide suggestions for any misspelled
words. Split MixedCase Words is a neat option. If checked, it will
interpret mixed case words as individual wordsthat is, a
method named DeleteEmployee would be spellchecked
as two words: Delete and
Employee. The Never Clear options, if checked,
will not clear the Ignore All or Change All Word lists until the
add-in is unloaded. If they are left unchecked (the default), these
word lists will be cleared whenever the add-in is closed.

From the Options tab, you can also specify the location of the
dictionary files to use for spellchecking with the add-in. The
spellchecker uses its own dictionary file, separate from Microsoft
Word's, meaning that you add commonly used variable
and method names that you would not want to be considered correct
spellings when using Word. Additionally, you can optionally specify
up to two of your own custom dictionary files.

13.4.2.2 Indicate patterns that should be ignored or always considered misspelled


The Exceptions tab allows you to provide a list of
regular expressions to indicate that certain patterns should always
be ignored or should always be considered to be misspelled. From this
tab, you can enter a variable number of regular expressions, one line
at a time, in the text box. Prefix the regular expression pattern
with an O to indicate that words that match the
pattern should be ignored; use an X prefix to
indicate that words that match the pattern should be marked as
misspelled.

For example, imagine that you prefixed your class's
member variables with the character m. Clearly,
variables like mAge, mName, and
so on, will trip up the spellchecker. You can opt to have the
spellchecker ignore all words that begin with m,
followed by a capital alphabetic character by using the following
pattern in the Exceptions tab:

O^m[A-Z]

13.4.2.3 Use different spellchecking rules for different file types


Since different programming
languages utilize different syntax, such
as the character(s) that indicate comment regions, the spellchecker
add-in utilizes different parsing rules based on the extension of the
file being spellchecked. From the File Types tab shown in Figure 13-11, you can indicate how different file
extensions are parsed by the spellchecker.


Figure 13-11. Configure how to handle various file extensions

The add-in ships with built-in parsers for six different languages:

C#Visual BasicHTML/XMLC/C++Text filesJ#

These six parsers dictate how comments and string literals are
parsed. Recall that from the Options tab you can specify if just
comments or string literals should be spellchecked. These parsers,
then, pick out the comments and strings for a particular language.
(Unsurprisingly, the text file parser treats all
content as content that is to be spellchecked; that is, regardless of
what type of content you have opted to have spellchecked, all content
in a text file will be checked.)

In addition to providing six built-in parsers, the add-in also allows
you to define parsing rules for up to two custom languages. From the
My File Types tab, you can specify the parsing rules, as shown in
Figure 13-12. Then, from the File Types tab, you can
indicate which file extensions should be mapped to which custom
parsing
rules.


Figure 13-12. Set up custom parsing rules.


13.4.3. Check for Spelling Errors


Once you have configured the add-in options,
return to the Code/Text tab to begin spellchecking. As Figure 13-13 shows, from this tab you can opt to
spellcheck:

The currently selected text

The current file

The current line to the end of the file

The current project


Once you have specified what to spellcheck, click the Start button to
begin the spellchecking process. This will step through your code,
highlighting misspelled words, prompting you to ignore the word,
change it to a corrected spelling, or add it to the dictionary, as
shown in Figure 13-13.


Figure 13-13. Replace, ignore, or add misspelled words to the dictionary file

Incorrect spelling in production code makes your software look
unprofessional and unpolished; comments riddled with misspelled words
lead to confusion and frustration for developers examining
others' code. There's no reason why
you shouldn't take the time to spellcheck, at
minimum, your code's comments and string literals.
Armed with this free add-in, such spellchecking is impressively fast
and easy.

Scott Mitchell


/ 172