4 ms·
I love CoffeeScript but I don't understand this. HTML / HAML / SHPAML are document languages. CoffeeScript is a programming language. An element that contains
by mikemaccana 15y ago
I love CoffeeScript but I don't understand this. HTML / HAML / SHPAML are document languages. CoffeeScript is a programming language.
An element that contains another element isn't a function. I don't see any reason to make it one.
If you want a templating language, why not use one, rather than having an unnecessary 'space dash greater than' to indicate elements are contained within each other?
- gosub 15y agoa markup language like html is not made of elements that containts other elements, that is just an artifact of the syntax. A tag is more like a "semantic modifier" of its argument/the thing that it contains. How is <i>Lorem ipsum</i> different from (italicize "Lorem ipsum") or italicize :: string -> adorned-graphic-text ? edit: also, I think having one entire application expressed with only language (coffeescript vs html+css+javascript) is an advantage.
- maxwell 15y agoThese are arbitrary distinctions; as Heidegger said, language is language. As long as they're Turing complete, the only difference between "programming" and "templating" (and "natural") languages are what they're used/optimized for. Element A containing Element B can be generated by function A taking Element B. The CoffeScript program converts a set syntax/grammar into JavaScript; but the syntax is just syntax, and its clean, smart design lends itself well for compiling code other than JavaScript, just as JSON is a useful serialization format in other langs. There are benefits in using the same syntax for representing structure, content, and presentation, as long as the concerns are still properly separated.
- akdetrick 15y agoThe "language is language" argument has shifted my thinking a bit from my initial reaction to this project. In that line of thinking, it's also raised a new question in my mind. CoffeeKup seems to be optimized for baking logic into the template. It is not too different, but too much like most "templating" languages for me to completely get behind it. This is however, a really cool project that's well executed. I'm just hoping that the idea of further separating logic from templates takes hold (something like mustache, perhaps).
- gcr 15y agoThe example that really made sense for me was from "Smooth Coffeescript" in which the author writes an entire nodejs app in one file. Here, I'll show you: http://autotelicum.github.com/Smooth-CoffeeScript/ http://autotelicum.github.com/Smooth-CoffeeScript/ webpage = kup.render -> doctype 5 html -> head -> meta charset: 'utf-8' title 'My drawing | My awesome website' style ''' body {font-family: sans-serif} header , nav, section , footer {display: block} ''' coffeescript -> draw = (ctx, x, y) -> circle = (ctx, x, y) -> ctx.beginPath() ctx.arc x, y, 100, 0, 2*Math.PI, false ctx.stroke() ctx.strokeStyle = 'rgba(255,40,20,0.7)' circle ctx, x, y for angle in [0...2*Math.PI] by 1/3*Math.PI circle ctx, x+100*Math.cos(angle), y+100*Math.sin(angle) window.onload = -> canvas = document.getElementById 'drawCanvas' context = canvas.getContext '2d' draw context , 300, 200 body -> header -> h1 'Seed of Life' canvas id: 'drawCanvas', width: 600, height: 400 http = require 'http' server = http.createServer (req, res) -> show "#{req.client.remoteAddress} #{req.method} #{req.url}" res.writeHead 200, 'Content -Type': 'text/html' res.write webpage res.end() server.listen 3389 show 'Server running at' show server.address() Notice something missing? - There's no separate file for the HTML template - There's no separate file for the javascript inside - There's no separate file for the web server It's just "node circles.coffee" and you're good to go. CoffeeKup makes this sort of one-shot webapp experiment scripts particularly easy. Now you don't need an entire folder for each of your sandbox projects.
- benbeltran 15y agoI see how this is cool, but weren't we trying to separate style information from the program logic? ... This seems like a step back into PHP spaghetti code.
- pygy_ 15y agoThe style is applied through CSS. The CoffeScript is unobtrusive. The template and the sever logic are distinct (but there's an indentation error in the request handling code). It's about logical, not necessarily physical separation. For small apps, having everything in one place is actually very convenient. See also _why's Camping: http://camping.rubyforge.org/ http://camping.rubyforge.org/ (nowadays maintained by judofyr a.k.a. Magnus Holm)