Live data from Hacker News

Don’t underestimate grep-based code scanning

littlemaninmyhead.wordpress.com

61–70 of 122 posts

Re: Don’t underestimate grep-based code scanning

#61
post #23
post #21

Earlier quoted context omitted.

Illumos is also a supported platform (SPARC and x86-64).

You obviously haven't tried it on either of those. They are "second tier", which means one is completely on one's own. What in your opinion would have to be the size of the source code to warrant jumping through the hoops to get this software running, as opposed to a combination of find + xargs + egrep,fgrep,awk?

Could you please review the guidelines and post less rudely and antagonistically?

https://news.ycombinator.com/newsguidelines.html

Re: Don’t underestimate grep-based code scanning

#62
post #3

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

Related to this, it is generally a very good idea to be strict when naming functions, parameters, variables, etc. so that each concept has exactly one name throughout the codebase.

Also, check your spelling. It's a pain when items don't show up in search because of spelling issues.

I've seen function names misspelled, and then every invocation just doubling down on that misspelling.

Re: Don’t underestimate grep-based code scanning

#65
post #55

Earlier quoted context omitted.

And that’s why PowerShell is awesome :)

Powershell falls over in the other direction: the objects flowing down the pipeline are "magic" and can't be serialised, or even necessarily inspected with normal tools. For most unix operations you can replace foo | sort with foo > file sort I like the idea of powershell, but every time I try to do something complicated with it I'm disappointed.

That is some serious BS. Objects can be serialized easily.

    $WhateverObject | Export-CliXml
    $WhateverObject = Import-CliXml whatever.xml
Most of the time `>` also work.

By the way, PowerShell serialization is by orders of magnitude better then anything *nix has to offer as you can use objects from other machine shell just like they exist on your local one.

> I like the idea of powershell, but every time I try to do something complicated with it I'm disappointed.

I did some very complicated things in PowerShell. For example, check out the script that maintains ~300 mainstream packages on Chocolatey up to date, all in few minutes with bunch of self maintenance features.

You need to learn it, simple as that.

https://gist.github.com/choco-bot/a14b1e5bfaf70839b338eb1ab7...

Re: Don’t underestimate grep-based code scanning

#66
post #55

Earlier quoted context omitted.

Powershell falls over in the other direction: the objects flowing down the pipeline are "magic" and can't be serialised, or even necessarily inspected with normal tools. For most unix operations you can replace foo | sort with foo > file sort I like the idea of powershell, but every time I try to do something complicated with it I'm disappointed.

That is some serious BS. Objects can be serialized easily. $WhateverObject | Export-CliXml $WhateverObject = Import-CliXml whatever.xml Most of the time `>` also work. By the way, PowerShell serialization is by orders of magnitude better then anything *nix has to offer as you can use objects from other machine shell just like they exist on your local one. > I like the idea of powershell, but every time I try to do so…

I suppose this is a good demonstration of the best way of getting a right answer being to post a wrong one, as I spent a long time trying to work out how to do this last time I needed it.

Re: Don’t underestimate grep-based code scanning

#67
post #23

Earlier quoted context omitted.

You obviously haven't tried it on either of those. They are "second tier", which means one is completely on one's own. What in your opinion would have to be the size of the source code to warrant jumping through the hoops to get this software running, as opposed to a combination of find + xargs + egrep,fgrep,awk?

> one is completely on one's own That's not accurate. The test suites are not run on CI for tier 2, but they are at least guaranteed to build. Tier 2 platforms have binary builds, are supported by rustup and often work just fine.

TBF, the table of Tier 2 platforms has differences in features that are expected to work, Illumos has fewer than other platforms.

You need rust to build Firefox, so any platform that can't get it to work well is going to be at a disadvantage.

Re: Don’t underestimate grep-based code scanning

#68
post #52

Don'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

I find `git grep` to be quite sufficient. A real pain when trying to look through code that isn't in git though.

Re: Don’t underestimate grep-based code scanning

#69
post #52

Don'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

#70

Earlier quoted context omitted.

Related to this, it is generally a very good idea to be strict when naming functions, parameters, variables, etc. so that each concept has exactly one name throughout the codebase.

Also, check your spelling. It's a pain when items don't show up in search because of spelling issues. I've seen function names misspelled, and then every invocation just doubling down on that misspelling.

I encountered a similar problem in a c++ codebase and the debugging logs it produced. There was an error which was being reported in the logs as "weak ptr expired" or somethings like that. I grepped for it the whole source code (a gigantic project). No results. Going back and forth several times. Feeling stupid beyond imagination. Then I copy-pasted what was actually printed in the logs into my grep query (previously I was typing it in manually). It quickly found a match. Turns out someone wrote "weak ptr" as "week ptr". Everyone in the team had a good laugh.
Post reply on HN