News for hackers. Stuff that matters.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by mavili on Monday March 04, 2024 @06:46PM (#39597658)
This is insanely cool! Looks really slick too, even in a mobile screen.

jQuery?? I cannot imagine how difficult it is to not break this when you make the slightest change, hats off for managing with vanilla Javascript and jQuery! The best thing about React for me is to not have to worry about breaking the DOM or messing up with event handlers because some jQuery line, somewhere obscure is probably doing something funky that is really difficult to track down!

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Intralexical on Monday March 04, 2024 @07:01PM (#39597751)
Oh, wow. When this came up before, I don't know if I looked at the DOM, because I assumed you would do this type of thing by drawing pixels on a Canvas. It's actually made of HTML elements? That's impressive.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Aaronmacaron on Monday March 04, 2024 @07:41PM (#39598055)
I too think it's very impressive but wouldn't it be even more impressive if it was made using canvas? It would mean that you would need to implement your own rendering loop and layout engine. You'd need to reimplement a lot of elements such as input fields or buttons. You get all of this for free when building on top of HTML/CSS.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by noduerme on Monday March 04, 2024 @09:18PM (#39598704)
You do get a lot of UI elements for free, but styling them consistently and getting them to layout properly becomes a lot more difficult.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Intralexical on Monday March 04, 2024 @09:19PM (#39598715)
I think it would likely be more technically involved and complicated if it were made with `canvas`.

But large blobs drawing to `canvas` aren't anything new at this point. The part that impressed me is doing it the simple way, using what the browser already provides, and getting it to work this well.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by msephton on Friday March 08, 2024 @12:47PM (#39643609)
Synology DSM (the web interface for a Synology NAS) also constructs a desktop UI the HTML way.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by onetom on Tuesday March 05, 2024 @12:44AM (#39599866)
It's hard to make that performant.

As a reference, here is a browser-adapted version of the https://cuis.st/ Smalltalk environment, which does its own rendering onto a canvas:

https://github.com/nmingotti/The-Cuis-CookBook/wiki/Run-Cuis...

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by MatthiasPortzel on Tuesday March 05, 2024 @09:51AM (#39604147)
It’s not performant if you’re using JavaScript APIs. But it’s also possible to write to a canvas with WebGL, which is hardware accelerated and is much faster than jQuery. I believe (although I can’t find a source for it now), that xterm.js used this strategy.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by mrBurger on Tuesday March 05, 2024 @01:35AM (#39600106)
I dunno, once you write the renderer, you essentially have no limits to worry about.

Working within the confines of HTML is way more impressive to me.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by moffkalast on Tuesday March 05, 2024 @05:18PM (#39609872)
That would be pretty slow, but with WebGL it could work.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by tambourine_man on Monday March 04, 2024 @09:56PM (#39598958)
You can easily shoot yourself in the foot with jQuery (or direct DOM manipulation for that matter), but it's not that hard not to. It just requires some discipline, like most things. React is also far from foolproof and not worth the added complexity in most cases, IMO.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by smaudet on Monday March 04, 2024 @11:49PM (#39599566)
Convention over Configuration.

That and types. The only framework that's useful to JS is a better static type check system (and none of this lets-make-the-whole-damn-runtime-slow to support X feature, looking at you TypeScript).

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by solumunus on Tuesday March 05, 2024 @12:59AM (#39599931)
Curious which TS features you’re referring to?
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by horacemorace on Tuesday March 05, 2024 @01:12AM (#39599990)
The level of easy facilitated in part by ts on synchronous is too damn high, for one.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Dylan16807 on Tuesday March 05, 2024 @01:25AM (#39600049)
> and none of this lets-make-the-whole-damn-runtime-slow to support X feature, looking at you TypeScript

TypeScript runtime? I don't think the deprecated code that sets up enum objects affects anything else...

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by codethief on Tuesday March 05, 2024 @04:06AM (#39601021)
> I don't think the deprecated code that sets up enum objects affects anything else...

TypeScript enums are deprecated now? I mean, yeah, they aren't great and should best be avoided but the deprecation would be news to me.

See also https://stackoverflow.com/questions/70661260/are-typescript-...

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Dylan16807 on Tuesday March 05, 2024 @05:08AM (#39601439)
I accidentally exaggerated because it's an easy word for a legacy feature you're supposed to avoid.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by codethief on Tuesday March 05, 2024 @04:34PM (#39609418)
Thanks for clarifying!
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by smaudet on Tuesday March 05, 2024 @02:00AM (#39600221)
Not enums. But you don't need a runtime or function mutation for that...

Particularly egregious was (is?) async/await. Upgrade your browser/runtime/don't use it you say? Sure, but first two weren't always possible, and the third isn't possible unless you thoroughly vet your dependencies (easier said than done).

"Compiling to javascript" is all well and good if you actually just compile to normal javascript, as soon as you have any code that simulates other features (classes/objects/what-have-you) you are no longer "compiling to javascript". I mean yeah sure as a sort of intermediary assembly language you are but the performance is not the same. You have a new language with a runtime overhead, that now requires you modify the "core" language to bring in new features, which results in the underlying execution engines (browsers/cpus) becoming more complicated, power hungry, etc....

Anyways, type caching is not all bad. While the TS overhead is likely responsible for the performance wins for javascript in the following chart: https://programming-language-benchmarks.vercel.app/typescrip...

The performance wins for typescript likely source from the ability of the runtime to pre-allocate and avoid type checking.

Providing the type checks without using any non-JS features (and possibly providing the runtime some heads up regarding checks to safely drop) is the ideal.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Dylan16807 on Tuesday March 05, 2024 @02:23AM (#39600345)
You can disable those fallback implementations if you don't want to use them. Just use the javascript version you have available as the basis for your typescript. The option to look into the future shouldn't be treated as a negative.

And I still don't see how they make "the whole damn runtime" slow. You don't pay the cost for code that isn't using it.

Also I'm pretty sure the class implementation doesn't slow things down. It's a very simple transformation.

> You have a new language with a runtime overhead, that now requires you modify the "core" language to bring in new features, which results in the underlying execution engines (browsers/cpus) becoming more complicated, power hungry, etc....

I think you have this backwards. Typescript doesn't implement new Javascript features until their addition to Javascript itself is imminent.

The only feature Typescript wants to push onto Javascript is a syntax for type annotations, because then you can remove the compilation step entirely. At which point there couldn't even be a runtime overhead.

> non-JS features

To first approximation, there aren't any. The main one is the old enum syntax, which is why I brought them up.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by smaudet on Tuesday March 05, 2024 @02:57PM (#39608443)
> Typescript doesn't implement new Javascript features until their addition to Javascript itself is imminent.

I guess we want different things from Type systems.

I want rock solid guarantees that code is correct, so that the only thing left to test as much as possible is the business logic. I don't care about the latest programming fads, and I want stable, performant code.

You seem to just want some boilerplate guarantees and backwards compatibility.

If I were writing/creating TypeScript, I would be not implementing new features before JS upgrades, but long after (possibly as support libraries). I understand the goal of "easing" the transition, but IMO those sorts of "upgrades" should be late, not early, in a tool whose primary goal is static type checking, not JS features.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by chfalck on Thursday March 07, 2024 @01:17AM (#39625607)
The things you seem to be worried about are configurable in the tsconfig. You can stay as polyfill free as you would like by instructing the Typescript compiler to error out instead of making the glue for you. Aside from the inescapable quirks of runtime JavaScript, Typescript felt pretty intuitive to me when transitioning to a new job from C# previously. Typescript with ESLint is about as solid as you’re going to get with JavaScript. I know that ideally there’d be something better, but in the real world right now this is the best it gets. At some point reality and business constraints are going to slam into ideations and things are going to get a bit dirty.

Aside from that, no matter what you pick, standard Typescript configs are absolutely compiling to JavaScript, not any other step in the interpreting process. It doesn’t matter if it’s taking your async/await and polyfilling it to run on an older browser engine… it’s still producing 100% JavaScript.

It goes Typescript -> JavaScript during the build, and the JS is what gets distributed to clients.

The JavaScript produced by TS is sent to the browser which performs the same JavaScript -> abstract syntax tree -> byte code -> execution, as usual

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by smaudet on Tuesday March 12, 2024 @04:02PM (#39684240)
"standard Typescript configs are absolutely compiling to JavaScript"

You are missing the point. I want zero cost abstractions (for some level of abstraction - I accept e.g. there is a CPU and a browser). I don't care what it is compiling to.

Typescript is not a zero cost abstraction. (Zero cost meaning, here, that any overhead is incurred compile time only).

"The things you seem to be worried about are configurable in the tsconfig"

That's terrible. I want the Z.C.A. to be by-default, not "configure the heck out of the language to make it so".

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by Dylan16807 on Friday March 15, 2024 @09:23PM (#39722472)
> That's terrible. I want the Z.C.A. to be by-default, not "configure the heck out of the language to make it so".

Don't you just set target? Is there even a default for target?

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by devjab on Tuesday March 05, 2024 @02:14AM (#39600295)
We use a lot of typescript with a very opinionated setup on coding style and conventions, but that only goes so far when you’re dealing directly with the dom.

Because the dom is notoriously hard to work with. The internet is full of blog posts and articles talking about how slow it is as an example, but in reality adding or removing a dom node is swapping a pointers which is extremely fast. What is slow is things like “layout”. When Javascript changes something and hands control back to the browser it invokes its CSS recalc, layout, repaint and finally recomposition algorithms to redraw the screen. The layout algorithm is quite complex and it's synchronous, which makes it stupidly easy to make thing slow.

This is why the virtual dom of react “won”. Not because you can’t fuck up with it, but because it’s much harder to do so.

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by codethief on Tuesday March 05, 2024 @04:01AM (#39600986)
> When Javascript changes something and hands control back to the browser it invokes its CSS recalc, layout, repaint and finally recomposition algorithms to redraw the screen. The layout algorithm is quite complex and it's synchronous, which makes it stupidly easy to make thing slow.

Wait, you're saying it's synchronous but what exactly is being blocked here (since you also said the JS hands back control to the browser first)?

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by pjc50 on Tuesday March 05, 2024 @04:25AM (#39601138)
Re-layout has to complete before any more JS runs. So if you want to change two things, you get update-layout-update-layout.
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by wizzwizz4 on Tuesday March 05, 2024 @08:17AM (#39602933)
Only if you yield to the layout engine (e.g. `await new Promise(resolve => setTimeout(resolve, 0))`) in between. Which, if you know you want to change two things, why would you?
Re:Show HN: 3 years and 1M users later, I just open-sourced ... by pjc50 on Tuesday March 05, 2024 @10:49AM (#39604973)
.. or you accidentally request a layout property: https://gist.github.com/paulirish/5d52fb081b3570c81e3a?ref=a...

(updating innerText sounds like an especially lethal trap https://source.chromium.org/chromium/chromium/src/+/main:thi... )

Re:Show HN: 3 years and 1M users later, I just open-sourced ... by devjab on Tuesday March 05, 2024 @09:03AM (#39603544)
I’m not quite sure what it is that you’re asking. When you want to show something in a browser, you go through this process: JavaScript -> style -> layout -> paint -> composite.

The browser will construct a render tree and then calculate the layout position of each element/node in a process where it’s extremely easy to run into performance issues. And since the rest of the render pipeline waits for this to conclude, it’ll lead to very poor performance. You can look into layout trashing if you’re curious.

My point is more along the lines of how you can ask a lot of frontend engineers what the render pipeline is and how it works and many won’t be able to answer. Which isn’t a huge issue, because almost everyone who does complicated frontends either use a virtual dom or exclusive hire people who do know. But for the most part, you won’t be fine with just JavaScript for massive UI projects as the person I was replying to suggested.