"The above is valid Clojure code, not another language whose syntax you have to learn or separate compiler to use."
Even though this is a fair point, the comparison between the Jade solution and the Clojure one is invalid. Jade was conceived as a whitespace-significant language. Its biggest benefit over plain HTML (or HTML-based template engines like Moustache) is the usage of indentation to determine hierarchies.
The comparison would be more valid with something like http://domo-js.com, which is solving the exact same problem: using a single language (JS) for markup production – and even replacing CSS.
That's a fair point. Really, I think we're making the argument that we prefer data approach to templates (i.e., language-native data structures (maps, arrays, strings)) represent html structure.
You can certainly take that approach in JS. domo-js isn't quite that, it would look more like:
["html" ["head" ["title" {class: "class1"} "Welcome to Domo"]]]
As we say in the post, you can totally pull all this off in JS, but I think if you're going to be manipulating nested data structures, it's better to have immutable data structures built in and the suite of functions that can manipulate them. Clojure makes building template structures really easy: persistent data structures, map/seq argument destructuring, keywords, sets, etc.
It is not clear that whitespace sensitivity has ever been a good idea in any language. In jade, it is often just encourages the antipattern of hardcoded hierarchy and throwaway templates rather than reusable abstraction. We like actual abstraction more than trivial syntactic suger.
Comments
"The above is valid Clojure code, not another language whose syntax you have to learn or separate compiler to use."
Even though this is a fair point, the comparison between the Jade solution and the Clojure one is invalid. Jade was conceived as a whitespace-significant language. Its biggest benefit over plain HTML (or HTML-based template engines like Moustache) is the usage of indentation to determine hierarchies.
The comparison would be more valid with something like http://domo-js.com, which is solving the exact same problem: using a single language (JS) for markup production – and even replacing CSS.
That's a fair point. Really, I think we're making the argument that we prefer data approach to templates (i.e., language-native data structures (maps, arrays, strings)) represent html structure.
You can certainly take that approach in JS. domo-js isn't quite that, it would look more like:
["html" ["head" ["title" {class: "class1"} "Welcome to Domo"]]]
As we say in the post, you can totally pull all this off in JS, but I think if you're going to be manipulating nested data structures, it's better to have immutable data structures built in and the suite of functions that can manipulate them. Clojure makes building template structures really easy: persistent data structures, map/seq argument destructuring, keywords, sets, etc.
It is not clear that whitespace sensitivity has ever been a good idea in any language. In jade, it is often just encourages the antipattern of hardcoded hierarchy and throwaway templates rather than reusable abstraction. We like actual abstraction more than trivial syntactic suger.