Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does anyone else find macros make it hard to grep a code base? This does seem like something semantic grep could solve, but I'm unaware of any semantic grep macros use cases.


This is why I generally avoid making new structs via macros, and why I personally dislike the popular error library snafu: breaking “go to definition” and codebase search really needs to be worth it IMO. It doesn’t feel as bad for proc macros that add methods for whatever reason for me, but having to use a type with an opaque definition hidden behind a macro really bugs me.


Snafu works fine with at least rust-analyzer's gotodef (though go-to-references is indeed broken by it :/).


The problem is not macros, it is concatenation of identifiers. I stumbled upon this a lot when working with CSS preprocessors which allow you to write code like this:

    .user {
        &--profile { color: red; } 
    }
Now, searching for "user--profile" CSS class becomes imposible. Despite this, SASS and similar preprocessor seem to be popular and used almost everywhere. Well, I never had high expectations of front-end developers, so I am not very disappointed.

So I think as long as you don't break identifiers, the code should be searchable. But, your IDE will probably not able to help you with auto-complete and navigation.


> The problem is not macros, it is concatenation of identifiers.

Yes, that's also a problem. As is MySQLCursorDict Class. Now you have to grep every column name every table your code base accesses.


Moreso than calling an ordinary subroutine?


The code demo in the crabtime readme is actually a good example of something that is now hard to grep. Let's say you see a usage of `Position1`, and you want to find where and how it's defined - well, there is no `enum Position1` in the codebase, because the identifier is concatenated from two separate parts. You lose out on some IDE niceties as well - can't command-click on the definition site to find usages, because there is no definition site (available to you, at least).




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: