Live data from Hacker News

Idea: using code rather than templates to generate HTML

github.com

31–40 of 74 posts

Re: Idea: using code rather than templates to generate HTML

#31
post #2

I've been sitting on this for a while and finally pushed it out, having never really had the chance to give the idea the work it deserves. Anyway, the idea is simple: templates are a mess. They have goofy language variants, etc. Your editor can't color them. Why not just use code to generate the HTML? Still needs: Context-sensitive escaping, css generation, javascript inclusion.

The reason why not is that eventually you will want to hand the site to a designer and not have to do a half-hour of work on it every coupla weeks for the rest of its life. Making things easier for the designer reduces your total work; forcing the designer to work inside the HTML your tool produces will either limit the nifty things she can do, or require you to come back and touch this code again and again. Even the…

If you've designed your markup well, this argument is a red herring; the designers aren't changing the markup, just the styling. It's also just not the case that templating schemes address this pain; any time your designer changes (bad) markup, you're likely to have to alter the code that produces it.

Re: Idea: using code rather than templates to generate HTML

#32
post #24

Earlier quoted context omitted.

Indeed, the most effective team will be at least minimally cross-disciplined. I think the desire to generate HTML via code is just a case of unfamiliarity. I've been writing code since 1986 and HTML since 1994, and I have to say that there is no advantage to generating via HTML per se (frameworks like Seaside notwithstanding). If you have a decent text editor it can color and edit templating languages just fine. Deve…

What if you want to repeat a similar chunk of HTML in a loop? What if you want variables? Functions? ? The world has spent too much time trying to hammer programming language constructs into XML-based languages and templating systems. There simply has to be a better, way, but no one has successfully come up with one that satisfies everybody yet.

That's where template systems like Django's and stuff like PHP come in handy. I can pass either off to a designer who knows HTML and they are off to the races.

Re: Idea: using code rather than templates to generate HTML

#34

Answer to "why not just use code to generate HTML?": to facilitate communication between the programmer and the designer. If you work with designers who create the HTML for you, it is much easier for them to deal with back-and-forth tweaks and edits using a template. But if you are acting as both the programmer and the designer on a project, then yes it's possible that coding the HTML might be better.

s/possible/likely in my opinion.

Re: Idea: using code rather than templates to generate HTML

#35
post #25
post #14

Not to rain on your parade, but this is a pretty ancient idea. I don't have links handy but I remember doing this with PHP (amusingly enough) around the turn of the century, and I'm pretty sure Perl has had something in place for eons. There are also a number of Python options if you google around. Though, at least looking at the Python implementation it seems very clean and simple compared to others I've seen (thoug…

For a project 1.5 years ago, I generated all my html via markaby from _why. It really kept my html very very clean, but the downside was that the designer guy didn't understand what the heck was going on so I haven't considered using it since.

Yeah, that's one of my objections.

HTML is a designers tool, and generating it is basically a programmer working by what they perceive as an annoyance by shooting someone else in the foot. It also smacks a bit of "I see no value in how this is done so I'm going to generate it from code", which I think is ignorant, but that's my opinion.

I also don't think it's as maintainable, but I have no evidence to back this up (but I really don't want to be the guy who has to go decipher the code that generates a website two years later, I'd even rather deal with ColdFusion).

Re: Idea: using code rather than templates to generate HTML

#39
post #35
post #25

Earlier quoted context omitted.

For a project 1.5 years ago, I generated all my html via markaby from _why. It really kept my html very very clean, but the downside was that the designer guy didn't understand what the heck was going on so I haven't considered using it since.

Yeah, that's one of my objections. HTML is a designers tool, and generating it is basically a programmer working by what they perceive as an annoyance by shooting someone else in the foot. It also smacks a bit of "I see no value in how this is done so I'm going to generate it from code", which I think is ignorant, but that's my opinion. I also don't think it's as maintainable, but I have no evidence to back this up (…

HTML is a designers tool

I thought the modern idea was that CSS is the designer's tool, and HTML should only be used for marking up content in the most semantically "correct" way (which has nothing to do with design).

Re: Idea: using code rather than templates to generate HTML

#40
As per the python example, this has been done a lot in already, to name a few: http://www.hoboes.com/Mimsy/?ART=128 http://code.activestate.com/recipes/366000/ http://www.linuxjournal.com/article/2986

and others, as pointed out in Guido van Rossum's 1999 "Using Python for CGI programming"

Post reply on HN