Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Google Unveils Code Search

Posted by kdawson on Thu Oct 05, 2006 07:31 AM
from the let-the-regexp-begin dept.
derek_farn writes, "Google now has a page that supports source code searching. I hope they extend it to be more programming-language aware (e.g., search for identifiers and functions) like the specialist code search sites (Krugle, Koders, and Codease), who probably now have very worried investors. I don't see any option to search for Cobol. I guess there is not a lot of Cobol source available on the Internet, even although there is supposed to be more Cobol source in existence than any other language (perhaps that statement is not true in the noughties)." From the Cnet.com article: "Google engineers, many of whom participate in open-source projects, already use these code searching capabilities internally. Since it is a Google Labs project, the company is not yet seeking to monetize searches through ads."

Related Stories

[+] Google Code Search Reveals Dark Corners 297 comments
saccade.com writes, "The new Google Code Search isn't just for hackers sniffing for passwords. Jason Kottke and friends have discovered the new feature reveals all sorts of dark corners hidden in our code. And you thought nobody ever read your comments!" From the article: "Code search is a great resource for web developers and programmers, but like the making available of all previously unsearched bodies of information, it's given lots of flashlights to people interested in exploring dark corners."
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.

Google Unveils Code Search 50 Comments More | Login /

 Full
 Abbreviated
 Hidden
