Live data from Hacker News

Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

github.com

1–9 of 9 posts

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#3
Interesting. It's worth noting that semicolons are generally optional in javascript, and there's a growing contingency of folks who actively do not use them and rely on their build tools to inject where necessary. Sounds like it would lead to subtle bugs but I guess it works ok.

Anyway, nice work in general! Assuming this only works with 'let' to avoid the weirdness around 'var' scoping?

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#4
post #3

Interesting. It's worth noting that semicolons are generally optional in javascript, and there's a growing contingency of folks who actively do not use them and rely on their build tools to inject where necessary. Sounds like it would lead to subtle bugs but I guess it works ok. Anyway, nice work in general! Assuming this only works with 'let' to avoid the weirdness around 'var' scoping?

Regarding the semicolons, due to the insertion mechanism JavaScript uses, lines starting with '[', '(', or '`' will get merged with the previous statement. So the example in the repo will get parsed in JavaScript as:

    x = 10;
    y = 20[x, y] = [y, x];
Your assumption is correct. NodeScript defaults to let-declarations. This leaves you with a block-scoped language and prevents leakage of global variables. If you want to make a global variable, you will have to explicitly write it as a property of the global object.

Thanks for the kind words. I really appreciate it.

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#5
post #3

Interesting. It's worth noting that semicolons are generally optional in javascript, and there's a growing contingency of folks who actively do not use them and rely on their build tools to inject where necessary. Sounds like it would lead to subtle bugs but I guess it works ok. Anyway, nice work in general! Assuming this only works with 'let' to avoid the weirdness around 'var' scoping?

Regarding semicolons, here's an interesting previous discussion: https://news.ycombinator.com/item?id=3842713

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#6
How does this handle shadowing? Consider, for example,

  let x = 1;
  function foo() { let x = 2; }
  function bar() { x = 3; }
  console.log(x); // 1
  foo();
  console.log(x); // 1
  bar();
  console.log(x); // 3
Without the declaration, how can you tell whether I intend to shadow or not?

Edit: I note from another comment that you state

> If you want to make a global variable, you will have to explicitly write it as a property of the global object.

The example above could appear in any scope, not only the global scope. Python now has a `nonlocal` keyword (as well as the `global` keyword) to disambiguate these cases.

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#7
post #6

How does this handle shadowing? Consider, for example, let x = 1; function foo() { let x = 2; } function bar() { x = 3; } console.log(x); // 1 foo(); console.log(x); // 1 bar(); console.log(x); // 3 Without the declaration, how can you tell whether I intend to shadow or not? Edit: I note from another comment that you state > If you want to make a global variable, you will have to explicitly write it as a property of…

The default behaviour is not to shadow variables. If you want to shadow a variable, you have to do so explicitly with the 'let' keyword.

Here is a NodeScript snippet and its equivalent in Python:

    // NodeScript
    
    x = 10
    function outer() {
        y = 20
    
        function inner() {
            x = 100
            y = 200
        }
    
        inner()
        console.log(x, y)
    }
    
    outer()


    # Python
    
    x = 10
    def outer():
        y = 20
    
        def inner():
            global x
            nonlocal y
    
            x = 100
            y = 200
    
        inner()
        print(x, y)
    
    outer()

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#8
post #3

Interesting. It's worth noting that semicolons are generally optional in javascript, and there's a growing contingency of folks who actively do not use them and rely on their build tools to inject where necessary. Sounds like it would lead to subtle bugs but I guess it works ok. Anyway, nice work in general! Assuming this only works with 'let' to avoid the weirdness around 'var' scoping?

> Sounds like it would lead to subtle bugs but I guess it works ok.

It does lead to subtle bugs. The same kind of people who leave semicolons out of javascript write C but leave out the braces in statements wherever it's allowed - which also leads to subtle bugs.

I guess looking pretty and saving a couple of keystrokes is preferable to being explicit and not having to just trust that the compiler/browser/whatever is able to intuit what you want the code to be as opposed to what you wrote.

Re: Show HN: NodeScript- JavaScript Without the Variable Declarations and Semicolons

#9
post #8
post #3

Interesting. It's worth noting that semicolons are generally optional in javascript, and there's a growing contingency of folks who actively do not use them and rely on their build tools to inject where necessary. Sounds like it would lead to subtle bugs but I guess it works ok. Anyway, nice work in general! Assuming this only works with 'let' to avoid the weirdness around 'var' scoping?

> Sounds like it would lead to subtle bugs but I guess it works ok. It does lead to subtle bugs. The same kind of people who leave semicolons out of javascript write C but leave out the braces in statements wherever it's allowed - which also leads to subtle bugs. I guess looking pretty and saving a couple of keystrokes is preferable to being explicit and not having to just trust that the compiler/browser/whatever is…

> It does lead to subtle bugs.

Have you encountered any bugs so far while testing NodeScript out? I thought I have taken care of all the gotchas when it comes to semicolons.