
Let’s Replace JavaScript with Something Better - wheresvic1
https://john.ankarstrom.se/english/texts/replacing-javascript/
======
wvenable
> JavaScript always was a bad idea, for the simple fact that automatically
> executing untrusted code from untrusted and unknown sources is a bad idea.

The premise here is completely wrong. A modern web browser is a sandboxed
application delivery platform. The entire purpose is to execute untrusted code
and it does so remarkably well. Take this away and you just have a document
viewer -- a sophisticated one for sure -- but one always limited to its
original purpose.

This proposed solution would eliminate many of the applications that web users
use every single day and many more that haven't even been invented yet. HTML5
games would be impossible. Forget Google Maps. It's not even worth
entertaining.

> In the company of the two declarative languages HTML and CSS, the
> imperative, all-purpose JavaScript always seemed the odd one out.

Declarative languages are extremely limiting and the trend has been to move
away from them. For example, the introduction of Service Workers to replace
manifest files.

Much of the success of the web has been in defiance of the declarative nature
of the formats rather than in support of them. We're building complex
applications in a declarative format designed for documents and that's only
possible because we can imperatively manipulate those documents with code.

~~~
bassman9000
_This proposed solution would eliminate many of the applications that web
users use every single day and many more that haven 't even been invented
yet._

No big deal. When Apple introduced the App store, a maybe-not-new-but-finally-
practical way of shipping applications to end-user devices was born. And they
weren't webapps. No JS at first, mostly Objective-C and plists. And was still
revolutionary in its reach, and consequences. Then Android came. Still no JS,
but XML and Java.

So, no, you don't need HTML+JS to deliver rich content application to users.

~~~
wvenable
You need HTML+JS if you want to deliver one single application to iOS,
Android, MacOS, Android, Linux, BSD, Solaris, Chrome OS, Tizen, and OSes that
don't even exist yet and not be held to a single proprietary platform owned
and managed by a single entity.

You could argue that it's not necessary but that's what it is.

The site you're posting to now probably wouldn't even exist if it required
installing a different proprietary application for every platform.

~~~
bassman9000
_You could argue that it 's not necessary but that's what it is._

Yeah, that's the whole point I'm trying to make. That it's not necessary. That
JS it no more special than any other language, and that there are recent,
real, practical examples of absolute disruption (Apple/Android app stores)
which broke what we thought it was required to deliver content to users.

As per the _one single application_ , that's a gross oversimplification.

~~~
wvenable
Nobody said JS is special but the point of the article is that code execution
(of any kind) is unnecessary.

The ironic part is that app store you're arguing for wouldn't even exist
without the web. The web is what made Mac OS X viable for users to switch to
it (and MS Office). The platform network affects that made Windows a monopoly
have been drastically cut down by the web.

> As per the one single application, that's a gross oversimplification.

Says another person posting on a web application that runs on every platform
out there.

------
dickbasedregex
Every 2-3 years this gets suggested again. Somebody builds something to
"compile" their pet language x to JS. At the same time 3 new JS libraries or
frameworks come out to abstract an abstraction. I've been writing JS since '94
and I'm sorry but at this point all I can muster is an eye roll.

~~~
Waterluvian
It has also grown unbelievably well. ES6 alone has added in so many quality of
life features that I find myself using fewer and fewer libraries every time I
go to do a project and check compatibility.

I just need full module support and I'll be laughing.

~~~
dickbasedregex
Maybe I'm just crotchety now and/or beyond front-end fatigue but I keep
thinking, "you don't need all that!"

------
ggregoire
I prefer JavaScript to all the other languages I've learned/worked with (C#,
Java, PHP, Python, Lisp, etc).

So thanks but no thanks.

~~~
peterashford
So, if you are one of the people who _doesn 't_ like JS, then... what? Screw
you?

~~~
ggregoire
We're not gonna "kill JavaScript" (quoting the article) just cause some people
don't like the language.

~~~
peterashford
I don't think it's a matter of killing JS - that would be rediculous. I don't
think it's unreasonable that people should be able to choose the right tools
for the job and it's not ok for JS fans to just say that JS is always the
right tool

------
Archanian
> Above all, what’s dangerous about JavaScript is that it is executed without
> the user’s knowledge or consent.

Ummm ... is this not how all software works? Is the average person 'aware' of
the code that is executing as he/she clicks around in any piece of software?
How is a web browser any different?

~~~
dplgk
Agreed. When a user opens Microsoft Word, billions of lines of code are
executed without supposed consent.

