Home

Awesome

Let's fix JS

JavaScript is everywhere. JavaScript got better during the last years, but some things are still inconvenient.

Update January 2020

Abondoned: I think WebAssembly will gain traction and JavaScript usage will decrease. That's why I think it does not make sense any more to fix fundamental flaws in JavaScript.

The rest of this text is left for the curious reader.

For other things which I think need an agreement/spec/ see Missing Internet Specs

Long term goal: fix the flaws.

Goal: fix the flaws by influencing future specification.

Before fixing the flaws consensus is needed.

How to make the transition?

The transition to the cleaned up version could be done to improve the strict mode

Current step: Write down the flaws

Before consensus can be reached, the flaws need to be written down.

Later

Contributing to ECMAScript

What is a flaw?

Everything which can be done simpler or more obivious is a flaw.

If unsure, the Zen of Python is a good general guideline.

Of course there is no single truth. Agreement need to be found by discussing and maybe voting.

Just for fun I keep a list of synomys for "flaw" which I saw while discussing how to fix JS:

But let's focus on the way we want it to be.

Feedback needed

Please tell me what you think:

Let's influence the future together :-)

Don't wait for others or projects like TypeScript to fix this. There are fundamental issues, which can't be solved in TypeScript, Polyfill, Shim, WebAssembly, ...

Please create a new issue and tell us how you would like JS to look like in the future: https://github.com/guettli/lets-fix-js/issues/new

Flaws

JavaScript Equality

"Equality is one of the most initially confusing aspects of JavaScript." Source: http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html

If it is confusing, then it is not obvious. This is a flaw.

Check if a dictionary is empty

It is way to complicated to check if a dictionary is empty:

Object.keys(obj).length === 0;

Above solution is from How do I test for an empty JavaScript object?

JavaScript: Support for BigInts

https://stackoverflow.com/questions/48802728/how-to-marshal-json-with-bigints

Works in Python

import json
>>> json.dumps(json.loads('{"NETWORK_ID": 6000370005980500000071}'))
'{"NETWORK_ID": 6000370005980500000071}'

JSON: binary data type

There thousand ways to work around it. Very common is base64 encoding. But that's a useless work-around.

In Python you can create binary data with the "b" prefix. Example:

binary_data = b'\x00\xff....'

JSON: No Datetime data type

It would be nice to support it.

Other tools which support this:

JSON: Timedelta

A timedelta datatype would be very nice.

Other tools which support this:

JSON: Comments

Quoting @asb:

Leave comments is essential for human beings understand what is going up. Is the best practice in any programming language. Is kind and nice for all who will study what is done. Every one knows that JSON was, -was- a encapsuled internal way to exchange data in javascript but now JSON is used do describe the data for all world. So, please make // into comments for JSON, let the spice flow.

Why HCL (HashiCorp Configuration Language) was invented:

JSON ... is fairly verbose and most importantly doesn't support comments.

Source: https://github.com/hashicorp/hcl

Thanks