Translate idiomatic Go into concise Javascript that works in every browser. Use Go's type system and world-class tooling to build large web applications with confidence.

Introduction

Today I’m excited to share the Joy compiler with the developer community. Joy brings Go’s simple design and excellent tooling to the frontend. I believe Joy will become the most productive way to build large-scale, maintainable web applications. I hope you’ll find Joy delightful as I do.

What is Joy?

What does Joy look like?

The following examples were selected from the test suite and should give you a taste of Joy's capabilities. For more examples, you'll want to check out the full test suite on GitHub.

Use the following dropdown to check out the examples. The Go code is on the left and the compiled Javascript code is on the right.

package main

func main() {
  println("hi world!")
}
package main

func main() {
  a := "a"
  b, c, d := "b", "c", "d"

  var e = 3

  f, g := func() (string, string) {
    return "f", "g"
  }()

  var (
    h = "h"
    i = "i"
    j, k = "j", "k"
  )

  println(a, b, c, d, e, f, g, h, i, j, k)
}
package main

// User struct
type User struct {
  Name string
  Phone Phone
}

// Phone struct
type Phone struct {
  Type string
  Number string
  Main bool
}

func main() {
  user := User{
    Name: "Matt",
    Phone: Phone{
      Number: "1234511",
      Main: false,
    },
  }

  println(user.Phone.Number)
  user.Phone.Type = "CELL"
}
package main

// User struct
type User struct {
  FirstName string
  LastName string
  Age int
  Phone Phone
}

// Phone struct
type Phone struct {
  Type string
  Number string
}

func main() {
  user := User{FirstName: "Tobi"}
  println(user.FirstName)
  println(user.LastName)
  println(user.Age)
  println(user.Phone.Type)
  println(user.Phone.Number)
}
package main

func main() {
  names := map[string]string{
    "a": "a",
    "b": "b",
  }

  nested := map[string]map[string]string{
    "a": map[string]string{
      "a": "a",
    },
    "b": map[string]string{
      "b": "b",
    },
  }

  println(names["a"])
  println(nested["b"]["b"])
}
package main

import "github.com/matthewmueller/joy/macro"

func main() {
  x := 15
  macro.Raw("x += 5")
  println(x)
}
package main

// Node struct
type Node struct {
  NodeName string
}

func main() {
  var nodes []Node

  nodes = append(nodes, Node{
    NodeName: "div",
  }, Node{
    NodeName: "strong",
  })

  for i, node := range nodes {
    println(i)
    println(node.NodeName)
  }

  for i := range nodes {
    println(i)
  }
}
package main

func main() {
  ch := make(chan string)
  go func(msg string) {
    ch <- msg
  }("hi")

  println(<-ch)
}
package main

import "github.com/matthewmueller/joy/macro"

func call() interface{} {
  fetch := macro.File(`./fetch.js`)
  return fetch
}

func main() {
  fetch := call()
  _ = fetch
  res := macro.Raw(`fetch("http://google.com")`)
  println(res)
}
package main

import "errors"

func main() {
  err := errors.New("new error")
  println(err.Error())
  panic(err)
}
package main

import (
  "27-global-fetch/promise"
)

// Fetch fn
// js:"fetch,omit"
func Fetch(url string, options *map[string]string) *promise.Promise {
  return &promise.Promise{}
}

// Response struct
// js:"response,omit"
type Response struct {
  responseText string
}

// JSON gets the json
// js:"json"
func (r *Response) JSON() string {
  return r.responseText
}

// Github struct
// js:"github,omit"
type Github struct {
  Login string `json:"login,omitempty" js:"login"`
  Name string `json:"name,omitempty" js:"name"`
  Bio string `json:"bio,omitempty" js:"bio"`
}

func main() {
  p := Fetch("https://api.github.com/users/matthewmueller", nil)
  ch := make(chan Github, 1)

  p.Then(func(v interface{}) interface{} {
    res := v.(Response)
    return res.JSON()
  }).Then(func(v interface{}) interface{} {
    ch <- v.(Github)
    return nil
  }).Catch(func(e error) interface{} {
    println(e)
    return nil
  })

  gh := <-ch
  println(gh.Login, "-", gh.Name)
}
package main

import "encoding/json"

