News for hackers. Stuff that matters.
Re:Greppability is an underrated code metric by abc-1 on Monday September 02, 2024 @11:51PM (#41431072)
A lot of this reads like code search tools could and should be a lot better. They probably will be with AI finding its way into everything. In the old days, people would Hungarian prefix types, but now the IDE mitigates that with color codes.
Re:Greppability is an underrated code metric by ddfs123 on Monday September 02, 2024 @11:56PM (#41431102)
Unless you have syntax-aware grep support, I don't see how searching nested key json could be better. But grep is the default installed. Not to mention ad-hoc languages that does not have any IDE support.
Re:Greppability is an underrated code metric by abc-1 on Tuesday September 03, 2024 @12:05AM (#41431150)
If you put a lot of arbitrary constraints to not allow it to be better, sure. Enjoy.
Re:Greppability is an underrated code metric by medstrom on Tuesday September 03, 2024 @07:13AM (#41433661)
There is no conflict between improving tools and learning how to express your code in such a way that as many tools as possible work better OOTB.
Re:Greppability is an underrated code metric by uasi on Tuesday September 03, 2024 @12:18AM (#41431219)
gron makes nested JSON greppable https://github.com/tomnomnom/gron
Re:Greppability is an underrated code metric by hoherd on Tuesday September 03, 2024 @08:35AM (#41434358)
`gron` is so underrated. Usually when I try to show people who useful it is they don't seem to understand how powerful it is. One common use is showing how to customize only one part of a helm chart by checking values of an already installed chart:

    $ helm get values -n $NS $DEPLOYMENT -o json | gron | grep resources | gron -u | json-to-yaml.py
    elasticsearch:
      client:
        resources:
          limits:
            cpu: 3
            memory: 4Gi
          requests:
            cpu: 1
            memory: 2Gi
      data:
        resources:
          limits:
            cpu: 6
            memory: 6Gi
          requests:
            cpu: 200m
            memory: 2Gi
    fluentd:
      resources:
        limits:
          memory: 768Mi
        requests:
          memory: 384Mi
That snip could be provided to another team or a customer as a yaml file that could be included with `helm upgrade -f whatever.yaml`. This is soooo much easier than digging that limited set of data out of the much more detailed data.
Re:Greppability is an underrated code metric by NavinF on Tuesday September 03, 2024 @12:28AM (#41431266)
> ad-hoc languages

This is self-inflicted.

Re:Greppability is an underrated code metric by klodolph on Monday September 02, 2024 @11:53PM (#41431088)
Do you have some ideas for how to make code search better?

Right now, code search is basically just text search. If you think code search tools “could and should” be a lot better, what kind of improvements are you thinking about? How would those improvements work?

Re:Greppability is an underrated code metric by Terr_ on Tuesday September 03, 2024 @12:04AM (#41431142)
Not OP, but we wouldn't need to worry so much about picking out distinct grep-able names if (big if) there were tools that parsed the code to draw out concepts for us.

A simple example would be any "find usages" too, which can vary widely in accuracy by language and IDE. When it works well, naming becomes a lot less important, because you don't need to grep for potential usages and because refactoring with a better name is low-stakes.

Re:Greppability is an underrated code metric by klodolph on Tuesday September 03, 2024 @01:26AM (#41431564)
I guess I wasn’t thinking of “find usages”, but as the article points out, it’s hard to find usages if the usages are dynamic.

The solution—to write code which is less dynamic—helps code search and features like find usages.

Re:Greppability is an underrated code metric by alexpovel on Tuesday September 03, 2024 @02:22AM (#41431855)
Regarding your third point, I put together a tool capable of that to some degree.

It allows you to grep inside source code, but limit the search to e.g. “only docstrings inside class definitions”, among other things. That is, it allows nesting and is syntax aware. That example is for Python, but the tool speaks more languages (thanks to treesitter).

https://github.com/alexpovel/srgn/blob/main/README.md#multip...

Re:Greppability is an underrated code metric by abc-1 on Tuesday September 03, 2024 @12:05AM (#41431152)
Vector embeddings.
Re:Greppability is an underrated code metric by dragonwriter on Tuesday September 03, 2024 @12:36AM (#41431299)
> Right now, code search is basically just text search.

We have lots of code search that is much more syntax-aware than just text search, but it tends to be behind very limited UI, because we have all the tech to do much better code search, but no one has come up with a generally-usable UI for it, so we just have very specific instances -- like "go to definition", "find references" , etc.

That takes all the same technological bits that would be need for, say, "find all definitions of functions visible in the current scope whose name starts with 'ban'" or "find all definitions of int8 constants visible in the current scope"...but what's the UI that makes that kind of searching outside of the kind of special cases now behind their own IDE menu items usable?