One thing which was not immediately obvious to me for a while: the stricter your language’s formatting is, the easier it will be to grep source code. I work a lot with Go, where all code in our repository is gofmt'ed. You can get quite far with regular expressions for finding/analyzing Go code. (And when regexps don’t cut it anymore, Go has excellent infrastructure for working with it programmatically. http://golang.…
Don’t underestimate grep-based code scanning
71–80 of 122 posts
Re: Don’t underestimate grep-based code scanning
#72 int
foo_func(void) {
You can grep for `^foo_func\b` to get to a declaration or definition, or `^foo_func\b.* {$` to get to a definition or `^foo_func\b.* ;` to get to a declaration. This is instead of using something like `^\w.* \bfoo_func\(`, which is what you'd need for: int foo_func(void) {
By the way, anyone know of a way to insert a literal asterisk here without having to follow it up with a space?Re: Don’t underestimate grep-based code scanning
#73Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep if you like. ag FooBar | grep -v Baz It's in brew/apt/yum etc as `the_silver_searcher` (although brew install ag works fine too). 0: https://github.com/ggreer/the_silver_searcher
Re: Don’t underestimate grep-based code scanning
#74Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep if you like. ag FooBar | grep -v Baz It's in brew/apt/yum etc as `the_silver_searcher` (although brew install ag works fine too). 0: https://github.com/ggreer/the_silver_searcher
ag provides sane default and settings for developers. grep is ubiquitous and great, but to do what most developers want it requires some guidance, whereas ag focuses on being what you want most of the time.
What I mean by that is that I enjoy the smart-case sensitivity (as in, if there are not caps in my pattern, then it defaults to case-insensitive but if I have any caps in my pattern, it uses case-sensitive) or fast filename searching with -g or both with -G.
I've tried rg and while it was faster, it also didn't provide as good support for filename searching. Ag is still what I consider "so fast I almost don't believe it"
It's like the 'tldr' command (https://tldr.sh/). Of course I still use man pages, but having something that gets me what I really need very quickly is important.
Steps:
1. Use ag
2. If ag isn't present, try to install ag
3. If I can't install ag, then use grep or find, no big deal.
ag > ack > grep/find
Re: Don’t underestimate grep-based code scanning
#75Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep if you like. ag FooBar | grep -v Baz It's in brew/apt/yum etc as `the_silver_searcher` (although brew install ag works fine too). 0: https://github.com/ggreer/the_silver_searcher
Is there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
Re: Don’t underestimate grep-based code scanning
#76Re: Don’t underestimate grep-based code scanning
#77Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep if you like. ag FooBar | grep -v Baz It's in brew/apt/yum etc as `the_silver_searcher` (although brew install ag works fine too). 0: https://github.com/ggreer/the_silver_searcher
Is there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
Well, there's no true hierarchy/succession order but rg was written after ag was.
Re: Don’t underestimate grep-based code scanning
#78Earlier quoted context omitted.
Is there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
Same experience here, started with ack and switched to ag and then to rg for speed. I've found them roughly equivalent in functionality, but for those who need specific features here's a link to a feature comparison table: https://beyondgrep.com/feature-comparison/
Re: Don’t underestimate grep-based code scanning
#79Earlier quoted context omitted.
Is there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
Pretty sure that rg is a successor to ag, so most people who use `ag` are just ones who haven't heard of `rg` yet. Well, there's no true hierarchy/succession order but rg was written after ag was.
Re: Don’t underestimate grep-based code scanning
#80The ability to easily grep for functions in C-like code is why I've come to appreciate projects defining their functions like: int foo_func(void) { You can grep for `^foo_func\b` to get to a declaration or definition, or `^foo_func\b.* {$` to get to a definition or `^foo_func\b.* ;` to get to a declaration. This is instead of using something like `^\w.* \bfoo_func\(`, which is what you'd need for: int foo_func(void)…