// Person struct
type Person struct {
  Name string `json:"name,omitempty" js:"name"`
  Age int `json:"age,omitempty" js:"age"`
}

func main() {
  var p Person
  if e := json.Unmarshal([]byte(`{"name":"ma\"tt","age":28}`), &p); e != nil {
    panic(e)
  }
  follows(&p)
}

func follows(p *Person) {
  println(p.Name)
}
package main

// Subthing struct
type subthing struct {
  name string
}

// Name string
func (s *subthing) Name() string {
  return s.name
}

// Thing struct
type Thing struct {
  *subthing
}

func main() {
  s := Thing{&subthing{"matt"}}
  println(s.subthing.Name())
}
package main

import "github.com/matthewmueller/joy/macro"

func main() {
  test("hi")
}

func test(msg string) {
  macro.Rewrite("console.log($1)", msg)
}
package main

func main() {
  test("a", "b", "c")
}

func test(results ...string) {
  println(results)
  test2("hi", results...)

  func(prefix string, results ...string) {
    // println(prefix, results)
  }("hello", results...)
}

func test2(prefix string, results ...string) {
  println(prefix, results)
}
package main

import (
  "time"
)

func main() {
  time.Sleep(1 * time.Second)
}
package main

import (
  "github.com/matthewmueller/joy/dom/htmlbodyelement"
  "github.com/matthewmueller/joy/dom/window"
)

