Live data from Hacker News

Should JavaScript be split into two languages?

devclass.com

81–90 of 324 posts

Re: Should JavaScript be split into two languages?

#81
post #75
post #69

Earlier quoted context omitted.

What parts are not available? WebAssembly can call arbitrary JavaScript through imports. You could literally provide an `eval` function if you were motivated to.

direct access to the DOM for example without having to go through the javascript host, which is slow and makes DOM intensive applications impractical

Or you can just draw to canvas to make the UI fast which is what Flutter does now:

https://flutterweb-wasm.web.app/

https://www.youtube.com/watch?v=Nkjc9r0WDNo

Re: Should JavaScript be split into two languages?

#82
post #75
post #69

Earlier quoted context omitted.

What parts are not available? WebAssembly can call arbitrary JavaScript through imports. You could literally provide an `eval` function if you were motivated to.

direct access to the DOM for example without having to go through the javascript host, which is slow and makes DOM intensive applications impractical

Can you give an example of anything anywhere that manipulates the DOM without using JavaScript? Because it seems to me that pretty much every web application is currently using the javascript host, and the well written ones are pretty snappy.

Re: Should JavaScript be split into two languages?

#83
post #48

Why JS0 and not wasm? Why is wasm so damn limited?

  Why is wasm so damn limited?
After watching it evolve for many years my conclusion is either politics or it being run by the wrong people who think they literally need to invent the whole world (in component model) before they can give us basic string objects. No, wasm string objects were an independent feature in experimental Chrome for a while but they got removed again. Wasm structs are beautiful without the component model but useless because they can't be read or written in JS.

Re: Should JavaScript be split into two languages?

#84
post #79
post #71

Earlier quoted context omitted.

That part caught my attention too. It reminds me of the discussion to remove complex numbers from Go. Funny enough, compiler writers can't even imagine why you would want BigInt or Complex, because those aren't useful for writing compilers.

one contributor to the pike programming language when asked why he took the effort to optimize syntactic sugar responded: so that pike users can write simple code and still have it run blazingly fast. in pike, bigint and int are integrated in such a way that the transition is automatic. there is no overflow but as long as the values fit in an int, that is used internally to keep the code fast.

I used LPC a long time ago on an LP Mud, so Pike has always had a fond spot in the back of my mind, even if I don't use it now.

However, that works for int and bigint, but Number (double precision) can represent numbers that BigInt can not, and BigInt can represent numbers which Number can not. There isn't a graceful way to automatically promote/degrade one to the other in all cases, and a silent conversion will do the wrong thing in many cases.

Re: Should JavaScript be split into two languages?

#85
post #4

Better to focus on WebAssembly instead. Bring every language to the web. JavaScript for some scripting, any other language for bigger applications.

Yes and no, there is a significant bundle size problem with wasm which is hard to fix. I'd rather we just move to native cross platform applications and stop using a document browser to build interactive applications. What's more likely is that all of this will probably be eclipsed by LLM and virtual assistants - which could be controlled by native apps with a dynamically generated GUI or voice. I think APIs exposing…

> I'd rather we just move to native cross platform applications and stop using a document browser to build interactive applications

Here you go. Do both native and wasm:

https://avaloniaui.net/

https://platform.uno/

https://flutter.dev/

Flutter example:

https://flutterweb-wasm.web.app/

Re: Should JavaScript be split into two languages?

#87
The proposal was submitted here but didn't get much attention. Are there other threads?

Language Evolution: Problems, and What Can We Do About It? - https://news.ycombinator.com/item?id=41795190 - Oct 2024 (1 comment)

Proposal of JavaScript becoming a compiled language: JS0 and JSSugar - https://news.ycombinator.com/item?id=41764825 - Oct 2024 (2 comments)

Re: Should JavaScript be split into two languages?

#88

Earlier quoted context omitted.

They’re already moving it that way, it’s not like it isn’t without complexities and such either. WASM isn’t the silver bullet everyone seems to cling to. I feel like the WASM fervor has more to do with the fact people don’t enjoy using Frontend tools or JavaScript etc. vs looking at the actual utility tradeoffs

>> WASM isn’t the silver bullet everyone seems to cling to. And it isn’t the silver bullet exactly for the reason that it's horribly complicated to access normal JS objects including strings.

You're two library functions away from having it easy:

    Copy from JavaScript to WebAssembly:
        Use TextEncoder to convert a JS String to Uint8Array
        Copy the bytes from the Uint8Array to WemAssembly.Memory

    Copy from WebAssembly to JavaScript:
        Copy the bytes from WebAssembly.Memory into a Uint8Array
        Use TextDecoder to convert from Uint8Array to JS String
JS Strings are pretty much always going to be "rope data structures". Trying to provide anything other than copy-in and copy-out is going to expose implementation details that are complicated as fuck and not portable between browsers.

Re: Should JavaScript be split into two languages?

#89

> Regarding BigInt, the presentation states that “use cases never materialized.” Yet every language has either that or BigDecimal. Even if Google's frontend devs haven't found a use, there also exist JS devs outside of Google who certainly have found uses (though possibly more of them on the backend). Similarly, not every developer has a compilation step in their JS work. And there are places where you can't have one…

Would help if it worked with JSON by default.

Re: Should JavaScript be split into two languages?

#90
post #82
post #75

Earlier quoted context omitted.

direct access to the DOM for example without having to go through the javascript host, which is slow and makes DOM intensive applications impractical

Can you give an example of anything anywhere that manipulates the DOM without using JavaScript? Because it seems to me that pretty much every web application is currently using the javascript host, and the well written ones are pretty snappy.

this is going beyond my level of experience, but i thought there can't be any such example because javascript is the only way. the difference is between code written in javascript which is fast of course and accessing js functions from WASM, which is slower. how much slower, i don't know. i also don't know how old that discussion is where i learned about this. so maybe it improved since. that would be good news.

did you mean there are snappy webapplications running in WASM? if you have any examples, i'd be curiuos to learn more.

Post reply on HN