OK, I'd never heard of this before and now I'm questioning why we have all these JS templating frameworks like Mustache, Pug[1], and the rest.
[1] I actually use this one and it's just fine - great, in fact - but seeing M4 does make me feel like a lot of people may have spent a lot of time reinventing a wheel.
I actually looked into some of these frameworks (in particular mustache but also a few others) before deciding to use m4. They were all either too complex or too limited (sometimes both!) for my use case.
M4 is old and clunky but it gets the job done without having to install half a trillion Node.js dependencies. I also know that my script will still work just fine 5 years from now (or even 50 years in all likelihood).
That being said, don't trash your favourite JS framework right away, while m4 is perfectly fine for simple tasks I don't even want to imagine the layers of opaque and recursive macros you'd end up having to maintain for any moderately complex project. It's like shell scripts, it's very convenient but it doesn't really scale.
> while m4 is perfectly fine for simple tasks I don't even want to imagine the layers of opaque and recursive macros you'd end up having to maintain for any moderately complex project
I'm not doing anything too clever with Pug, but there are certainly a bunch of things that it makes quite easy that would otherwise be awkward or complex.
Lots of things work really nicely as well: includes, sections, configuration, and it certainly cuts down on typing. I'm absolutely not contemplating a switch from Pug to M4.
I just find it interesting that there's this thing that's been hanging around for decades that would do at least a partial job and is still decent for simpler use cases.
I've tried to get into M4 in the past but was always put off by the syntax. Mustache has been my go-to since it's simple and has lots of implementations in different languages. Are there any good reasons to use M4 over Mustache?
The only reason I didn't use Mustache was because it was unnecessarily complicated for my very simple use case. I just needed to effectively include blocks from other files in order to be able to share boilerplate between pages, plus having basic variable substitution for things like the page name. I even considered using the C preprocessor instead!
But I definitely wouldn't recommend using m4 for anything beyond a quick hack, unless you're a m4 wizard (or willing to become one) and you trust that whoever is going to work on the project is going to be one too. It's definitely clunky and not very user friendly.