func main() {
  document := window.New().Document()

  a := document.CreateElement("a")
  println(a.NodeName())
  strong := document.CreateElement("strong")
  println(document.CreateElement("strong").OuterHTML())
  a.AppendChild(strong)

  strong.SetTextContent("hi world!")

  body := document.Body().(*htmlbodyelement.HTMLBodyElement)
  body.AppendChild(a)
  println(document.Body().OuterHTML())
}
;(function() {
var pkg = {};
pkg["01-hello-world"] = (function() {
function main () {
console.log("hi world!")
};
return {
main: main
};
})();
return pkg["01-hello-world"].main();
})()
;(function() {
var pkg = {};
pkg["02-variables"] = (function() {
function main () {
var a = "a";
var b = "b", c = "c", d = "d";
var e = 3;
var $f = (function() {
return ["f", "g"];
})(), f = $f[0], g = $f[1];
var h = "h", i = "i", j = "j", k = "k";
console.log(a, b, c, d, e, f, g, h, i, j, k)
};
return {
main: main
};
})();
return pkg["02-variables"].main();
})()
;(function() {
var pkg = {};
pkg["07-struct-nested"] = (function() {
function main () {
var user = {
Name: "Matt",
Phone: {
Type: "",
Number: "1234511",
Main: false
}
};
console.log(user.Phone.Number);
user.Phone.Type = "CELL"
};
return {
main: main
};
})();
return pkg["07-struct-nested"].main();
})()
;(function() {
var pkg = {};
pkg["09-zero-values"] = (function() {
function main () {
var user = {
FirstName: "Tobi",
LastName: "",
Age: 0,
Phone: {
Type: "",
Number: ""
}
};
console.log(user.FirstName);
console.log(user.LastName);
console.log(user.Age);
console.log(user.Phone.Type);
console.log(user.Phone.Number)
};
return {
main: main
};
})();
return pkg["09-zero-values"].main();
})()
;(function() {
var pkg = {};
pkg["12-maps"] = (function() {
function main () {
var names = {
"a": "a",
"b": "b"
};
var nested = {
"a": {
"a": "a"
},
"b": {
"b": "b"
}
};
console.log(names["a"]);
console.log(nested["b"]["b"])
};
return {
main: main
};
})();
return pkg["12-maps"].main();
})()
;(function() {
var pkg = {};
pkg["13-simple-raw"] = (function() {
function main () {
var x = 15;
x += 5;
console.log(x)
};
return {
main: main
};
})();
return pkg["13-simple-raw"].main();
})()
;(function() {
var pkg = {};
pkg["16-range"] = (function() {
function main () {
var nodes = [];
nodes = nodes.concat({
NodeName: "div"
}, {
NodeName: "strong"
});
for (var i = 0, node; i < nodes.length; i++) {
var node = nodes[i]
console.log(i)
console.log(node.NodeName)
};
for (var i = 0; i < nodes.length; i++) {
console.log(i)
}
};
return {
main: main
};
})();
return pkg["16-range"].main();
})()
;(function() {
var pkg = {};
pkg["github.com/matthewmueller/joy/internal/runtime"] = (function() {
function Chan (o) {
o = o || {};
this.capacity = o.capacity || 0;
this.values = o.values || [];
this.sends = o.sends || [];
this.recvs = o.recvs || [];
this.closed = o.closed || false
};
function Channel (capacity) {
return new Chan({
capacity: capacity
});
};
function Deferred () {

if (!(this instanceof Deferred)) return new Deferred()
var self = this

var p = new Promise(function(resolve, reject) {
  self.resolve = resolve
  self.reject = reject
})

self.then = p.then.bind(p)
self.catch = p.catch.bind(p)
;
return self;
};
Chan.prototype.Recv = function() {
var c = this;
if (c.values.length > 0) {
var value = c.values[0]

c.values = c.values.slice(1)
return Promise.resolve(value);
};
if (c.sends.length > 0) {
var send = c.sends[0]

c.sends = c.sends.slice(1)
if (c.closed) {
send.promise.reject(new Error('send on closed channel'))
return Promise.resolve();
}
send.promise.resolve()
return Promise.resolve(send.value);
};
if (c.closed) {
return Promise.resolve();
};
var promise = Deferred();
c.recvs = c.recvs.concat(promise);
return promise;
};
Chan.prototype.Send = function(value) {
var c = this;
if (c.closed) {
return Promise.reject(new Error('send on a closed channel'));
};
if (c.recvs.length > 0) {
var recv = c.recvs[0]

c.recvs = c.recvs.slice(1)
recv.resolve(value)
return Promise.resolve();
};
if (c.values.length < c.capacity) {
c.values = c.values.concat(value)
return Promise.resolve();
};
var promise = Deferred();
c.sends = c.sends.concat({
value: value,
promise: promise
});
return promise;
};
return {
Chan: Chan,
Channel: Channel,
Deferred: Deferred
};
})();
pkg["23-goroutine-basic"] = (function() {
var runtime = pkg["github.com/matthewmueller/joy/internal/runtime"];
async function main () {
var ch = new runtime.Channel();
(async function(msg) {
await ch.Send(msg)
})("hi");
console.log(await ch.Recv())
};
return {
main: main
};
})();
return pkg["23-goroutine-basic"].main();
})()
;(function() {
var pkg = {};
pkg["25-external-file/fetch.js"] = (function() {
return function fetch(url) {
return 'Google'
}

})();
pkg["25-external-file"] = (function() {
function call () {
var fetch = pkg["25-external-file/fetch.js"];
return fetch;
};
function main () {
var fetch = call();
;
var res = fetch("http://google.com");
console.log(res)
};
return {
main: main
};
})();
return pkg["25-external-file"].main();
})()
;(function() {
var pkg = {};
pkg["26-errors"] = (function() {
function main () {
var err = new Error("new error");
console.log(err.message);
throw err
};
return {
main: main
};
})();
return pkg["26-errors"].main();
})()
;(function() {
var pkg = {};
pkg["github.com/matthewmueller/joy/internal/runtime"] = (function() {
function Chan (o) {
o = o || {};
this.capacity = o.capacity || 0;
this.values = o.values || [];
this.sends = o.sends || [];
this.recvs = o.recvs || [];
this.closed = o.closed || false
};
function Channel (capacity) {
return new Chan({
capacity: capacity
});
};
function Deferred () {

if (!(this instanceof Deferred)) return new Deferred()
var self = this

var p = new Promise(function(resolve, reject) {
  self.resolve = resolve
  self.reject = reject
})

self.then = p.then.bind(p)
self.catch = p.catch.bind(p)
;
return self;
};
Chan.prototype.Recv = function() {
var c = this;
if (c.values.length > 0) {
var value = c.values[0]

c.values = c.values.slice(1)
return Promise.resolve(value);
};
if (c.sends.length > 0) {
var send = c.sends[0]

c.sends = c.sends.slice(1)
if (c.closed) {
send.promise.reject(new Error('send on closed channel'))
return Promise.resolve();
}
send.promise.resolve()
return Promise.resolve(send.value);
};
if (c.closed) {
return Promise.resolve();
};
var promise = Deferred();
c.recvs = c.recvs.concat(promise);
return promise;
};
Chan.prototype.Send = function(value) {
var c = this;
if (c.closed) {
return Promise.reject(new Error('send on a closed channel'));
};
if (c.recvs.length > 0) {
var recv = c.recvs[0]

c.recvs = c.recvs.slice(1)
recv.resolve(value)
return Promise.resolve();
};
if (c.values.length < c.capacity) {
c.values = c.values.concat(value)
return Promise.resolve();
};
var promise = Deferred();
c.sends = c.sends.concat({
value: value,
promise: promise
});
return promise;
};
return {
Chan: Chan,
Channel: Channel,
Deferred: Deferred
};
})();
pkg["27-global-fetch"] = (function() {
var runtime = pkg["github.com/matthewmueller/joy/internal/runtime"];
async function main () {
var p = fetch("https://api.github.com/users/matthewmueller", null);
var ch = new runtime.Channel();
p.then(await async function(v) {
var res = v;
return res.json.bind(res)();
}).then(await async function(v) {
await ch.Send(v);
return null;
}).catch(await async function(e) {
console.log(e);
return null;
});
var gh = await ch.Recv();
console.log(gh.login, "-", gh.name)
};
return {
main: main
};
})();
return pkg["27-global-fetch"].main();
})()
;(function() {
var pkg = {};
pkg["31-json-unmarshal"] = (function() {
function follows (p) {
console.log(p.name)
};
function main () {
var p = {
name: "",
age: 0
};
var e = (function(data, v) {
try {
var o = JSON.parse(data)
for (var k in o) v[k] = o[k]
return null
} catch (e) { return e }
})("{\"name\":\"ma\\\"tt\",\"age\":28}", p);
if (e != null) {
throw e
};
follows(p)
};
return {
main: main
};
})();
return pkg["31-json-unmarshal"].main();
})()
;(function() {
var pkg = {};
pkg["38-receiver-funcs"] = (function() {
subthing.prototype.Name = function() {
var s = this;
return s.name;
};
function subthing (o) {
o = o || {};
this.name = o.name || ""
};
function main () {
var s = {
subthing: new subthing({
name: "matt"
})
};
console.log(s.subthing.Name.bind(s.subthing)())
};
return {
main: main
};
})();
return pkg["38-receiver-funcs"].main();
})()
;(function() {
var pkg = {};
pkg["42-basic-rewrite"] = (function() {
function main () {
console.log("hi")
};
return {
main: main
};
})();
return pkg["42-basic-rewrite"].main();
})()
;(function() {
var pkg = {};
pkg["50-slice-spreads"] = (function() {
function test2 (prefix) {
var results = Array.prototype.slice.call(arguments, 1);
console.log(prefix, results)
};
function test () {
var results = Array.prototype.slice.call(arguments, 0);
console.log(results);
test2.apply(null, ["hi"].concat(results));
(function(prefix, results) {

})("hello", results)
};
function main () {
test.apply(null, ["a", "b"].concat("c"))
};
return {
main: main
};
})();
return pkg["50-slice-spreads"].main();
})()
;(function() {
var pkg = {};
pkg["58-time-sleep"] = (function() {
async function main () {
await new Promise(function(resolve, reject) { setTimeout(resolve, 1 * 1000) })
};
return {
main: main
};
})();
return pkg["58-time-sleep"].main();
})()
;(function() {
var pkg = {};
pkg["52-basic-dom"] = (function() {
function main () {
var document = window.document;
var a = document.createElement("a");
console.log(a.nodeName);
var strong = document.createElement("strong");
console.log(document.createElement("strong").outerHTML);
a.appendChild(strong);
strong.textContent = "hi world!";
var body = document.body;
body.appendChild(a);
console.log(document.body.outerHTML)
};
return {
main: main
};
})();
return pkg["52-basic-dom"].main();
})()

