Live data from Hacker News

Marko – A declarative, HTML‑based language

markojs.com

91–100 of 189 posts

Re: Marko – A declarative, HTML‑based language

#91
post #46

This sort of stuff is just a big nope: Why make a special language? Just use HTML and TypeScript that will be compatible with editors, tooling, etc. This is the same mistake Imba made. It's a shame because the core of Marko looks phenomenal: streaming, fine-grained bundling, rendering performance, etc. Also not sure about the file-based routing of Marko Run. That was a big reason why I abandoned SvelteKit.

File-based routing is fundamentally flawed and it cannot be fixed. A number of libraries opt for it since it's easier for newcomers to pick up, but eventually you run into all of the cases where you do need something else. This in turn leads you to a hybrid system of multiple things where there's no single source of truth and everything is spaghetti.

Care to make quite a simple example where file based routing would struggle?

Re: Marko – A declarative, HTML‑based language

#92
post #51
post #48

Earlier quoted context omitted.

FWIW, marko comes from Ebay. So, it scales - and being primarily SSR, its a better UX than your preferred frameworks

Pretty much every JS framework has SSR, the question is really how quickly does it hydrate. React typically rates poorly there but Svelte does great, at least partially because it has a compiler to optimize (like Marko does, it appears).

Marko’s compiler is designed for partial hydration (by default, without any special developer effort), which performs quite well. IIRC they were also looking at implementing “resumability” (term coined by Qwik, for an approach that sidesteps hydration as a concept entirely). I’m not sure where they’re at on that now, but I think it’s generally safe to say that Marko prioritizes load time performance more than nearly all other frameworks.

Re: Marko – A declarative, HTML‑based language

#93
post #51
post #48

Earlier quoted context omitted.

FWIW, marko comes from Ebay. So, it scales - and being primarily SSR, its a better UX than your preferred frameworks

Pretty much every JS framework has SSR, the question is really how quickly does it hydrate. React typically rates poorly there but Svelte does great, at least partially because it has a compiler to optimize (like Marko does, it appears).

[dead]

Re: Marko – A declarative, HTML‑based language

#94
post #57

Earlier quoted context omitted.

I mostly agree with you but React isn’t just JavaScript. JSX is not JavaScript. It’s just that we’re so used to it we don’t consider it notable any more. Worth keeping in mind when you’re looking at a brand new framework.

I mean, you’re technically correct. But you’re also not understanding the point. What people mean when they say “React is just JavaScript” is… 1) JSX, more than any other templating system, is just HTML interleaved with JavaScript. It’s HTML, and anything between { and } is evaluated as JavaScript. 2) Inserting a React component’s “HTML tag” in your JSX is _actually_ the same as calling the JavaScript function. The H…

It's further than that even. JSX has the semantics of (modulo a couple of optimisations there and there) a bunch of nested function calls returning normal JavaScript objects. That means you can, in your head, very easily convert between the JSX representation of an expression and the equivalent transpiled JavaScript code.

This is unlike a lot of other templating languages where, even if the expression part of the language is pure JavaScript (or PHP or Python or whatever), it's still interleaved with arbitrary text which will get printed out according to its own rules. This makes the whole thing much harder to reason about (leading to the philosophy that you should put as little logic as possible in your templates because it makes them harder to understand, _even when that logic is directly related to the templating process_.

A good example is for-loops. In a lot of templating languages, you start in text-land, then you enter expression-land to write the opening {% for (const X of ...) %} line, then you're back in text-land again. You sprinkle in a couple of expressions, and then at the end you go back to expression-land to close the loop. You're jumping backwards and forwards between the two worlds, but there's no real syntactical or structural support for mixing them.

Meanwhile, in JSX, you start in text-land, then you open up an expression between two curly braces, and in that expression you write the entirety of your loop. If you need to go back to text-land within that loop, you can create a _new_ set of text nodes, but you're not interleaving expressions and text in the same way.

The result of this is that, once you understand how your JSX will get compiled, it's very easy to read it as if it were the JavaScript that it will get compiled to, rather than as a separate templating language. Which in turn makes it very easy to think of it as "just JavaScript", even if it's technically a syntax extension.

Re: Marko – A declarative, HTML‑based language

#95
post #57

Earlier quoted context omitted.

