Show HN: Write Go code in JavaScript files

(npmjs.com)

43 points | by yar-kravtsov 3 hours ago

8 comments

  • montakaoh 1 minute ago
    we need to go deeper
  • h33t-l4x0r 6 minutes ago
    How big is it? Is it smaller than imagemagick wasm?
  • foreigner 1 hour ago
    Reminds me of this toy I made some years ago: https://www.npmjs.com/package/polyglot-tag
  • b_e_n_t_o_n 1 hour ago
    Hah. Back in the day I wrote a plugin to convert Lua files into a module that ran via one of the JS lua vms. Good fun.
  • pjmlp 1 hour ago
    Cool hack, just use JavaScript.
    • Cthulhu_ 44 minutes ago
      99 times out of a hundred, sure. But sometimes you need better performance or a library that isn't available in JS.
      • hollowturtle 2 minutes ago
        Better performance? For javascript code that calls into native platform apis provided by the browser it's been alteady proven that performance is an order of magnitude better than calling into wasm and doing all the sheningans to move bytes from and to wasm
      • pjmlp 5 minutes ago
        WebGPU or WebGL is the answer.
    • kitd 52 minutes ago
      The author explains why you might want to use Go instead at the end of the readme.
      • onion2k 38 minutes ago
        I don't think any of the use cases suggested really make sense though. For a compute-intense task like audio or video processing, or for scientific computing where there's likely to be a requirement to fetch a ton of data, the browser is the wrong place to do that work. Build a frontend and make an API that runs on a server somewhere.

        As for cryptography, trusting that the WASM build of your preferred library hasn't introduced any problems demonstrates a level of risk tolerance that far exceeds what most people working in cryptography would accept. Besides, browsers have quite good cryptographic APIs built in. :)

        • tgv 22 minutes ago
          > For a compute-intense task

          The browser often runs on an immensely powerful computer. It's a waste to use that power only for a dumb terminal. As a matter of fact, my laptop is 6 years old by now, and considerably faster than the VPS on which our backend runs.

          I let the browser do things such as data summarizing/charting, and image convolution (in Javascript!). I'm also considering harnassing it for video pre-processing.

          • pjmlp 4 minutes ago
            You can take advantage of that power via WebGPU, or WebGL if the browser is not yet up to it.
  • hshdhdhehd 1 hour ago
    Like it. Especially the how to use it and when to use it guidance.
  • smashah 1 hour ago
    funny but this is going to become extremely popular.
  • nsonha 1 hour ago
    seems like an unintuitive idea that could have only come from someone infected by react/vercel. The natural way that most would think about this is just write go in a go file and have an import attribute or macro
    • yar-kravtsov 1 hour ago
      Fair take! Though, this was literally built as a joke in response to @ibuildthecloud's tweet. Sometimes the dumbest ideas are the most fun to prototype.
    • iamsaitam 54 minutes ago
      Are there vaccines for these infected? I hope we can stop the spread /s