Slashdot Mirror


Google Unveils Code Search

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

40 of 212 comments (clear)

  1. the one thing everyone will search by J3r3miah · · Score: 5, Funny
    --
    God is real unless declared as int
    1. Re:the one thing everyone will search by kripkenstein · · Score: 3, Funny

      A search for "bill gates" 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. */

    2. Re:the one thing everyone will search by mr_tommy · · Score: 2, 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)

    3. Re:the one thing everyone will search by Anonymous Coward · · Score: 4, Informative

      You can also find some unfunny stuff too!

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

      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.

    4. Re:the one thing everyone will search by groovelator · · Score: 2, Funny
    5. Re:the one thing everyone will search by nschubach · · Score: 2, Interesting
      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  2. COBOL hasn't been topdog for a while by BadAnalogyGuy · · Score: 2, Interesting

    VB has been the language with the most LOC since the early-mid 90's.

    As scary as that sounds.

    1. Re:COBOL hasn't been topdog for a while by doti · · Score: 4, Insightful

      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.

      --
      factor 966971: 966971
    2. Re:COBOL hasn't been topdog for a while by plopez · · Score: 2, 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' and syntacticly hasn't changed much since. So you could say that there is a lot of COBOL in 'Visual Basic'. Sure, it became object focused and now OO, but it still resembles COBOL. So COBOL lives on, as Visual Basic. It will not die :)

      And while I am on the soap box :) .....

      So much of the code I have seen is just COBOL in drag. Java, VB, C++, C# etc. just COBOL programs in drag. Most people have not really changed their mindset since COBOL.

      Case in point:
      I showed my boss who is supposed to be an OO programmer how to abstract out a data access layer so that the layer knows nothing about the request sent to it or the exact DB structure and the requesting class knew nothing of the database. I used a few of the nicer features of C# and .Net.

      My boss, supposedly a programmer didn't 'get it'. The upshot beign we ended up writing one class per DB table (as opposed to one table manager class total) and the results could have been quicker and easier in COBOL.

      I will now step down off the soap box.

      --
      putting the 'B' in LGBTQ+
    3. Re:COBOL hasn't been topdog for a while by locoluis · · Score: 3, Interesting

      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.

  3. Restricted Use Due to Copyrights by eldavojohn · · Score: 5, Interesting

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

    --
    My work here is dung.
  4. What's that I hear???? by bluelip · · Score: 5, Funny

    It's the sound of millions of CS majors cheering!!!!

    Dang, this a neat tool.

    --

    Yep, I never spell check.
    More incorrect spellings can be found he
    1. Re:What's that I hear???? by bluelip · · Score: 2, Insightful

      _OR_, the sound of thousands of Profs moaning.....

      --

      Yep, I never spell check.
      More incorrect spellings can be found he
    2. Re:What's that I hear???? by Gospodin · · Score: 3, Insightful

      Why? This makes it easier to check for plagiarism.

      --
      ...following the principles of Heisenburger's Uncertain Cat...
    3. Re:What's that I hear???? by SpinyNorman · · Score: 2, 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. Plenty of other things you could do too to normalize the code and factor out any trivial rewritings (changing parenthesis, etc).

      Any smart code comparison would look for function by function matches to factor out trivial reordering, and would anyways operate on a diff-like basic looking for changes rather than a yes/no match.

      Net result is that a smart code compare tool would not be fooled in the slightest if you completely reformatted the code, changed all the identifiers and comments, reordered all the functions, and even rewrote a few pieces for good measure - it'd still show a 95% match with the original, which for anything more than a trivial fucntion would be almost certain proof that id had been copied.

      Ben

  5. Non-alphanumerics at last! by maccallr · · Score: 4, Informative

    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"

    1. Re:Non-alphanumerics at last! by serialdogma · · Score: 2, Informative

      The @ prefix in PHP just stops it from printing an error message if something goes tits-up.

    2. Re:Non-alphanumerics at last! by fruey · · Score: 2, 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...

      --
      Conversion Rate Optimisation French / English consultant
  6. Useful to whom? by kjart · · Score: 4, Interesting

    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 :)

    1. Re:Useful to whom? by admdrew · · Score: 3, Insightful

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

  7. "Given enough eyeballs... by bloblu · · Score: 3, Informative

    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

    I hope this service will help improve code quality...

    1. Re:"Given enough eyeballs... by ggvaidya · · Score: 2, Interesting

      Some of those are a hack around the VC 6 "for loop doesn't scope as per ANSI" bug. This forum post explains when its used.

  8. Re:I like this search better - fucking funny as by kafka47 · · Score: 3, Funny

    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

  9. No need to search for Cobol? by krell · · Score: 5, Funny

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

    --
    Where were you when the voynix came?
  10. A good start.. by sfraggle · · Score: 5, Insightful

    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.

    --
    were you expecting to see a sig here? perhaps you'd rather see the inside of an ambulance!
    1. Re:A good start.. by Slurfer · · Score: 3, Informative

      According to the help / FAQ page, they are searching cvs & subversion repositories.

  11. Not that useful by fellm · · 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 - it is a vertical search engine that search ten of thousands of forums and millions of discussions. Usually someone already asked my question and hopefully it has an answer. It is highly recommended for troubleshooting and specific problems/questions.

  12. security hole search by Sub+Zero+992 · · Score: 5, Insightful
    --
    They who would give up an essential liberty for temporary security, deserve neither liberty or security - Ben Franklin
    1. Re:security hole search by RalphSleigh · · Score: 2, Informative

      Mmmmm, SQL injection for the world to see. Good Call.

      --
      Come as you are, do what you must, be who you will.
  13. The old saying is true . . . by scottennis · · Score: 4, Funny

    Good programmers write good code. Great programmers find it on Google!

  14. Your Search by mazarin5 · · Score: 3, Funny

    Your search 10 print "boobs" 20 goto 10 returned no results. Try searching again using fewer terms.

    --
    Fnord.
  15. Oh crap! by sparkyng · · Score: 4, Funny

    I hope my CS professor doesn't find this until the semester is over.

  16. Re:Well this answered a question for me... by Roger_Wilco · · Score: 2, Interesting

    I did a brief survey on "I hate [X]", and got the following:

    perl 9
    java 20
    c 8000
    c++ 11
    c# 1
    lisp 0
    scheme 0
    elisp 0
    fortran 3

    Looks like John McCarthy wins.

  17. I found orgasm code! by Jugalator · · Score: 3, Funny

    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;
    }

    --
    Beware: In C++, your friends can see your privates!
  18. Moo by Chacham · · Score: 3, Funny

    I just searched for "20 GOTO 10". Oh my. I don't know if that is funny or sad.

  19. Re:I like this search better - fucking funny as by tkittel · · Score: 5, Interesting

    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?

  20. This is great: finding algorithms by chroma · · Score: 2, Interesting
    I just had a need for this very thing. I've been looking for an implementation of the Minkowski sum in Java. And Google had it. 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.

    --

    Your design to a real part online: Big Blue Saw
  21. K&R vs. Alii by zobier · · Score: 2, Interesting

    Indent style searches: K&R about 5,900,000 Alli (Actually, this is a bit broken! Anyone worked out how to enable multiline mode?) about 11,100,000

    --
    Me lost me cookie at the disco.