News for hackers. Stuff that matters.
Re:Greppability is an underrated code metric by WalterBright on Tuesday September 03, 2024 @12:15AM (#41431203)
That's why D has a cast keyword:

    ubyte c = cast(ubyte)i;
instead of:

    unsigned char c = (unsigned char)i;
Casts are a blunt instrument that subvert the type system, and so they need to be greppable.
Re:Greppability is an underrated code metric by jenadine on Tuesday September 03, 2024 @01:33AM (#41431594)
Do you often grep for casts? I never do that.
Re:Greppability is an underrated code metric by WalterBright on Tuesday September 03, 2024 @02:58AM (#41432071)
I regard every cast as a bug in my own code and try to refactor it so there aren't any. I can't get rid of all of them, but they're always worth a second look.

I don't normally grep for them, but others have told me they did.

P.S. one thing about D is you can do things like this:

    ubyte b = i;            // error, losing bits
    ubyte b = cast(ubyte)i; // ugly cast
    ubyte b = i & 0xFF;     // no cast, no error!
It's just one of the nice little details that making programming in D a pleasure.
Re:Greppability is an underrated code metric by Too on Wednesday September 04, 2024 @01:08AM (#41442113)
These things are better checked automatically with a static linter, that presumably already has a full parser and AST representation of the language and knows what is a cast and not.

Nobody should keep a checklist of "100 things to grep for when doing a code review".

Re:Greppability is an underrated code metric by aa-jv on Tuesday September 03, 2024 @02:45AM (#41431994)
Try to think about why you might want to do that. It makes a lot of sense, but if you're not doing it, that might be enlightening...
Re:Greppability is an underrated code metric by SnowflakeOnIce on Tuesday September 03, 2024 @08:38AM (#41434378)
When doing appsec review in C or C++, yes!
Re:Greppability is an underrated code metric by EasyMark on Tuesday September 03, 2024 @09:22AM (#41434699)
Honestly I know I don’t do that either. I mean if there was some special case where I remembered “oh yeah I had to cast that variable in this special case”. In general I avoid casting as much as I can in C/C++, but especially in C.