74
21
ot
I wish I had known about cog some 14 years ago when I implemented exactly the same thing (https://github.com/ot/inpytex).

It was made for LaTeX files but could have worked with anything. It even uses the same checksum protection!

I wonder how many people independently came up with the same idea.

chriswarbo
I think the closest "standard" tool for this is m4, which doesn't seem powerful enough for most applications.

Lips seems similar, but for Lisp/Scheme (e.g. https://github.com/zc1036/lips https://github.com/rbryan/guile-lips )

teddyh
My immediate thoughts:

• PHP, the poster example for template-based languages, seems to have spent all its recent years in development trying to get away from its HTML templating roots. I basically never see a PHP file in the wild which is using the old style with mostly HTML with sprinkles of PHP; it’s almost all pure PHP.

• Python has a perfectly good templating system in Jinja2, used by Flask and many others. Last I looked, even Django seemed to imply that they’d themselves would rather be using Jinja2 than Django’s own templating language. IIRC, Django even natively supports replacing its templating engine with Jinja2.

• For small-ish templates embedded inline in code, Python now has f-strings.

Therefore, I wonder: In what situation, exactly, would Cog, a PHP-style inline code templating system, be better than Jinja2 and/or f-strings? And would this benefit be worth the added cost of having yet another model of abstractions which few people would be familiar with?

bytK7
Looking at this reminds me strongly of texthon, but with a less attractive syntax. A quick skim through the source appears to show a similar use of eval.

Too bad texthon is essentially unknown and unmaintained, as far as I know. I worked on a project with it for several years and it always worked really well and was much more pleasant to use than something like jinja. Maybe I need to make a modern fork…

Anyway, anyone interested in cog should check it out as well.

vitiral
I both like and dislike the "immediate inline" nature. I guess it depends on what you're using it for. It's great when the output is small, but I just imagine folks using it to generate enourmous classes or such inline, forcing programers to scroll through all of that, as well as giving false signals when searching code.

Like any tool, you need to use it well or it will be a foot gun.

neilparikh
petre
This is possibly worse than the C preprocessor.