Hacker News new | past | comments | ask | show | jobs | submit login

Hello everybody, author here. I hope you enjoy my tiny project.

Regarding language, I chose Javascript for three reasons:

- the (ab)use of `eval` lets you do all sorts of sorcery, like instant evaluation

- the JS Redux library makes it easy to work with state, and I couldn't have implemented SCRIPT-8's time-traveling debugger without it

- I dream in Javascript

I love Lua's small footprint, and very early on I considered writing SCRIPT-8 in MoonScript, which compiles to Lua and has gorgeous syntax. Maybe some day.

And yes, my fantasy computer is definitely not the only open source project, there's several out there, and probably all of them are more stable than mine. Go check them out.




Thanks to the pointer to Bret Victor's video on Inventing on Principle. Nice to see you brought some of his concepts into SCRIPT-8.


> very early on I considered writing SCRIPT-8 in MoonScript, which compiles to Lua and has gorgeous syntax. Maybe some day.

I know it's no longer considered hip these days, but why not support CoffeeScript?

It's easy to compile to JS on the client-side, so support should be much simpler than Lua or MoonScript. You could steal the trick TIC-80 uses to support MoonScript and say that starting a cassette with the string "use CoffeeScript" marks it as a CS file. Then it's "just" a matter of an if(String.startsWith("use CoffeeScript\n"))-check followed by an intermediate string-to-string compilation step, right?

https://coffeescript.org/


Coffee Script is hell.

Apart from https://github.com/usefulthink/coffeescript-from-hell/blob/m..., it takes the worst approach to spaces as syntax, because it doesn't enforce consistency, so with many devs you can end up with a file with two, four spaces, tabs all compiling but easily breaking. It has features their own syntax checker recommend not using, like defining objects without curly braces (which I think shouldn't even be a feature, but it was once so backwards compatibility)

Coffee Script tries to be beautiful without straying too far from Javascript and it ends up being an easily broken mess. I would then recommend either typescript or purescript.


Honest question: pointing out programming design warts that allow for WAT-level code[0] is perfectly valid, and I obviously prefer elegantly designed languages. Having said that, how realistic are the odds of being bitten by these issues when using CoffeeScript?

Also, if our point of comparison is Lua and MoonScript, how do those compare?

EDIT: regarding TypeScript and PureScript, can those be compiled in the browser? By which I mean, I'm sure they can technically but do not-too-heavy implementations of such exist?

[0] https://www.destroyallsoftware.com/talks/wat


> how realistic are the odds of being bitten by these issues when using CoffeeScript?

In my experience, minimal if you know the language well and can work around its quirks. Having said that, I prefer working with a language that doesn't require much time to tame and let me do concrete work, at the same time holding my hand when necessary (because of time schedule and pressure and so on). This is less of an issue with private projects, but still there are no downsides in learning a tool that is great for both lone and team work, so there is no real benefit in using coffeescript when there are much more solid languages that compiles to Javascript out there. Hell even heard you can change Glasgow backend compiler to make haskell output Javascript haha

I can't answer about lua and moonscript, I'm completely unfamiliar with them.

About typescript and purescript being compiled in browser, I have never even looked into such approach, they feel unrealistic, because from the top of my head it would require a compilation tool written in JS, which is not particularly efficient for this kind of task that benefits from parallelization, specially if you are not doing deep checks, just translating code. Then there is the matter of what to do with the resulting code. Can we dump it into a file and load it programatticaly? I would be surprised if we could. Eval() the output? Not without some serious security checks that would further compromise performance.

So I believe there is no motivation in not pre-compiling and distributing the result dist code


> About typescript and purescript being compiled in browser, I have never even looked into such approach, they feel unrealistic, because from the top of my head it would require a compilation tool written in JS

Eh, not really: you could write the compiler in any language that compiles to JS, then use the compiled output as your compiler. In the case of TypeScript or PureScript you could basically write a self-hosting compiler this way.

Walt is a compiles-to-WASM language that has partialy done so[0]. Its compiler written in JavaScript, and the generated compiler is also JavaScript. While not self-hosting, the guy developing it has rewritten parts of it in WASM to figure out what the best language design for strings and related JavaScript interop would be.

