Introducing GOTOJS: Sequential Programming for JavaScript

With all the Javafication of JavaScript still going around today, I'd like to take the conversation in another direction and humbly introduce GOTOJS.

It's a lightweight, low-level library that:

  • Introduces proper sequential programming based on line numbers, something sorely missing from JavaScript
  • Reduces complexity by eliminating the need for semicolons
  • Works exclusively in global space; no more var statements for your variables (seriously, don't use them or something may break)
  • Simple, direct control of code execution with goto()
  • Powered by eval()

Using GOTOJS

Basically, it's BASIC.

Example

program = {  
    10: "x = 0",
    20: "x = x + 1",
    30: "print(x)",
    40: "if (x < 5) goto(20)",
    50: "print('Done!')",
    60: "end()",

    100: "print('Hello World!')"
};

run();  

Produces:

1  
2  
3  
4  
5  
Done!  

You can also run from a given line number:

run(100);  

Produces:

Hello World!  

Easy!

Commands

  • run(line) start execution of the program at the beginning or line.
  • goto(line) move execution to the line specified.
  • print(string) prints the string to the document.body.
  • tron() turns the tracer on.
  • tron() turns the tracer off.
  • end() stop execution of the program.

Is it brittle? Hell yes, it runs everything in global space. Does it work? Sure. At least as well as BASIC did back in the day.

Want to contribute? I'd love to see GOTOJS form the basis of a complete application framework. I put a repo in GitHub:

http://github.com/davebalmer/gotojs

Why would I do this? To poke a little fun, really. More in Is JavaScript's eval really evil?.

Endorse davebalmer on Coderwall submit to reddit
comments powered by Disqus