11 ms·
Show HN: Joy – a Go to JavaScript compiler
- schickling 9y agoThis looks amazing! Is there some demo video available?
- matthewmueller 9y agoThanks! Not yet, but I'm planning to make some videos very soon :-)
- matthewmueller 9y agoHey folks! I've been hard at work building this compiler for the last few months and I'm very excited to finally be able to share it with you. I'll be here to answer any questions you might have!
- schickling 9y agoI'm very much looking forward to the Next.js-like framework you've teasered!
- matthewmueller 9y agoIt's my top priority :-)
- notheguyouthink 9y agoIs this going to be in Go?
- tjholowaychuk 9y agoBut not the hacky routing :D please, libraries > frameworks
- trog 9y ago"The Go code is on the right and the compiled Javascript code is on the left. " I am not very familiar with Go and am only barely passable at Javascript - but aren't these the wrong way round?
- _eric 9y agoYup.
- matthewmueller 9y agoHaha wow good catch – updated!
- zellyn 9y agoI command-F searched for GopherJS, looking for the obvious question -- how is this different? -- but found nothing besides crediting it as “inspiration”. So, how is this different? EDIT: asked in the Golang slack. Will update when I find out the answer.
- matthewmueller 9y agoHey sorry for the oversight there, I'll be documenting this in further in the next few days, but for now you can head over to: https://github.com/matthewmueller/joy/issues/56 https://github.com/matthewmueller/joy/issues/56 to read more
- vanderZwan 9y agoNot OP, but GopherJS is an emulator: > GopherJS emulates a 32-bit environment. This means that int, uint and uintptr have a precision of 32 bits. However, the explicit 64-bit integer types int64 and uint64 are supported. The GOARCH value of GopherJS is "js". Joy doesn't seem to be: > [Joy ships] a minimal runtime only when it's needed > 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. This has some obvious consequences in how they differ. For example, if I look at [0][1], GopherJS results in a huge amount of code bloat because it includes a translation of the Go runtime. A basic example 33 LOC grows to 44 LOC on its own, but with the GopherJS environment that becomes: > 1470 LOC and 45kb, uncompressed and unminified. The bulk of which is the builtin library. It will only compile what it needs to. So if you declare types that are never used, they won't show up in the resulting code. This goes for core packages too. If I change that code so it requires "fmt", the result explodes to 12845 LOC and 624kb ("fmt" imports a LOT of stuff). (In GopherJS' defense, minification slims it down to 21kb, and the example probably is missing a production code compiler flag) The examples on the Joy webpage look a lot more minification-friendly and easier to integrate with other JavaScript. [0] http://legacytotheedge.blogspot.se/2014/03/gopherjs-go-to-javascript-transpiler.html http://legacytotheedge.blogspot.se/2014/03/gopherjs-go-to-ja... [1] https://gist.github.com/rolaveric/9407509 https://gist.github.com/rolaveric/9407509
- sAbakumoff 9y agoI have the only question and I would really appreciate to get a clear answer instead of many down votes. Why are you doing this?
- wyuenho 9y agoHey nice work! Can you tell us a little about why you've created this and its utility for the general public? Thanks!
- matthewmueller 9y agoThanks :-) You can read more about my personal view here: https://mat.tm/joy/#why https://mat.tm/joy/#why
- matthewmueller 9y agoHeading to bed now. I'll be back on this thread tomorrow to answer any lingering questions. Feel free to open an issue on github with any additional questions or ping me at twitter.com/@mattmueller. Thanks everyone and good night!
- andrewl-hn 9y agoHey, great work! Just a heads up about licensing. JavaScript code fragments that you use inside the compiler to produce the final output are technically part of the source code, and thus the output is also GPLv3 licensed as a derived work. That's a known GPL quirk, and other GPL-licensed compilers like GCC use a separate variant of GPL to avoid that collision. You can see how GNU Bison does it: https://git.savannah.gnu.org/cgit/bison.git/tree/src/parse-gram.c#n20 https://git.savannah.gnu.org/cgit/bison.git/tree/src/parse-g... since they put fragments of Bison code to the final generate source file. That's exactly what Joy does to generate JavaScript, so you should put similar notice to the repository. Also, LICENCE file is not there.
- matthewmueller 9y agoThanks for the heads up! I was hoping for someone with more licensing knowledge to stop by :-)
- lobster_johnson 9y agoHi, this looks great! Quick question: My company has a few libraries (including a language parser/compiler) currently written in Go, and we have a need for the exact same functionality in the browser and in other places (e.g., Node.js apps). Rather than port everything to JS and have two codebases to maintain, we tried translating with GopherJS, which seemed promising at first. But the emitted code was enormous, and it pulled in parts of the standard library that couldn't be transpiled. (Our code had limited dependencies, but our main problem was the "fmt" package, which, if I remember correctly, is somewhat special and not something you can just omit.) In the end, it was too much work for a small company with our limited resources. Is Joy intended to serve this purpose?
- matthewmueller 9y agoHi there, I've created an issue for your purpose: https://github.com/matthewmueller/joy/issues/63 https://github.com/matthewmueller/joy/issues/63 I definitely want to take the stdlib slow and not overdo it. If we can't make it work well in JS, we'll probably just leave it out.
- tboyd47 9y agoThis is AWESOME. I absolutely love the idea of transpiling other languages to readable (and therefore, debuggable and maintainable) Javascript. Kudos and I'll be watching this project.
- matthewmueller 9y agoThanks for the kind words of encouragement!
- kotrunga 9y agoDo you have a personal website / blog? I could be completely missing something, but mat.tm is down.
- matthewmueller 9y agoWeird, maybe a DNS issue? Can you try again?
- readams 9y agoLooks interesting but I think WebAssembly remains the more promising path for compiling to web browsers at this point. x to JS transpilers are likely on the way out.
- IshKebab 9y agoTrue, but right now this is the better approach because you can access the DOM, and presumably make use of Javascript's garbage collector.
- matthewmueller 9y agoExactly that – I think there will be great opportunities to use both depending on what kind of code it is. WASM is on the radar though: https://mat.tm/joy/#faq-webassembly https://mat.tm/joy/#faq-webassembly
- dinedal 9y agoHow is this different from the more established GopherJS?
- Touche 9y agoFrom an issue in the GitHub, it sounds like GopherJS has a slightly different goal; it is attempting to make it possible to compile existing Go libraries / projects, whereas Joy is more focused on new projects built specifically to run in the browser.
- dfabulich 9y agoIt advertises VDOM support, but Go/Joy doesn't appear to have anything like JSX, right? (JoySX?)
- fiatjaf 9y agoI hope not.
- matthewmueller 9y agoNo JSX – VDOM would mean things what JSX turns into e.g. `React.createElement(...)`
- m00s3 9y agoPossible conflict with the name: https://en.wikipedia.org/wiki/Joy_(programming_language) https://en.wikipedia.org/wiki/Joy_(programming_language)
- matthewmueller 9y agoHmm, good catch. Let's see how it plays out :-)
- nerdponx 9y agoWhy not call it JoyGo or JoyJS or Go2js or something? No reason to cause name (and command line) confusion just because you like a name.
- Sir_Cmpwn 9y agoJoy is coming up on 15 years without a release, there should probably be a statute of limitations on this sort of thing.
- JustSomeNobody 9y agoI disagree. You'll end up with new languages using the names of older languages. Besides, software can at some point be done.
- Sir_Cmpwn 9y agoSoftware can also fade into irrelevance, which is what has happened to Joy.
- a-nikolaev 9y agoJoy is a mathematical language similar to lambda calculus. It's getting old very slowly, slower that this compiler.
- sAbakumoff 9y ago> 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. Thanks, but for type system we already have type script. Secondly, the post powerful Golang feature which is you know co-routines can't be translated to javascript
- matthewmueller 9y agoI was a heavy Typescript user and a big fan. I personally found Go's type system and overall ecosystem to be much easier to grok, especially when it came to interacting with 3rd party packages. If you read through https://mat.tm/joy/#why https://mat.tm/joy/#why you'll read more about my perspective there. Actually to my surprise, goroutines and channels can be modeled quite well in Javascript! Right now the compiler uses async/await but for 1.0, I think it's possible to compile it down to ES3.
- sAbakumoff 9y agoDid you try Angular 4 + TypeScript? I recently switched to it after years in React and that's amazing, google really did it right this time. After using it for a while I don't feel any need in any additional tools.
- sAbakumoff 9y agoWait, async/await and co-rotines are completely different concepts, aren't they? the former just separate the moment of execution from the moment of receiving the result, the latter allow to execute the code in parallel. In browser the parallelism is only possible with web-worker.
- MatthewPhillips 9y agoHi Matt! First congratulations. This is a very interesting project, one that I look forward to trying out. I'm wondering if Promises are the right way to compile goroutines though. Promises don't run in parallel, and they actually do block; they don't defer to the event loop. I wonder if compiling to web workers would be possible though...
- notheguyouthink 9y agoHey, I just saw this on the Github WASM thread, looks cool! I'm interested, but if I may request, you should highlight the missing/non-fully-functional keywords. That's my main concern, and from the main page it sounded like this was a fully working Go. Yet the Github issues seemed to highlight several missing keywords. While this may not seem like a big issue, having to conceptually know what works and what doesn't is mental overhead, so reducing that overhead by making it super prominent would be great for me. Thanks! This looks really cool btw, once I have a better idea on the completeness of this, I'll definitely try it with React! It's the one thing I failed with GopherJS on, React integration was difficult to keep performant. I'm excited :)
- matthewmueller 9y agoThanks for the kind words. Yah I think you're right that I should make the current state more clear, not just where it's headed. FWIW, there's some more information on that lower down the page: https://mat.tm/joy/#next-steps https://mat.tm/joy/#next-steps
- srameshc 9y agoWhat a coincidence. I was thinking when would something like this be out yesterday and it stayed just a thought. Didn't bother to google and now I see it here. Something I would certainly love to try.
- 52-6F-62 9y agoHey Matt, I received this error when trying to compile a "hello world" for the first time: error downloading headless chrome: error making directory: mkdir /Users/matt I'm not really clear on why it would need to create a folder under Users on Mac. I am looking forward to giving it a try, though.
- matthewmueller 9y agoUnfortunately there's a bug: https://github.com/matthewmueller/joy/issues/53 https://github.com/matthewmueller/joy/issues/53 Will fix it in the morning but I need to sleep now. Zzzz... Thanks for the kind words and please try it again tomorrow :-)
- ridiculous_fish 9y agoHow are Go's pointers implemented in JS?
- matthewmueller 9y agoThis is not done yet. Right now there's no difference between pointer values and non-pointer values.
- kindfellow92 9y agoThere is a statement in that document that says that much of the standard library hasn’t been translated but isn’t most of the Go standard library written in Go? Why can’t Joy convert the standard library?
- matthewmueller 9y agotime. never enough time ;-)
- kindfellow92 9y agoWell, the go standard library is mostly written in Go, and Joy is supposed to convert go... so shouldn’t this just work?
- deleted 9y ago[deleted]
- rkeene2 9y agoOn startup (with no arguments, so just "help" output) it tries to read my ~/.aws/credentials file and there seems to be some kind of tracking going on: https://github.com/matthewmueller/joy/blob/master/internal/stats/stats.go https://github.com/matthewmueller/joy/blob/master/internal/s... I almost used this software, but I'm going to have to go through the code before I do now.