I mostly agree with you but React isn’t just JavaScript. JSX is not JavaScript. It’s just that we’re so used to it we don’t consider it notable any more. Worth keeping in mind when you’re looking at a brand new framework.

I mean, you’re technically correct. But you’re also not understanding the point. What people mean when they say “React is just JavaScript” is… 1) JSX, more than any other templating system, is just HTML interleaved with JavaScript. It’s HTML, and anything between { and } is evaluated as JavaScript. 2) Inserting a React component’s “HTML tag” in your JSX is _actually_ the same as calling the JavaScript function. The H…

I don't think the syntactic sugar works how you describe. JSX components actually desugar to something like:

   {jsx(MyComponent, { attr: "yes" })
(Previously this function was called "React.createElement", but these days they have special functions that only the JSX compiler is allowed to use.) The extra layer of indirection is needed to do things like support hooks being called inside of MyComponent's function body, keep track of `key` props, and so on.

Re: Marko – A declarative, HTML‑based language

#96
post #57

Earlier quoted context omitted.

I mostly agree with you but React isn’t just JavaScript. JSX is not JavaScript. It’s just that we’re so used to it we don’t consider it notable any more. Worth keeping in mind when you’re looking at a brand new framework.

I mean, you’re technically correct. But you’re also not understanding the point. What people mean when they say “React is just JavaScript” is… 1) JSX, more than any other templating system, is just HTML interleaved with JavaScript. It’s HTML, and anything between { and } is evaluated as JavaScript. 2) Inserting a React component’s “HTML tag” in your JSX is _actually_ the same as calling the JavaScript function. The H…

And this is one of the disadvantages of JSX. The snippets you posted are NOT identical.

JSX (react flavor) is lazy. is not rendered/evaluated until it's needed.

You can't just call a react component. It's not a regular function call.

Re: Marko – A declarative, HTML‑based language

#97

This is actually quite cool - JS inside HTML, rather than the more React-y HTML inside JS. As I understand it, Ryan Carniato was a major part of this project, and later went on to lead SolidJS, which goes back to the React style HTML in JS. Has he spoken at all about why he went back to that templating style?

JS inside HTML! Groundbreaking! It's nothing like Netscape ever conceived in 1995...

Re: Marko – A declarative, HTML‑based language

#98

previously: January 2023, 125 comments - https://news.ycombinator.com/item?id=34591625 August 2017, 150 comments - https://news.ycombinator.com/item?id=15057371 February 2015, 10 comments - https://news.ycombinator.com/item?id=9065447

Oh wow! So I guess Marko has been around for while. Despite that, this is my first time hearing about it.

The main author also wrote morphdom circa 2015, which is/was used in htmx and sprung up a bunch of other frameworks.

Re: Marko – A declarative, HTML‑based language

#99
post #68

I didn't look deep into Marko yet, but in my opinion JSX is by far the best HTML template language there is. And it's not restricted to React. Most other template languages hits serious limitations really fast. I tried and hated (for non trivial things): Angular, Handlebars, Razor (dotnet) and Vue (which does support JSX optionally).

Could you please try to be a bit more substantive with your comments? E.g., Why do you think JSX is the best? What limitations did you hit with those other template languages?

Most template languages can't do something like that:

  // data
  const numbered = true // or false
  const strings = ["a", "b", "c"]

  // render
  const items = strings.map(i => Item {i})

  if (numbered)
    return ({items})
  else
    return ({items})

Re: Marko – A declarative, HTML‑based language

#100
post #62

Earlier quoted context omitted.

Yes, we go in circles, but there are subtle (and sometimes not so subtle) improvements every iteration. Of course sometimes there are also dead ends. It is exciting to see what the ingenuity of the next group brings, even though some existing things are lost, but hopefully not forgotten.

This. Also it cannot be understated: apis, language and tooling are miles ahead better they were a decade ago or more.

I’m not completely sure of that. The simplicity of a backbone app, plain javascript with no build, less/sass, early days node.js or old RoR apps is becoming increasingly elusive. Not a lot of modern apps you couldn’t build with those stacks, and most of the underlying technology is the same (http/html/css/js/sql/libuv/etc).

Saying this feels like advocating for a return to horse carriages though, when the right analogy would be the brief electric car era of the early 1900s, and React as the Model T.

Post reply on HN