> which is not particularly efficient for this kind of task that benefits from parallelization

First of all, isn't WebPack written in JavaScript? Seems to do just fine.

Also, if we are talking about a somewhat modern browser that supports Web Workers parallelization is perfectly viable, no? Add Web Assembly and TextEncoder/TextDecoder in the mix and things could get even faster[1][2][3].

(The main performance issue I see is that due to SharedArrayBuffers being disabled (for now), each worker would need its own Uint8Array copy of the source input[4])

> Can we dump it into a file and load it programatticaly? I would be surprised if we could.

Saving a file is easy these days, just use a Blob[5].

> Eval() the output? Not without some serious security checks that would further compromise performance.

Creating Function object works. It just requires a string as input. I also don't see why this would be more insecure than compiling the same source string ahead of time - you end up running the same code. This isn't the typical user-context in which eval is dangerous.

> So I believe there is no motivation in not pre-compiling and distributing the result dist code.

You are arguing this from a technical point of view, which misses the entire point. Namely, that client-side compilation allows for browser-based apps, demos, and sharing. It greatly lowers the threshold to trying things out.

You may dislike CoffeeScript, but being able to try it out in the browser is quite a good sales pitch[6].

For a more ambitious example: Observable is a notebook environment similar to IPython, but for JavaScript, and with one of IPython's biggest quirks removed: cells track dependencies on other cells and re-evaluate as necessary[7]. The server is there for cloud storage and remote collaboration, allowing you to instantly share the notebook. However, I think it does most, if not all of its compilation client-side, since it still works when you are temporarily off-line (also, Jeremy Ashkenas is part of the developer team).

The aforementioned compiler for Walt can easily run in the browser, so last year I tried combining the two. It took me only a couple of hours to get it working[8].

Of course, you lose the benefit of a developer environment made for the language (but IIRC supporting compiles-to-JS languages is on the long-term Observable roadmap), but still: being able to quickly try out some simple WASM code without needing anything except a modern browser is quite powerful.

[0] https://github.com/ballercat/walt

[1] https://dzone.com/articles/webassembly-web-workers

[2] https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder

[3] https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder

[4] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[5] https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob

[6] https://coffeescript.org/#overview

[7] https://beta.observablehq.com/

[8] https://beta.observablehq.com/@jobleonard/compiling-walt-in-...


I wish more people used CoffeeScript and supported it. The syntax makes me so happy


Do cassettes have a size limit? AFAIK all (most?) the other fantasy consoles do but I didn't see anything on your page.

A lot of the cool features others mentioned seem like they would be overkill on a small codebase.


They don't now, but that is coming. The "SHOW CASSETTE SIZE" button under the live-preview screen shows you the current size / compressed size. But it doesn't prevent you from making a huge cassette - not yet.


This looks fun! Would be great to have something that catches runtime errors and highlights them in the source code. Then, of course, code completion etc to make it easy to find stuff.

I started working on a bit similar project some years ago (I unfortunately abandonded it...) but I got one thing right: the ability to highlight the erroneous line. See http://write-a-game.herokuapp.com/ and try to call a non-existent function.


Here's the stack trace parser used. It tries to extract the line number and error message from an Error object. Sorry for the coffeescript!

https://github.com/raimohanska/write-a-game/blob/8d2111e2372...


Good idea. This would be useful for sure.


This is amazing! I'll be letting my kids play with it tomorrow!

And JS is a great choice.


Very creative project! Did you experience any issues doing pseudo-low-level programming with Javascript's lack of typing system or definite integer/float data-types?


Thank you, and no issues, because I didn't implement any low-level programming. I use React/Redux and Canvas 2D, with some custom shape drawing to avoid antialiasing (e.g. Bresenham's algorithm).


"I love Lua's small footprint, and very early on I considered writing SCRIPT-8 in MoonScript, which compiles to Lua"

Something similar, in Lua: https://liko-12.github.io/


Glad to find another moonscript fan!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: