3 ms·
I’ve always wondered why regular expressions and full text indexes are the best thing we expect out of a code search engine. I mean, we’re talking about code h
by ninkendo 7y ago
I’ve always wondered why regular expressions and full text indexes are the best thing we expect out of a code search engine.
I mean, we’re talking about code here. Text meant to be interpreted and understood by a compiler. Why can’t we do better?
Why can’t I say “show me everyone that’s calling this function”, like an IDE lets me do? Or “show me functions that accept <type> as one of their arguments and return <type>”, in a way that integrates with the real grammar/AST of the language(s) in question, without resorting to clunky regular expressions?
I should be able to write structured queries against a codebase, with regexes being just one part of that query language.
- londons_explore 7y agoModern Google Codesearch does exactly this. You can try it out here: https://cs.chromium.org/ https://cs.chromium.org/ In typical google style, the documentation is all google-internal, but by clicking bits of source code you should figure out most of the commands. Doesn't work well on mobile unless you have a beefy CPU - sorry!
- michaelt 7y agoOnly some languages can readily support such features. For example C has a preprocessor and linking step driven by a build system. And C has a bunch of different build systems available, some of which are procedural rather than declarative. Maybe you'll need to support package management - if a function signature calls for a CopyOnWriteArrayList do you need to know what the subclasses and superclasses of that type are? Do you need to resolve all the dependencies to be able to do that? If you're thinking "No problem, everyone compiles their programs in CI anyway" - are you happy to skip indexing unused code and uncompileable code? And of course you'll be chasing after language and build tool changes - not only to one language, but every language. On the other hand, a nice simple grep? Sounds much simpler to me.