Brand new Syntax

Here is an idea I've been thinking about for the past month-ish and I'd like to make the case for JS, a Language mind you that is tangled with a mess of a syntax. I think a lot of can agree that using prototype.array.toUpper() or whatnot is a handful. So I'd like to propose we take a look at what I would argue to be a better use of syntax. That being Python that through countless years has been touted as the most (or one of) the most beloved languages out there. instead of using dot notation to get it done, lets use simple use spaces.

So for example instead of using:

if(a === b){
// do whatever here //

we can do:

if a equals b:
push b into array1

or whatnot. I think this looks much more concise and readable. For those who are claiming that this is a rudimentary example and not good enough of a reason to implement a brand new syntax. ok then, very well.

Consider my next example: (I'm using sveltejs btw)

function plusOne() {
cart.update(c => {
c.find(item => === id).amount++
return c;

With this, I think we could drastically reduce the markup to something like

function plusOne:
update cart and find(item) amount++
return item

Which one looks better? Which one looks more easily readable, and can easily be deciphered. I'd argue the one with spaces in it and not the dot notion and the arrow function that we currently have.

You might be interested in coffeescript syntax, which largely takes us that direction. Overall, I believe a degree of symbols is important, otherwise, you'll just end up with a word soup that's difficult to scan. There's a reason people don't write math problems in essay format, and there's similar reasons why people doesn't write code in essays. Symbols can help improve scanability. Though, syntax highlighting helps prevent word soupiness in languagesl like python, because important operators stand out with special colors. Overall, I do agree that the syntax of python does look much nicer.

In general, the JavaScript language itself won't ever be able to change its syntax like this, because it never does a breaking change. You'd effectively have to ask browsers to support a second language instead, that's just like JavaScript, but has a different syntax. In other words, you'd have to ask browsers to support something like CoffeeScript natively. This is unlikely to happen - a fresh coat of paint is probably not a strong enough reason to add support for a second language. It's not even a good enough reason for CoffeeScript to hold onto its fanbase - that language has started dying out ever since JavaScript implemented most of the unique features it offered, which is why it's mostly just an alternative syntax now.

1 Like

The C-style syntax is there because it's easier to parse, less ambiguous and easily distinguishable.
Every language has a unique syntax; Python has it's own distinct style, so do Rust, Haskell, Ruby, JS and many others. Just because you like the syntax of one doesn't mean it should be the norm for every other. JS is what it is and it should be; changing things all of a sudden could cause all sorts of headaches and is just not worth it; (it's effectively like asking for a whole new language) instead appreciate what we have😀

--- confession ---
I personally wanted JS to support a Go/Rust like syntax; with less parentheses:

if x < 5 {
    // do smt

for let x of arr {
    // do smt

But ya I'm happy with what it is ;)

1 Like

not to mention any coffee/python like syntax would break existing minifiers. there are notable projects still using es5 syntax, partly because the older syntax can be more aggressively minified.