Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Programmer's Language-Aware Spell Checker?

Posted by kdawson on Tue Sep 04, 2007 04:12 AM
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?"
+ -
story

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
More
Loading... please wait.
  • by pringlis (867347) on Tuesday September 04 2007, @04:16AM (#20461575)
    The version of Eclipse I run, Eclipse WTP 3.3, does spell checking on comments as standard. Not for variable, function names and the like though. It's a decent first attempt though. In truth, I turned it off within the first few hours. It underlines any mistakes in red which I find really annoying when scanning code as I keep thinking I've seen syntax errors. More often than not my eyes are drawn to a spelling mistake, which in many cases isn't even really a mistake, which distracts me from what I'm actually trying to look at.
    • by Anonymous Coward on Tuesday September 04 2007, @07:03AM (#20462579)
      Man Dies Waiting for Eclipse to Launch

      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.
    • Spell checkers are fine but they make mistakes as well. The best thing I have found, and this goes for any project, software or printed word, is to have someone who is not connected to the project or better yet not even connected with the subject proofread what the public sees. They will often catch mistakes that jump off the page but people working on the project just don't notice. I have made some really stupid mistakes that I never saw but were on the cover of a book I was publishing. I am SO glad it was
      • Re: (Score:3, Informative)

        For the record, 'I' is a word. Also plenty of spellcheckers will ignore one or two letter words.

        The idea isn't anywhere near as nuts as you think it is, provided you make a habit of using meaningful variable/class names.
        • Also plenty of spellcheckers will ignore one or two letter words.
          So if you use fortran, you're screwed? No change there, then ...
            • by MindKata (957167) on Tuesday September 04 2007, @07:45AM (#20462959) Journal
              "Any douche who doesn't realise a misspelt function name will fail to compile clearly hasn't written any code yet."

              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: (Score:3, Interesting)

                You have one again confirmed Hartman's Law (or Skitt's, depending on preference; see http://en.wikipedia.org/wiki/Hartman's_law [wikipedia.org]).

                "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: (Score:3, Informative)

            Yeah, not to nitpick but, you see; 'i', being a variable-name, would be a properly camel-cased 'I' from the point of view of the spellchecker.
      • His next project is to have a handy little helper with a RAM chip avatar. His name is chippy and he comes out with helpful phrases like:

        "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?"
          • Re: (Score:3, Informative)

            1. The stop-problem is undecidable only on a device with infinite RAM, if you put an upper bound on the RAM, you get a decidable problem (in theory only).
            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)

            It's actually impossible for the computer to know whether you're creating an infinite loop.

            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)

          In fact, there are only two kinds of things to look at:
          • string literals (not what the poster wanted, but this is what needs spelchekars the most)
          • identifiers

          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)

    by Anonymous Coward on Tuesday September 04 2007, @04:16AM (#20461583)
    Visual Assist for Visual Studio does this.

    Next silly question, please.
    • by nietsch (112711) on Tuesday September 04 2007, @05:23AM (#20461947) Homepage Journal
      Please don't use the names of the tools the beast of Redmond uses to stupify the world. This is /. after all, if you have to code on/for windos, then please be humble and shy about it.
    • Re: (Score:3, Informative)

      It is important to note that with a large code base, Visual Assist is noticing any time you have a variable or function name that it can't find anywhere else, and highlighting it with the red underline. This is in addition to turning the various keywords, macros, #defines, class names, function names, member variable names, nonmember variable names, and other such things all into their own colors. Granted, if you misspell something everywhere, then it will highlight correctly, and not indicate a problem.
      • Re: (Score:3, Informative)

        See listed spelling features. It will spell check normal language (looks like only comments) and highlight *mistyped* symbols, not mispelled symbols.

        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.

  • by uucp2 (731567) on Tuesday September 04 2007, @04:18AM (#20461589)
    Some people call using it a "code review". If you are really serious about it, post the code to /. - plenty of people here seem to have time to point out any spelling errors.
    • by Anonymous Coward on Tuesday September 04 2007, @04:27AM (#20461639)
      Um, let me introduce you to the famous spelling mistake: HTTP Referer [wikipedia.org]. How about we let computers and people each do what they're good at. Computers are good at comparing strings in a spell checker, and people are good at producing typos, spelling mistakes, and approving fixes. Discipline isn't the solution, better tools are. (I bet there's a spelling mistake in here -- which proves my point that Opera needs a spell check like Firefox!)
    • by iapetus (24050) on Tuesday September 04 2007, @05:21AM (#20461937) Homepage
      You're aware of the concept that a bug is cheaper to fix the earlier you spot it? If it's flagged up as soon as it happens I have to rename that one variable in one place, and I can do it at virtually no cost. If it's flagged up after I've finished the work and committed it for review, then I'll need to change it across multiple files (sure, an IDE will do refactorings like that in most cases, but there can be side effects) and recommit. That's a far greater expense.
  • by PhrostyMcByte (589271) <phrosty@gmail.com> on Tuesday September 04 2007, @04:25AM (#20461629) Homepage
    And not too hard to implement - all you need is a lexer and a few functions to classify different naming styles. lexertl [benhanson.net] even comes ready with a full example for C++, so get to it ;)
  • vim 7.0 anyone? (Score:3, Insightful)

    by Janek Kozicki (722688) on Tuesday September 04 2007, @04:28AM (#20461647) Journal
    I particularly like the spelling feature in new vim, right-click menu (:set mousemodel=popup) to select a corrected word or remember current word as correct. Perhaps writing a vim plugin as you explain could be possible? I'd be very glad to use it too ;)
  • by YeeHaW_Jelte (451855) on Tuesday September 04 2007, @04:33AM (#20461667) Homepage
    We've got code here that refers to 'insurrances', 'insurances', 'insurrences' and 'insurences', I'm not kidding.

    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.
    • by Corporate Troll (537873) on Tuesday September 04 2007, @04:48AM (#20461755) Homepage Journal

      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.

  • by NNKK (218503) <nknight@runawaynet.com> on Tuesday September 04 2007, @04:44AM (#20461735) Homepage
    TextMate on OS X has spell checking functionality that is semi-useful, but it's not really "aggressive" enough, and there doesn't seem to be a way to make it such with prefs/configuration.

    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)

    by atlep (36041) on Tuesday September 04 2007, @05:22AM (#20461941)
    I remember from spellchecking some html documents a while back ago that aspell is at least aware of html. I do not know how well it works with other kinds of documents.
  • How about this (Score:5, Interesting)

    by Ed Avis (5917) <ed@membled.com> on Tuesday September 04 2007, @05:48AM (#20462093) Homepage
    Yes, this is a legitimate problem. I work on code that has spelling mistakes embedded into interfaces and it's very annoying. The fashionable use of StudlyCaps in programming (why? who decided that TextLikeThis is more readable than text_like_this?) makes the job a little harder but not impossible, as long as you follow the sane rule of making each word start with capital and continue lowercase, even if an acronym (so XmlParser not XMLParser or, God forbid, XMLparser - though of course XML_parser would be better than any of those).

    Enough rant. How about this:

    perl -ne "s/([a-z])([A-Z])/$1 $2/g; tr/A-Za-z/ /c; foreach (split) { print qq{$_\n} unless $seen{lc $_}++ }" source_file...

    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 /usr/share/dict/words or in the private word list. Indeed, why not this:

    find . -type f -name '*.c' | xargs perl -ne "s/([a-z])([A-Z])/$1 $2/g; tr/A-Za-z/ /c; foreach (split) { print qq{$_\n} unless $seen{lc $_}++ }" >found_words
    sort -u private_word_list /usr/share/dict/words >allowed_words
    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.
    • who decided that TextLikeThis is more readable than text_like_this?


      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)

    by Koyaanisqatsi (581196) on Tuesday September 04 2007, @05:58AM (#20462157)
    For .net languages, FxCop does some of this checking, even understanding camel casing and underscores in tokens. And a bunch more, since it is a static code analysis tool.

    http://www.gotdotnet.com/Team/FxCop/ [gotdotnet.com]
  • Visual Assist (Score:3, Interesting)

    by soundman32 (147936) on Tuesday September 04 2007, @06:02AM (#20462179) Homepage
    Doesn't Visual Assist from Whole Tomato do this? I've used it in the past and I'm sure spelling mistakes (and a whole host of other things) were pointed out.

    I'm not associated with Whole Tomato, but if anyone from WT sees this, can I have a free subscription :-)

      • Re: (Score:3, Interesting)

        '' It points out spelling mistakes in "strings" but not variable names. ie, it won't point out that the variable lAnsIdx is spelt incorretly, like the submitter is asking for, that would be just stupid. ''

        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)

    by Taagehornet (984739) on Tuesday September 04 2007, @06:47AM (#20462451)
    True, identifier names containing spelling errors can be a real annoyance, but I somehow doubt you'll ever find a usable solution, at least not as long as you'll need to interface to code beyond your control. What spell checker wouldn't choke on regular C++? Just picking a random declaration from MSDN (feel free to choose any other API, it won't change anything):

    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)

      Just looking at that declaration makes me want to claw my eyes out. Bad C++ is almost (but not quite) as bad as Perl.
  • by Maximum Prophet (716608) on Tuesday September 04 2007, @10:38AM (#20464801)
    Wow, 240 comments about spelling and programming and no-one's mentioned the famous Ken Thompson quote:

    "If I had to do it over again? Hmm... I guess I'd spell 'creat' with an 'e'."
  • by SuperKendall (25149) on Tuesday September 04 2007, @10:42AM (#20464871)
    Still a great IDE after all these years...
    • by DarkSkiesAhead (562955) on Tuesday September 04 2007, @04:41AM (#20461719)

      if you want your code to read like english, you consider a language like COBOL? Not that it would help you with spell checking, per se...

      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".

      • by Splab (574204) on Tuesday September 04 2007, @04:49AM (#20461759)
        Also people tend to miss that our brains are very good at correcting spelling mistakes as we read, doing code review trying to catch spelling mistakes can be very tough.
      • by evanbd (210358) on Tuesday September 04 2007, @05:21AM (#20461935)

        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: (Score:3, Informative)

        If you maintain a library that is used by customers, that would be a *very* big issue. You just broke backwards compatibility for a spelling fix.

        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)

      by YttriumOxide (837412) on Tuesday September 04 2007, @05:03AM (#20461823) Journal
      It's not so simple when you're not the one writing the code, but have to deal with the results. There's an SDK that I use as a part of my job, developed by our head office in Japan - it's a set of C# classes, and nothing annoys me more than typing "Connection foo = new Connection();", then noticing Visual Studio isn't highlighting it as I'd expect. Hunting around for anywhere up to a minute and eventually finding out it is actually "Conectin" instead of "Connection". If there were a good "programmers spellchecker", I may not need to use it myself, but I could give it to my Japanese colleagues to make MY life easier! (note: the above example is fictitious, but is an illustration of the type of error that I deal with that this would prevent)
      • Re: (Score:3, Insightful)

        Remember... your code will run faster if you remove some, but not all, vowels from your variable names.

        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
    • by BasilBrush (643681) on Tuesday September 04 2007, @05:04AM (#20461831)
      The question wasn't about user interface strings. It was about spelling in APIs. e.g. One issue at my last company, which was British, is that they standardized on US spelling, but some British spellings crept in too. So sometimes you'd get a function containing "Initialize" and sometimes "Initialise".
      • no, clearly he meant you need to keep all your _identifiers_ in external files too, by "interface" he means API