DOWNLOAD JOY

The easiest way to get started is to run this curl command in your terminal, but you can also download Joy from the GitHub releases tab.


Joy's Guiding Principles

These principles greatly influenced the design and implementation of Joy:

Why did you work on Joy?

I want to let you in on a little secret – I love Javascript.

I started making websites when I was 13 and became obsessed with AJAX after playing with Google Maps and chatting on Meebo. I owe my career to the Javascript and Node.js community and still consider myself a frontend engineer. In the early days, Javascript didn't get much love. Consistency across browsers wasn't taken seriously, so you needed frameworks like jQuery to get anything done.

Now we have the opposite problem – Javascript gets too much love.

While browser consistency has greatly improved, the language itself has been rapidly changing. This has caused major breaking changes over the last couple years. These breaking changes have segmented the community, left behind older browsers and caused cascading issues downstream in tools and across libraries.

There’s no doubt that the language has been improving and critics would argue that these changes are just growing pains. While I do believe the language will settle down in the future, these issues make it very difficult to author long-lasting web applications today.

For me, the breaking changes weren’t enough motivation to work on Joy. I began looking for post-Javascript alternatives after I built Standup Jack.

Standup Jack is a medium-sized Node.js application that schedules and coordinates team standups on Slack. Standup bots are particularly tricky because if you take the service down for even a few minutes, there are going to be teams not receiving their standups on time.

