Programmer's Language-Aware Spell Checker? 452
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?"
Re:How about eyeball Mk 1? (Score:5, Insightful)
Keep text in dedicated files (Score:2, Insightful)
vim 7.0 anyone? (Score:3, Insightful)
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".
Re:May I suggest.... (Score:4, Insightful)
Re:simple (Score:5, Insightful)
Re:Syntax Highlighting (Score:4, Insightful)
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.
Re:How about eyeball Mk 1? (Score:5, Insightful)
aspell? (Score:4, Insightful)
Re:How about eyeball Mk 1? (Score:1, Insightful)
2) If it is that big of a problem, he's probably writing too many LoC. Refactor, reuse, learn patterns. Learn a better language.
3) Maybe he should document his API. It's pretty hard to get a spelling mistake through when your whole team has the whole API automatically documented in HTML on your intranet.
Re:May I suggest.... (Score:2, Insightful)
Unfortunately when I tried to compile my customised version, there were hundreds of errors, the majority of which were where I had spelled words correctly. Mostly I fixed these by changing the spellings in my code, but there were a couple of places where I'd somehow ended up with compilable code that was using the wrong variable, resulting in run-time crashes.
The difficulty is, any spell checker would have to realise that TcpRcv, TcpRcvr, probably even TcpRecvr are valid abbreviations, but TcpReciever is a spelling mistake. I think rather than looking at whole words, it would probably have to look for problematic sequences of letters, such as 'cie' which should almost always be 'cei'.
Re:Eclipse WTP 3.3 Europa seems to do this.. almos (Score:3, Insightful)
Attempting to tell programs the correct grammar or spelling does not always go well. While most will thank you for your input on catching their mistakes, others take it like you step on their babies head.
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!
Re:Annoying perhaps but (Score:3, Insightful)
Re:How about eyeball Mk 1? (Score:2, Insightful)
Re:simple (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 and words_with_underscores, then feed that document to the spell checker. If it's not in your public API, it shouldn't matter how it's spelled.
Also, externalize your strings so that people with English writing training can write your field labels and error messages. Even programmers who spell check strings often misgrammarize them.
Lazy Bones (Score:1, Insightful)
So write one, lazy bones.
English (or $YOUR_LANGUAGE_HERE) (Score:3, Insightful)
At least in the real writing business there are editors trained and paid to catch these errors.
Being unable to spell correctly makes you look really stupid to most people.
Just FYI, if you have a decent programming environment, it should at least flag cases where you've mistyped an existing identifier. If there's an ImmediateFlag in your code, you'd get a warning if you typed ImediateFlag or ImmediateFalg or whatever. Not much help when the programmer is creating new identifiers, of course. Although I've seen cases where the programmer in question for whatever reason decided that because ImediateFlag was undefined then they would just define it, even though ImmediateFlag existed and was what they meant. That ought to get you fired in my book.
Hey by the way, pair programming is a great way to have continuous code reviews and a check on some of the more typical fumble-finger errors.