Spending years as grumpy code janitor has taught me a number of hard lessons. Like, for example, unused *anything* (import, unexported function/variable) should be a fatal error, and there should never ever be any kind of indirect importing of anything.

If there was a reasonable way to make unused globals a fatal error I'd be all for that, too.

@wordshaper

Would that be "unused" as in uninitialized, or "unused" as in never used as a right value?

@lizmat unused as never an rvalue. Sometimes the initialization side effects for a bread variables are important but mostly not, and it’s just more time spent at startup and dependencies built. More mess that makes a build bigger, slower, and more annoying.

Honestly because of the uncertain side effects unused variables are arguably worse than unused functions, because they’re less safe to automatically clean up.

@wordshaper

Hmmm... feels like a special container class in #rakulang should be possible: once a value was fetched, set some flag. Then in END processing, check all those special containers and report if not used.

I guess the big thing would be keeping track of the containers: perhaps only if a trait is applied to the variable:

my $foo is required-rvalue = 42;

Something like that?

@lizmat That'd work, yep. It's a perennial issue with libraries that export things -- you can't know without having global knowledge of all your library's users whether an exported symbol is referenced. Variables with initializers are doubly annoying because you can't always tell if the initializer has some external effect so deleting unreferenced locals can have actual prod effects.

It's all very annoying to people who are code janitors. (And by "people" I mean me. It's me, the code janitor)