I found that while it was easy to develop Standup Jack, it’s been very hard to maintain and add features to the service, even with good test coverage. Over time, your understanding of your work fades and you need good tools to tell you what you should and shouldn't do. This issue is compounded when you didn't write the code yourself or you're under pressure to push a fix.

You need tools that can walk all the possible code paths and warn you, "Hey slow down, you're forgetting about this". Tools like this require a type system. Microsoft realized this and developed Typescript in 2012. Facebook realized this and developed Flowscript in 2014.

While I’ve used and prefer these type systems over vanilla Javascript, they come with their own additional complexities because they’re adding types on top of an untyped, dynamic language. Go’s type system is a lot simpler because it was developed alongside the design of the language.

Additionally, the browser APIs have been getting more powerful over the years. You used to need big Javascript frameworks to be able to get anything done. Nowadays, there are only a handful of indispensible Javascript libraries. The rest can be re-written or bound inside a Go application with minimal effort.

For these reasons, I believe that writing maintainable and long-lasting Javascript that works in every browser is more time-consuming and painful than starting from scratch and kickstarting a fresh ecosystem built on top of a more solid foundation.

That's why I got to work.

Why Go?

There are 5 primary reasons why I chose Go as the source language:

Go embraces write once, read many times

Go was built to be easy to read, understand and maintain. As one of the Go's original authors puts it:

Go was deliberately designed from the start to support large scale programs implemented by hundreds or thousands of different programmers.

Go’s syntax is stable

The language has been stable and backwards compatible since 2012. This is very important and it allows us to be confident that the Go code we write today will work 5 years from now.

Go’s type checking and compiler are blazingly fast

Coming from the frontend world, we expect to be able to see our changes show up in the browser in the blink of an eye. We’ve spent countless hours tweaking webpack configurations to get hot reloads working so we can reach a feedback loop that puts us in the zone.

You'll find that Go’s type checker and compiler performance check this box and the cross-platform binary builds make it an excellent language for frontend tooling.

Go has an excellent standard library and tools

Go has a comprehensive and well-tested standard library and nearly everyone uses the same set of tools. While this may sound like a lack of diversity or an innovation killer, it actually makes life easier.

Less options mean easier decision-making, more expertise and more resources can be directed towards a smaller set of libraries and tools.

Implicitly asynchronous

With Go you can move asynchronous behaviors inside functions and libraries so from the caller’s perspective, an asynchronous function looks synchronous. No more callback hell, promise chains or async function wrappers.

Critics may say that this hides expensive calls, but you can answer these kinds of questions easily with the "Jump to Definition" tool that's supported by all the major editors.

How does Joy Work?

The Joy compiler has 5 steps: parse, index, graph, translate and assemble.

  1. Parse turns your Go code into an abstract syntax tree (AST). This is primarily done using the x/tools/loader library provided by the Go team.
  2. Index processes these Go ASTs allowing us to answer deep questions about our program. Questions like: "what packages does this function depend on?" and "which structs implement this interface?". This step is very similar to what our editors do to give us features like autocomplete, "Find all References" and "Jump to Definition".
  3. Graph uses the index to create a dependency graph. This graph is sorted topologically and pruned, resulting in a list of nodes containing the functions, variables, structs and interfaces that are used in our program.
  4. Translate is the fun part. Translate is where we take the nodes in our graph and the knowledge in our index to translate the Go AST into a Javacript AST.
  5. Assemble takes the resulting Javascript AST and generates Javascript code.