~~~
krapp
Not to mention when your operating system likely updates itself, when you
import new dependencies from a repo, when any software is updated to a new
version by any means other than the user recompiling from source, etc.

It happens all the time but for some reason, it's more evil when it's
javascript.

------
mirkodrummer
“JavaScript is also weird because it is imperative, forcing the programmer to
describe the means in which to achieve the desired result, instead of
declaratively describing the desired result itself, like in HTML and CSS.”

It actually has First Class Functions that enables declarative programming,
there’s a lot of cool libraries out there(ramda as an example) that let you
express your apps in declarative way. Not saying that is a Pure functional
language nor that was born as a functional language, it is indeed a general
purpose language enabling more styles of programming with a plenty of good and
bad ideas. However it gets better as it is continuosly improved by a lot of
smart guys. Btw as I can see it, the main point or your article is not about
javascript but about browser APIs

------
fenwick67
> Let’s Replace JavaScript

The entire article is about changing various browser APIs, not Javascript
itself

~~~
pdonis
It's about adding browser APIs _in order to replace Javascript in the most
common use cases_.

------
johnhenry
Wasn't this Google's premise when they released Dart?

~~~
forgot-my-pw
Also CoffeeScript and TypeScript

~~~
johnhenry
Well, CoffeeScript and TypeScript are different in that they simply compile
into Javascript, but Google initially intended dart to be available directly
within web-pages. More on the reversal of that decision here:
[https://news.ycombinator.com/item?id=9264531](https://news.ycombinator.com/item?id=9264531)

------
peterashford
My view is that instead of running JS, browsers should run a standard bytecode
with a well-defined and safe interface to the browser and managed access to
the user's machine. The article covers some of these concerns. I really think
a byte code is the way to go, just so people can use whatever language they
prefer. It is ridiculous that if I want to solve a problem on my computer I
can use whatever language I like but if I want to write something on a browser
- one of the most important IT systems in the world - I only have one choice.

~~~
electric_sheep
What's your favored language? Because odds are good that it can compile to JS:
[https://github.com/jashkenas/coffeescript/wiki/list-of-
langu...](https://github.com/jashkenas/coffeescript/wiki/list-of-languages-
that-compile-to-js)

------
mrskitch
My sentiment here is that modern JavaScript is _much_ better than its
predecessors. The real issue, as it pertains to the web browser, is supporting
legacy functionality that's causing drag on the web as a whole.

I'm curious: what's so bad about JavaScript that other languages seem to do
better?

~~~
ben-schaaf
It still doesn't have integers.

~~~
cuspycode
Agreed. The fact that JavaScript lacks reasonable numeric types means that I
never use it except when there is no alternative.

------
43920
This article has some interesting ideas, and it's definitely true that the web
has a lot of problems, but I'm not sure how much of it is actually related to
the underlying technology. Sites that use a lot of javascript tend to fall
into one of two categories: * News sites with a billion ads and tracking
scripts. * Actual web apps (Google Docs, Gmail, etc).

For the first category of websites, it's basically an economic problem - sites
are including all this junk because it makes money. If this proposal were
implemented, most sites would just find ways to work around it - and if you
can send network requests in response to events, it's always going to be
possible to track users. You could easily just send a network request every
time something on the page is clicked, hovered over, etc. and doing that would
likely be even less efficient than what we have today. The article mentions
alerting people when a network request is made, but if you had to click a
button every time a site wanted to make a network request, it would be so
annoying that most people would just give up and go back to the old web.
Ultimately, the only way to stop tracking is to somehow fix the economic model
so that there's no incentive to do it, although it's not entirely clear how
that would happen.

For the second category of things that are real apps, this system is probably
not going to work in most cases. There's a practically infinite number of
actions that a real app would need to do, and if you implement an API for
every single one, you'd end up with something that's really similar to what we
have today. Most likely, you would just go back to downloading and installing
native apps, which provides even less security protections than a web browser
does (and it also makes it much harder to distribute your apps, which is the
whole reason the web won in the first place).

Rather than getting rid of javascript completely, I think there's a few things
that we could do that would solve a lot of the problems present today: *
Create a way for sites to easily accept micropayments so that there's an
alternative to ads. Brave seems to be the only company attempting this right
now; it will be interesting to see whether they succeed or not. * Have your
web browser notify you if a site is using too many resources. Firefox already
kind of has this with the "x is slowing down your browser" notification,
something like "x has used 100MB of data. Stop loading?" would work really
well. * Enable first-party isolation by default, which would do a lot to
reduce cross-site tracking.

------
krapp
The article seems to suggest that javascript should be replaced by extensions
to HTML and CSS, making both more or less Turing complete.

However, I don't think it sufficiently defends the premise of being
objectively superior to javascript, given that all of the features mentioned
_could be implemented in javascript._ There is nothing fundamental to the
language which prevents designers from being proactive about consent in the
way described.

I feel like the author blames the language for what are, essentially, design
paradigms with which he disagrees, and I think a lot of people who criticize
javascript do the same thing. We don't need to replace javascript to
accomplish what the article describes, we just need to write javascript more
ethically.

------
mykull
Webassembly is the better thing we will replace JS with as a target language
for browsers.

~~~
vdnkh
JS will stick around because it is easier to write. WASM will be for heavy
lifting, not for making a modal pop up.

~~~
KyleGalvin
WASM will pave the way for other 'easier to write' languages to occupy the
same space as JS. Rust is pushing heavy for native browser support and will
likely be an early adopter in this space. It's only a matter of time until
<your language of choice> will support compiling to WASM and run in the
browser

~~~
krapp
The problem with that is, no one is going to be writing raw WASM code - it's
going to be compiled from another language, which means requiring a compiler
toolchain to replace an interpreted scripting language that only really
requires a text editor.

For sites which are already using the paradigm of "compiling to javascript"
that might not be an issue, but that doesn't cover all the use cases for
Javascript.

Other languages can't really occupy that same space until it's possible to,
say, embed Lua or Rust source in script tags and just have it work as easily
as Javascript does, and have the browser handle compilation and execution
entirely.

~~~
KyleGalvin
That's an interesting thought. I didn't mean to suggest anyone code in WASM,
but I think I see what you mean.

I have experience embedding lua applications within mobile apps, and it
required a fair deal of wiring in C to marshal between java and lua (android)
or swift and lua (ios).

To do the same in WASM sounds rather undesirable.

Edit: to finish my thought, I dont see the problem with using a compiler
toolchain to create web applications. Can you elaborate on why that isn't a
good thing?

~~~
krapp
>Can you elaborate on why that isn't a good thing?

It's not a bad thing per se, but it's added complexity without any obvious
benefit if that code is still doing what javascript already does, just as a
binary blob, especially for simple uses like glue code around jQuery or the
sort of JS running on Hacker News.

------
alexandernst
Whoever wrote this pile of crap hasn’t used a SPA and doesn’t understand what
actually JS is used for nowadays.

------
ben-schaaf
As much as I disagree with getting rid of imperative languages on the web,
that CSS Prolog idea is amazing. Styling is exactly the kind of niche I can
see it succeeding in. Though I would be a little worried about my CSS looping
infinitely...

------
nostalgeek
JS clearly has issues and I wish some of these issues could have been
alleviated when ECMA introduced "use strict". It was a one time opportunity to
correct the language at its core, AKA remove a bunch of features and behavior.

~~~
Waterluvian
Not one time. They also considered "use strong" but declined. I don't recall
why. But you can always do it again and make further subsets of the language
that clean up for modern use with modern support.

But I also question the purpose. Just use dev tools to help enforce more
strict code.

------
ausjke
My only issue with javascript ecosystem, i.e. nodejs, is that when I 'npm
install', all of sudden I get hundreds of modules pulled in with a few hundred
MB of content, which I feel bloated and who-knows-what-just-pulled-in.

A glibc-style standard binary library might be better to maintain and for
production use. Making the 'standard library' modularized so I can customize
will be even better.

------
andybak
Nice to see Intercooler getting some recognition. I haven't done much front
end stuff for a while but I always intended to do a deep dive into it.

------
dcwca
“In light of the Meltdown and Spectre bugs”, allow me to pivot the
conversation to something completely unrelated.

~~~
bradym
Yeah, that's where I stopped reading...

------
optimalKEK
It seems to me that you are criticizing JS as it were in 2005. There are well
known -low overhead- solutions to all the 'problems' you identified.

~~~
darepublic
Despite being a js fan i don't think this criticism of the article is true.
The critique applies equally to today as 2005 no? It seems that the article
wants a language whose capabilities vs js are heavily neutered

------
artursapek
lol

------
lcnmrn
I will love Python to replace JavaScript and Sass to replace CSS, but it will
never happen.

~~~
jack_jennings
WASM will mean compiling Python will be possible, and most of the useful Sass
features are supported in CSS now?