More | Login
Keybindings Beta
Q W E
A S D
Loading ... Please wait.
    • by kripkenstein (913150) on Thursday October 05 2006, @07:38AM (#16319479)
      A search for "bill gates" [google.com] turned up these tidbits:

      if (gates == NULL) /* eat this, Billy-boy */
      gates = (HINF **) Hmalloc (sizeof (HINF *) * 10);


      int_fast16_t reserved1; /* Ask Bill Gates what this is all about. */
      [ Parent ]
      • Re: (Score:2)

        My first thought was this [google.com]. I didn't think anyone actually used those in real life.

    • Re: (Score:3, Funny)

      Hilarious- the pains that writers have to code for browsers!

      - Calendar.continuation_for_the_fucking_khtml_browse r = function() {
      // check for function objects (as usual, IE is fucked up)
    • Re:the one thing everyone will search (Score:4, Informative)

      by Anonymous Coward on Thursday October 05 2006, @08:22AM (#16320027)
      You can also find some unfunny stuff too!

      This could be abused by email spammers.
      Search for: http://www.google.com/codesearch?q=%40 [google.com]

      This reveals a lot of email addresses in code.
      It's giving the spammers email addresses on a plate. (within a geek targeted audience)
      That's definitely not funny but scary.
      [ Parent ]
  • VB has been the language with the most LOC since the early-mid 90's.

    As scary as that sounds.
    • by doti (966971) on Thursday October 05 2006, @08:03AM (#16319787) Homepage Journal
      It's true that not a lot of people write COBOL today, but the submiter was talking about legacy code. No wonder they're not on the Internet: not only they are from a pre-Internet era, but the vast majority of it is from corporations that keep their code very closed.
      [ Parent ]
      • by locoluis (69948) on Thursday October 05 2006, @10:40AM (#16322213) Homepage Journal
        True. And if there's any COBOL code on the Internet, it can be found using the following search terms:

        "IDENTIFICATION DIVISION" "DATA DIVISION" DISPLAY PROGRAM-ID SECTION

        No need for Google to develop a special search for what look less like a computer program and more like a plain text file.
        [ Parent ]
    • Re: (Score:3, Interesting)

      Well... if we want to quibble... :)

      Basic was intended as a teaching language and so the language incorporated lots of syntax and ideas from the 2 major languages of the time: COBOL and FORTRAN.

      BASIC eventually begat that idiot bastard child 'Visual Basic'
  • Restricted Use Due to Copyrights (Score:5, Interesting)

    by eldavojohn (898314) * <my/.username@@@gmail.com> on Thursday October 05 2006, @07:40AM (#16319507) Homepage Journal
    I made a simple search for "fade file:.js" in order to find a javascript function that would fade a div or table or anything really (I know scriptaculous [aculo.us] offers this already, just curious as to what's out there). I found something but the header of the file read:

    All Code herein is Copyright 2005 Match.com
    Do not copy, reproduce, reuse or sell any code herein
    without the express, written consent of Match.com.
    For information contact webmaster@match.com.
    All Rights Reserved.

    Which is expected. However, that means this tool isn't useful for finding a method or function or class I can use and then using it ... it seems to be restricted to one of two uses. If I'm looking for code that does natural language parsing, I could hope a comment somewhere contains NLP as a description of what's going on. Or, I could look for libraries out there with methods and then search for those methods to see how other people used them to get an idea of how they work. The vast majority of this code seems to be just web development front-end code at least from the few searches I've done. Too bad, that's a very small part of programming.
    • Re: (Score:2)

      You could always just search for code under the license you want. Instead of all code.
      • Re: (Score:2)

        But wait, aren't all those licenses listed in the combobox free (as in open source) licenses?
    • Re: (Score:2)

      But you can study the code, and try to apply the general idea to your own code.
  • ...I can forget RegEx's now.

    But honestly, this might have some bells and whistles but I don't see myself getting rid of my regular expression searches any time soon.
  • What's that I hear???? (Score:5, Funny)

    by bluelip (123578) on Thursday October 05 2006, @07:44AM (#16319561) Homepage Journal
    It's the sound of millions of CS majors cheering!!!!

    Dang, this a neat tool.
    • Re: (Score:2, Insightful)

      _OR_, the sound of thousands of Profs moaning.....
      • Re: (Score:3, Insightful)

        Why? This makes it easier to check for plagiarism.

          • Re: (Score:3, Insightful)

            Not really, you can just tokenize the code, removing the issue of white space, comments and formatting completely, and just treat identifiers as a token type vs even looking at the name - then you're just doing a pure structural comparison of the code. Ple
  • Non-alphanumerics at last! (Score:4, Informative)

    by maccallr (240314) on Thursday October 05 2006, @07:45AM (#16319563) Homepage
    At last we can use regexps and search on all the important characters between the alphanumerics! For example the prefixed '@' in PHP - very hard to figure out what this is, without reading the reference cover to cover. Now at least we can search the codebase and hope to see some useful comments preceding it, or figure out from context what's going on.

    e.g. "@fopen file:.php"

    • Re: (Score:2, Informative)

      The @ prefix in PHP just stops it from printing an error message if something goes tits-up.
      • Re: (Score:3, Informative)

        Not only stops it from printing an error, but ignores the error and carries on parsing the rest of the code.

        Useful for including a file that might not be there, for example...
  • How many (Score:2)

    Open Source projects that you know are written in COBOL? I don't know of any. It is a lot of legacy code. There is very few new projects being started in COBOL.
  • This is pretty cool.. i hate trying to search code on normal google, it usually filters out most of the search characters and you end up with nothing useful.

    Now if only they'd add regex searching to normal google (unless it already has it and i'm missing i
  • Useful to whom? (Score:5, Interesting)

    by kjart (941720) on Thursday October 05 2006, @07:47AM (#16319603)

    Whenever I search for something code related on the web it's usually because I want to know how to do something. In such cases I dont really know what the code itself would be (i.e. the reason why I'm searching) so this wouldn't help at all. I suppose if you were looking for specific code it could be useful, but why would you be doing that? That would likely be your own code, so wouldn't a simple grep be easier?

    I'm sure I'm missing something here - Google doesn't (usually) release useless new products :)

    • Re:Useful to whom? (Score:4, Insightful)

      by admdrew (782761) <admdrewNO@SPAMgmail.com> on Thursday October 05 2006, @09:27AM (#16320987) Homepage

      If you're unaware of how to do something from a design standpoint, you're right that viewing code is not necessarily going to help. This tool, however, works great for more specific issues related to syntax, etc. I've already used this to see examples of ItemTemplate [google.com] in C#. A simple search on regular google yields examples, but it also returns a lot of crap.

      When considering TMTOWTDI, looking at other code similiar to yours can be very helpful, and (for me, at least) can help break out of a code writers block when I've been working with a particular chunk of code for too long.

      [ Parent ]
  • "Given enough eyeballs... (Score:3, Informative)

    by bloblu (891170) on Thursday October 05 2006, @07:47AM (#16319621)
    all bugs are shallow."

    Well, it looks like that's not really the case: http://www.google.com/codesearch?hl=en&lr=&q=++%5C sif%5C(%5B%5E)%5D*%5C)%3B+license%3Agpl+lang%3Ac%2 B%2B&btnG=Search [google.com]

    I hope this service will help improve code quality...
    • Re: (Score:2)

      That's surprising to me.
      I never made that typo, and never saw it on other's code.

      Impressive.
  • No need to search for Cobol? (Score:5, Funny)

    by krell (896769) on Thursday October 05 2006, @07:49AM (#16319643) Journal
    "I don't see any option to search for Cobol."

    Well, that's one entire season of "Battlestar Galactica" rendered entirely pointless. Thanks a lot!
  • A good start.. (Score:5, Insightful)

    by sfraggle (212671) on Thursday October 05 2006, @07:50AM (#16319665)
    It's a good start. They really need to start searching Subversion/CVS repositories as well. One of the most obvious things that they seem to have missed is to index all the Sourceforge downloads.
    • Re: (Score:3, Informative)

      According to the help / FAQ page, they are searching cvs & subversion repositories.
  • Not that useful (Score:2, Interesting)

    As a programmer who needs to solve a problem I need a place to find answers to the problem I am solving. Searching for a code won't do it because I am looking for an answer and not how to code it. To find answers I use Omgili [omgili.com] - it is a vertical search engi
  • security hole search (Score:5, Insightful)

    by Sub Zero 992 (947972) on Thursday October 05 2006, @07:54AM (#16319697)
    How to find security holes in PHP web applications:

    http://www.google.com/codesearch?hl=en&lr=&q=Where +%5C%24_POST+-addslashes+lang%3Aphp [google.com]
  • The old saying is true . . . (Score:5, Funny)

    by scottennis (225462) on Thursday October 05 2006, @08:00AM (#16319755) Homepage
    Good programmers write good code. Great programmers find it on Google!
  • Your Search (Score:4, Funny)

    by mazarin5 (309432) on Thursday October 05 2006, @08:03AM (#16319781) Journal
    Your search 10 print "boobs" 20 goto 10 returned no results. Try searching again using fewer terms.
  • For online services : Don't put up code that states explicitly, not for production [google.com] .

    For users : Stay away from online services that put up code that states "not for production". :-)

    cpan.org
    twiki.org
    osuosl.org
    ...

    /K

  • I searched for some of my own code from sourceforge CVS, and it couldn't locate it.
  • Proof (Score:5, Funny)

    by jmv (93421) on Thursday October 05 2006, @08:23AM (#16320037) Homepage
    Crap! There goes SCO's case [google.com].
  • Oh crap! (Score:4, Funny)

    by sparkyng (635050) on Thursday October 05 2006, @08:44AM (#16320313)
    I hope my CS professor doesn't find this until the semester is over.
  • I found orgasm code! (Score:4, Funny)

    by Jugalator (259273) on Thursday October 05 2006, @09:03AM (#16320595) Journal
    This is just too funny :-)

    void Mammal::mate( Mammal& partner ) { /* potential mating partner */
            M_partner = partner.getId(); /*printf( "." ); fflush( stdout );/**/ /* mating must be mutual */
            if( partner.getPartnerId() != M_id ) { /*M_wait += 15;/**/
                    return;
            } /*printf( "+" ); fflush( stdout );/**/ /* this is male object */
            if( M_gender == 0 ) { /* perform breeding in female object */
                    partner.mate( *this );
                    return;
            } /* this is female object */
            assert( M_gender == 1 ); /* current position */
            int x = M_x, y = M_y; /* behind position */
            switch( M_direction ) {
                    case EAST: x--; break;
                    case NORTH: y++; break;
                    case WEST: x++; break;
                    case SOUTH: y--; break;
            } /* back to field wall */
            if( !M_field->in( x, y ) ) return; /* newborn's position */
            int cx = M_x, cy = M_y; /* move mother backward */
            M_x = x;
            M_y = y; /* conception */
            orgasm();
            partner.orgasm();
            Mammal* child;
            child = new Mammal( *M_field, cx, cy, NEWBORNENERGY, *this, partner ); /*printf( "CHILD%d ", child );/**/ /* birth */
            M_energy -= CHILDBIRTHENERGY;
            M_population->add( *child );

            printf( "MATE(%d,%d)->%d(%d) ", M_id, partner.getId(), child->getId(), child->getGeneration() ); /* partner.printGenotype();
            partner.printState();
            printGenotype();
            printState();
            child->printGenotype();
            child->printState();/**/
    }

    void Mammal::orgasm() {
            M_energy -= MATINGENERGY;
            M_result = 1;
    }
  • Moo (Score:3, Funny)

    by Chacham (981) on Thursday October 05 2006, @09:22AM (#16320899) Homepage Journal
    I just searched for "20 GOTO 10". Oh my. I don't know if that is funny or sad.
  • This is great: finding algorithms (Score:3, Interesting)

    by chroma (33185) <chroma AT mindspring DOT com> on Thursday October 05 2006, @10:12AM (#16321767) Homepage
    I just had a need for this very thing. I've been looking for an implementation of the Minkowski sum [wikipedia.org] in Java. And Google had it [google.com]. So if you need to implement a particular algorithm that someone else might have already implemented, this is the way to find it.

    I can't find any of the software with my name on it that's on SourceForge, though.

  • K&R vs. Alii (Score:3, Interesting)

    by zobier (585066) <zobier AT hotmail DOT com> on Thursday October 05 2006, @10:46PM (#16332315) Homepage
    Indent style searches:
    K&R [google.com]
    about 5,900,000
    Alli [google.com] (Actually, this is a bit broken! Anyone worked out how to enable multiline mode?)
    about 11,100,000
    • Re: (Score:2)

      I would have tried it anyhow, considering that it was cited in the article summary.

      (Sorry couldn't resist) :-)

      /K

    • by kafka47 (801886) on Thursday October 05 2006, @07:48AM (#16319631) Homepage

      LOL your search has now uncovered the hidden angst of a million programmers :

      ($backend && $backend->isa("Acme::Scurvy::Whoreson::BilgeRat::B ackend::$params{language}")) ||
      die("For fuck's sake, the fucking backend's fucked");

      /K

      [ Parent ]
        • by tkittel (619119) on Thursday October 05 2006, @09:27AM (#16320985)
          I agree, it is rather funny. My favourite is so far:

          /usr/src/linux/arch/sparc/kernel/ptrace.c: /* Fuck me gently with a chainsaw... */

          But I also stumbled upon this little gem in /usr/src/linux/net/core/netfilter.c:

          /* netfilter.c: look after the filters for various protocols.
          * Heavily influenced by the old firewall.c by David Bonn and Alan Cox.
          *
          * Thanks to Rob `CmdrTaco' Malda for not influencing this code in any
          * way.
          *

          Anyone knows if there is a story behind this comment? Is it a private joke on taco, or did he piss them off?
          [ Parent ]
    • Re: (Score:2)

      Oh believe me, I've tried. To the whiny chorus of "Where's the curly brackets?"

      *sob*

    • Re: (Score:2)

      Maybe SCO can use it to find the millions of lines of misappropriated code that "got lost" in Blepp's suitcase?