How does Joy work with existing Javascript?

There are multiple ways to bring existing Javascript into a Go codebase using the macro package bundled with Joy:

There will be more documentation and examples on these macros in the coming weeks, but for now you can check out the examples above and the DOM's window API on GitHub to see the macros in action.

How does Joy work with existing Go?

Most existing Go code does not yet compile to Javascript. This is because most of the standard library still needs to be translated to Javascript. This will be a focus of the 2.0 release. Signup for the mailing list to follow along with the progress.


JOIN THE MAILING LIST

Be the first to know when we release new version, add features, create tutorials and spotlight websites using Joy in production. No spam ever.


What’s next for Joy?

1.0: Getting Joy Production Ready

Finish up the Go to Javascript translator and finalize the DOM and virtual DOM APIs.

Right now the translator is about 90% complete. There are still some missing statements (e.g. switch, select), syntax variations and a few scoping bugs that need to be addressed.

Additionally, we need to finish the production build. According to this issue, it’s possible to bring generator support to ES3, which means channels can be supported. At the very least, we can support ES5 by removing async/await function calls and the bind functions.

Lastly, I’d like to add incremental compilation here too, so we can keep the compiler zippy for large projects.

After Milestone 1 is complete, Joy will be considered production-ready and stable. At this point, we will take breaking changes very seriously. If we do have to make breaking changes, they will only be done during major releases.

2.0: Growing the Ecosystem

Implement much more of Go’s standard library. Standard libraries like time, url, fmt need to be translated.

We’ll also be improving the toolchain, by adding support for go test (to run browser tests!) and adding more support for essential frontend libraries like D3.

3.0: Hygienic Macro System

At this point, I'd like to explore creating a hygienic macro system to allow Go to be translated into more variations of Javascript. This will allow the compiler to be extended to support more flavors of Javascript without needing the Joy authors' blessing. It’s also more decentralized than a plugin system like the one in the Babel compiler because it allows library authors to implement their own plugins without needing you to set it all up manually.

4.0: Optimize performance and build size

Further reduce the Javascript build size, improve Javascript performance and improve the compiler’s performance. This will be ongoing, but will be a focus for this phase since the compiler’s internal APIs should be settled.

5.0: Target WebAssembly

Target WebAssembly for non-DOM libraries. This work may happen in parallel with the other milestones, but will be much more of the focus going forward since that's where the future is heading.

FAQ

How does Joy compare to GopherJS?

GopherJS and Joy are two different approaches to the same goal.

PaluMacil describes it best:

GopherJS started with Go as a priority and is working towards great JavaScript interoperability whereas Joy started with JavaScript as a priority and is working towards great Go interoperability.

GopherJS currently implements much more of the standard library and has a complete syntax translation. Joy is working to get to this point.

Joy uses Go's static analysis tools to eliminate dead code and uses a macro system to produce much smaller Javascript builds with better performance. Joy's goal is to produce Javascript that looks like it could have been handwritten. The compiler architecture was very much inspired by projects like Bucklescript and Rollup.

Joy's development started with me asking myself:

Could I create a more productive and fun frontend development environment in Go over using Typescript, Webpack, React and the Javascript module ecosystem?

To that end, the initial focus is on supporting the DOM and essential frontend libraries. Later on, we'll be working on compatibility with existing Go libraries.

How much is Joy going to cost me?

I hope to keep the core compiler free forever and find other ways to pay for Joy's development and support.

As an independent developer with limited resources, I can only take this project so far on my own. The only way for this project to reach it’s full potential is for Joy to become community-driven and financially self-sustainable.

The work I do to reach a break-even is even more important than the code I write and I will be experimenting with various ways to reach this goal.

If you can help me do that or you have ideas on how to get there, please reach out to me directly on Twitter or comment on this Github issue.

What is Joy's license?

Joy is licensed under GPLv3. In short, this means that Joy is free to use and modify, but any remixes to the Joy compiler must also be free and open source.

Of course, this only applies to the compiler code itself. You own the input and output source code.

If you'd like to use Joy in your organization but find this license too restrictive, please reach out to me directly.

Can Joy compile to WebAssembly?

Not yet, but it’s part of the master plan (cue sinister laugh).

