Slashdot Log In
Programmer's Language-Aware Spell Checker?
Posted by
kdawson
on Tue Sep 04, 2007 04:12 AM
from the hands-off-my-camelcase dept.
from the hands-off-my-camelcase dept.
Jerry Asher writes "Not all of my coworkers are careful about spelling errors. Sometimes this causes real embarrassment as spelling errors creep into software interfaces. Does anyone know of spell checkers for programming languages? I don't want a text spell checker, I want a programming-language-aware spell checker. A spell checker that I can pass all of my code through and will flag spelling errors in function names, variable names, and comments, but will ignore language keywords, language constructs and expressions, and various programming styles (camel code, or underscores, or...). I want a spell checker that knows that void *functionSigniture(char *myRoutine) contains one spelling error. Does anyone have such a thing for Java or C++? Are there any Eclipse plugins that do this?"
Related Stories
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.
Eclipse WTP 3.3 Europa seems to do this.. almost. (Score:5, Informative)
Man Dies Waiting for Eclipse to Launch (Score:5, Funny)
A software engineer in San Jose, CA was found dead at his desk yesterday, apparently having died while waiting for his Java editing program, Eclipse, to finish its boot process. Coworkers say the engineer came in that morning vowing to "get Eclipse working on his box or die trying." The last thing anyone heard him say aloud was the cryptic comment: "I see the splash screen is appropriately blue." Nobody knows what he meant. The man was then thought to have fallen asleep, but hours later it was discovered that the engineer had died suddenly of apparent natural causes. The forensics team's investigation that evening was reportedly interrupted unexpectedly when the dead man's Eclipse program suddenly finished launching. The team tried to interact with it to see if they could find clues about the man's death, but the program was unresponsive and the machine ultimately had to be rebooted. At this time, the police commissioner says there is no evidence of foul play, and they currently believe the man simply died of either boredom or frustration.
Parent
Re:Man Dies Waiting for Eclipse to Launch (Score:5, Informative)
Parent
Re:Man Dies Waiting for Eclipse to Launch (Score:4, Interesting)
Work in a windows environment in Virginia. Access the Eclipse workspace directory through a mounted drive pointing to your home directory on a UNIX box in Montana. On the UNIX machine, your home directory is actually mounted on a Windows box back in Virginia.
God help you if you have the "compile on save" option enabled. And don't even THINK of rebuilding the workspace.
And yes, I know this from experience.
Parent
Re:Eclipse WTP 3.3 Europa seems to do this.. almos (Score:3, Insightful)
Re: (Score:3, Informative)
The idea isn't anywhere near as nuts as you think it is, provided you make a habit of using meaningful variable/class names.
Re:Eclipse WTP 3.3 Europa seems to do this.. almos (Score:5, Funny)
Parent
ego != good_open_minded_programmer (Score:5, Insightful)
You clearly fail to see a programmer can also create their own function names, as well as use other peoples functions. So you prove you are a very inexperienced programmer, (and close minded), which adds weight to the idea you are either young or just arrogant. Also your very apparent need to show hostility, shows a degree of insecurity, where you are over compensating, by verbally hitting out at others, in an attempt to appear to be more knowledgeable than you really are.
The easiest way to become a better programmer, is to be more open minded. So far you have failed to demonstrate this.
As a side note, (back in the DOS days of programming), I found the the spell checker in Multiedit very useful (especially when having to work very late at night, after the coffee stopped working!
Parent
Re:ego != good_open_minded_programmer (Score:5, Funny)
We're the do-anything team that specialises in imaginging new ways for you to reach your audience.
The word "pwned" doesn't spell check correctly either, but it is applicable.
Parent
Re: (Score:3, Interesting)
"Misspelt" is a legitimate spelling in British English. It's in the OED, with examples from 1762 to 1990.
Since I have just corrected you, I assume I have made an error somewhere in this post, though I haven't managed to find it.
Re:What the fuck is the OP on? (Score:5, Funny)
Parent
Re: (Score:3, Informative)
Re:Eclipse WTP 3.3 Europa seems to do this.. almos (Score:5, Funny)
"You appear to be creating an infinite loop. Would you like me to increment your counter variable?"
"You appear to be writing a virus, would you like a list of the latest Windows Vista sploits?"
Parent
Re: (Score:3, Informative)
2. There are some practical ways to construct proofs that a loop ends (remember the CS lectures). Sure, it's not a perfect solution, but if you can't construct a proof that the loop ends, you'd better rethink the loop, and possibly rewrite it.
Re: (Score:3, Informative)
Its impossible for a computer program to be constructed which can do so for all cases (hence, the halting problem), but that doesn't mean that its impossible to detect some infinite loops, or to detect constructs which are particularly likely to be infinite loops, either of which could, in theory, be useful features in an IDE.
Spelling/grammar checkers for human language aren't flawless, either, but they still have uti
Re: (Score:3, Interesting)
The former can be done by a simple regexp, the latter... you can do a LALR parser, but why even bother? Just look for _any_ potential identifier; in most languages, that's [a-zA-Z_][a-zA-Z_0-9]+; and simply add the few keywords which are not English words to your dictionary. In fact, this would be nearly programming language agnostic.
When it come
Visual Assist (Score:3, Informative)
Next silly question, please.
Re:Visual Assist (Score:5, Funny)
Parent
Re:Visual Assist (Score:4, Funny)
Parent
Re: (Score:3, Informative)
Re: (Score:3, Informative)
Just FWIW, it checks typing in both comments and (perhaps more importantly) string literals. It's also "intelligent" enough to know (for example) that '%d' should not be treated as a problem in a string literal. It is true, however, that symbols that are misspelled don't get highlighted, provided the misspelling is consistent.
How about eyeball Mk 1? (Score:5, Funny)
Re:How about eyeball Mk 1? (Score:5, Insightful)
Parent
Re:How about eyeball Mk 1? (Score:5, Funny)
Parent
Re:How about eyeball Mk 1? (Score:5, Insightful)
Parent
Sounds like a good idea (Score:5, Interesting)
vim 7.0 anyone? (Score:3, Insightful)
It's a good question ... (Score:5, Interesting)
People here making fun of his request and saying that this should be set in stone in design documents, or be checked in peer code reviews are obviously not working in a run-of-the-mill software company where there's neither the inclination nor the time to do everything the formal way. Also, I have to see the first design document that correctly enumerates all the requirements for the software, let alone all the names for the variables to be used.
Re:It's a good question ... (Score:5, Informative)
As a non-native English speaker, working in a non-native english speaking team (mainly french speaking people) it is a real problem. The biggest problem happens when you search something and don't find it because you wrote it right and your coworker wrote it wrong. (Or the inverse, I don't claim to be perfect in English)
Sure, you might say, "Write your code in French", but that's not a solution. My mother tongue is Dutch, we have a German coworker, and you never know if the next guy will be Italian. There is also this team that has to maintain code written by Spanish people.... in Spanish.... and they don't know Spanish. Fun times, if you like to hear them curse....
In multilingual environments this problem increases drastically.
Parent
TextMate does some... (Score:3, Interesting)
You can right-click on any "word" (variable name, subroutine name, whatever, just generally a whitespace-delimited group of characters) and it will check the spelling and present alternatives in the context menu. It also recognizes things like perl's sigils so correcting '$teh' turns into '$the', not 'the'.
It _won't_ automatically check spelling except in strings (so e.g. if I have '$teh = "This is a tset.";', 'tset' will be underlined, '$teh' won't). It doesn't include comments in its automatic checking either, which is probably the most annoying part about it.
Overall I typically just don't bother with it, but someone _has_ thought along these lines, at least.
aspell? (Score:4, Insightful)
How about this (Score:5, Interesting)
Enough rant. How about this:
perl -ne "s/([a-z])([A-Z])/$1 $2/g; tr/A-Za-z/
That will give a list of unique words in your source code (use find and xargs to scan the whole source tree). Then you can run that list of words through an ordinary spellchecker such as ispell. Unfortunately when you find a mistake you have to go back and grep for it to find where it occurs. You would also need a personal dictionary for things that are not English words but nonetheless appear in code.
I would probably keep the private word list containing things like 'foreach' and 'const' with the program source code, and have a makefile target 'make spellcheck' that runs a command like the above and then prints out all words found that are not in
find . -type f -name '*.c' | xargs perl -ne "s/([a-z])([A-Z])/$1 $2/g; tr/A-Za-z/
sort -u private_word_list
diff -u allowed_words found_words | grep -E '^[+][^+]'
The private word list can be kept under version control and checked in whenever you add a new non-English word like 'Frobule' to your source code.
Adding filenames and line numbers to the output is left as an exercise for the reader. You might also want to change the perl command to ignore words with length < 5.
Re: (Score:3)
I suspect that they actually decided that TextLikeThis was easier to type, and sufficiently readable that the typing ease benefit was worth the switch. Of course that's because no one thought of making shift-<space> map to _.
FxCop (Score:5, Informative)
http://www.gotdotnet.com/Team/FxCop/ [gotdotnet.com]
Visual Assist (Score:3, Interesting)
I'm not associated with Whole Tomato, but if anyone from WT sees this, can I have a free subscription
Re: (Score:3, Interesting)
Comments like this make me wonder. Is it so hard to imagine a spelling checker for say the C language that finds words that were not written the way they were intended? Limiting yourself to correct English words for identifiers is stupid. Assuming that a spelling checker for a programming language would do
Annoying perhaps but (Score:5, Interesting)
HRESULT MFGetService(
IUnknown* punkObject,
REFGUID guidService,
REFIID riid,
LPVOID* ppvObject
);
You'll probably just end up spending all your day removing false positives.
Re: (Score:3, Insightful)
Ken Thompson and creat() (Score:5, Interesting)
"If I had to do it over again? Hmm... I guess I'd spell 'creat' with an 'e'."
Emacs - ispell-check-comments (Score:3, Informative)
Re:How about the Built-in OS X spell checker? (Score:5, Funny)
We're talking about programming, friend.
Parent
Re:May I suggest.... (Score:5, Insightful)
Responses like this entirely miss the point of the question. Same with the "just review your code" responses. It's not a matter of making the language more readable. It's a matter of making the code more usable. Certainly, correct spelling is pointless without other elements of good code practice. However, bad spelling can add a lot of frustration.
I joined a project which already had a few misspelled class names. I'm a fast typer and often I've typed out more of a filename than is spelled correctly before hitting tab to complete the name. Needless to say, I've been trained to hit tab earlier for a few choice files. But it's certainly been an irritation. Similarly, I've been confounded more than once when a function or variable couldn't be found by the compiler, only to realize that I'd spelled a word correctly rather than how the actual name was spelled.
We choose to use English words for our class, function, and variable names for a reason. That reason is mostly defeated by misspelling the English word. A dictionary is a great idea, even for coding languages that don't "read like English".
Parent
Re:May I suggest.... (Score:4, Insightful)
Parent
Re:May I suggest.... (Score:4, Insightful)
It strikes me that the problem is that most spell checkers try to check everything, and that a lot of code has things that really shouldn't be spell checked at all, mixed with things that should. I imagine that one way to start would be to only alert on those errors that are almost correct -- if it looks like garbage, ignore it, but if it's close, assume it should be right. Perhaps ignore prefixes / suffixes as well -- pSomething is fine, pSometihng isn't. Also, CamelCase ought to be easy enough to detect -- treat it as word boundaries, and spell check the individual words. Again, egregious misspellings probably aren't -- nextObjFoo is ok, even though Obj isn't a word -- it's so far from being a word that we assume the programmer meant it that way.
Similarly, there should probably be a set of words added that aren't "English" but are used often enough to be worth adding to the dictionary. Things like Obj, Int, and Ptr.
I think the reason such spell checkers don't exist already is fairly simple -- everyone just assumes they're impossible, and doesn't try. Couple that with the fact that a mediocre quality one would be so annoying as to be worse than useless, and you have a recipe for a program that won't get written. I don't think either of those would have to be the case if someone sufficiently clever decided to attack the problem, though.
Parent
Re: (Score:3, Informative)
Overall, the answers to the submitters question are absolutely horrible so far. If the tool he's searching for doesn't exist, it damn well should.
Re:simple (Score:5, Insightful)
Parent
Re: (Score:3, Insightful)
To the original question: is strncpy misspelled? What about foo? sqrt? exp? Impl? Programese has an interesting linguistic history and its lexicon contains much not found in English.
While misspelled variable and function names are annoying, a refactor tool and a compile make them relatively painless. Perhaps the best approach would be to take your API documentation, run a script to split CamelCase an
Re:Syntax Highlighting (Score:4, Insightful)
Parent
Re:the problem is really prevalent (Score:5, Funny)
Parent
Re: (Score:3, Funny)