I can get where this advice is coming from.
For newer devs, there can be a lot of “opportunities” to write code that benefit other people than the developer producing code for some solution or other. I mean, it might be someone’s “killer app idea” or a code-for-equity something, or one of those “hackathons” intent on engaging innovative people to help some firm or cause figure things out.
But a lot of code you write, especially when starting out is going to be “free” code. Finished a tutorial and want to explore some aspects of the language? That’s free code. Spent some time considering some technology and want to see how it work if you put something together, quickly? That’s free code, too.
You might have even seen an implementation of a solution and thought, “perhaps I can reason about that differently”. And you spend some time hacking together that approach. That’s free code.
As it turns out what some people call free code is just a part of how we developers learn, build and grow. Not always in that order. Ultimately, a more nuanced perspective is that one should learn to ask, why is this code I’m going to write valuable to me?
The answer to that should help determine if you want to press into an idea via code, or not.