WebAssembly is very much on my mind and I think Joy’s parsing, indexing and graphing phases can be re-used to translate Go into an extremely compact WebAssembly binary format.

I wanted to start with Javascript because WebAssembly is still experimental technology and only available in about 68% of web browsers. Additionally, the current implementation of WebAssembly cannot access the DOM directly and is meant to be used alongside Javascript in the form of WASM modules.

Outside of Joy, there’s some work being done on the Go compiler itself to bring WASM support natively. If that works out, I’m hoping we can use that and choose the output format in an intelligent way based on what type of code you’re compiling and the target browser.

In either case, if we want to start using Go on the frontend, we’ll need to start building frontend tools and bindings in Go, so why not get started on that work today!

Isn’t Go too verbose?

When compared with Javascript, Go takes a lot more keystrokes to express the same idea. This was very frustrating to me at first, but I soon realized that Go will save you time in other ways:

More generally, this means that you spend more time in your editor coding and less time context-switching and getting distracted.

Does Joy work with React?

Absolutely! Joy has virtual DOM bindings for React today, but it’s not well-documented yet.

In the coming weeks I’ll be introducing a framework based on Next.js that will make programming with React even easier. Sign up for the mailing list to find out when that’s ready.

I believe React is just the beginning here. Now that we have a Go to Javascript compiler that produces really great Javascript, we can create all sorts of tools for the front-end ecosystem.

Personally, I’d love to see the Vue.js compiler brought to Go where the <script> tags would export Go functions.

Is Joy right for my team?

It would be misleading for me to say that Joy is a right call for every team. Joy is still in it’s infancy and your choice in tech stack will largely depend on the needs of your application and the size of your team.

I think Joy is a great choice if your web application is sufficiently complex, expected to be updated over multiple years or you have multiple teammates working on the same codebase.

While Joy and Go’s frontend ecosystem are still nascient, I believe they will grow very quickly to cover a variety of needs.

My hope is that you’ll give Joy a try for your next project and see if it’s right for you and your team and if it’s not, I’d love to hear why.

Why do you ask for our email address?

I’d like to be able to reach you when we add features, create tutorials and spotlight websites using Joy in production.

I hate spam as much as the next person and if the emails you receive aren’t helpful, I’d love to hear how we can improve them. And if you want to stop receiving email altogether, you'll have an option to unsubscribe in each email sent.

What metrics do you collect?

Joy collects metrics on when events happen, number of lines of code compiled and compiler errors. Joy will never collect any information on the actual contents of the code.

These metrics will helps us move quickly to improve the performance of the compiler and address regressions.

How can I help?

The best way to help would be to provide financial support. If I can work on Joy full-time, the project will move a lot faster.

Where can I find more examples?

Right now the best place to find examples is in the test suite. I’ll be adding many, many more examples in the near future.

How can I contact you?

The fastest way to reach me is on Twitter but you can also email me. In either case, please be patient and respectful.

Anything else?

The sky is the limit! Get after it.

A Special Thanks

The Joy Compiler stands on the shoulders of some excellent engineers.

TJ Holowaychuk & Tejas Manohar

The feedback I received from TJ and Tejas was invaluable during the early stages of design and development.

The Go Team

They created a truly pragmatic, modern programming language. Their tooling is in a league of its own and most of the heavy lifting done by Joy is actually making use of the hard work put into the Go standard library and it’s peripheral libraries like x/tools.

A special shoutout to Alan Donovan whose presentations on Youtube helped me to make sense of some of the lesser documented tools, Robert Griesemer for a just-in-time pull request adding support for Go AST rewrites and Michael Fraenkel for a much smarter Go imports command that greatly simplified the DOM and VDOM code generation.

The GopherJS authors

GopherJS was instrumental in showing me that creating a Go to JS compiler was even possible and whenever I had a question about what a Go statement should translate to in Javascript, I looked to GopherJS for inspiration.

The Typescript & Edge teams

Joy would not have seen the light of day if I knew I would have to write an entire DOM API by hand. Fortunately, the Typescript team with the help of the Edge team did most of that work already, allowing me to programmatically generate a DOM API.

The Chromium Team

From the beginning, I knew I wanted joy run to execute against a real DOM. Thankfully, the Chromium team came out with a headless version of Chrome that is performant, reliable and easy to use.