Solod – A Subset of Go That Translates to C

(github.com)

73 points | by TheWiggles 4 hours ago

9 comments

  • 0xmrpeter 23 minutes ago
    The claim that no goroutines makes this pointless isn't quite right. Migrated 50 services off Docker Compose using Nomad and half of them had zero concurrency needs. A safe Go-syntax C target is actually useful for that layer.
  • ridiculous_fish 1 hour ago
    I was curious how defer is implemented. `defer` in Go is famously function-scoped, not lexically-scoped. This means that the number of actively-deferred statements is unbounded, which implies heap allocation.

    The answer is that Solod breaks with Go semantics here: it just makes defer block-scoped (and unavailable in for/if blocks, which I don't quite get).

    https://github.com/solod-dev/solod/blob/main/doc/spec.md#def...

    • hmry 1 hour ago
      What's the point if it's incompatible? The README suggests using go's testing toolchain and type checker, but that's unreliable if the compiled code has different behavior than the tested code. That's like testing and typechecking your code in a C++ compiler but then for production you run it through a C compiler.

      Would have been a lot more useful if it tried to match the Go behavior and threw a compiler error if it couldn't, e.g. when you defer in a loop.

      Is this just for people who prefer Go syntax over C syntax?

  • Retr0id 3 hours ago
    I don't really "get" the sweet-spot being targeted here. You don't get channels, goroutines, or gc, so aside from syntax and spatial memory safety you're not really inheriting much from Go. There is also no pathway to integrate with existing Go libraries.

    Spatial memory safety is nice but it's the temporal safety that worries me most, in nontrivial C codebases.

    • tidwall 3 hours ago
      Looks to me like having the ability to write Go syntax and interop directly with C is the plus.
      • Retr0id 3 hours ago
        I do like Go's syntax but I can't help thinking the best language for C interop is C.
        • AdieuToLogic 2 hours ago
          > I do like Go's syntax but I can't help thinking the best language for C interop is C.

          SWIG[0] is a viable option for incorporating C code as well.

          0 - https://swig.org/Doc4.4/Go.html#Go

          • stevekemp 2 hours ago
            I love how SWIG is still around! I first used it about 30 years ago to integrate with Perl, then later with Java.
      • whateveracct 1 hour ago
        Go's syntax is basically C tho lol

        what's the benefit? for loops?

  • numlock86 17 minutes ago
    > So supports structs, methods, interfaces, slices, multiple returns, and defer.

    > To keep things simple, there are no channels, goroutines, closures, or generics.

    Sure, slices and multiple return values are nice, but it's not what makes Go good. When people think about Go they usually think about channels and goroutines. YMMV

    While I do kind of get what the appeal and target audience is supposed to be, I absolutely don't get why you'd choose a subset and still have it behave differently than the Go counterpart. For me that destroys the whole purpose of the project.

  • tidwall 3 hours ago
    "To keep things simple, there are no channels, goroutines, closures, or generics."

    I wonder if it could be integrated with https://github.com/tidwall/neco, which has Go-like coroutines, channels, and synchronization methods.

  • MYEUHD 3 hours ago
    Related and currently on the front page: https://news.ycombinator.com/item?id=47627595
  • remywang 2 hours ago
    Anton also wrote the fantastic codapi [1] for embedding executable code snippets with wasm

    [1]: https://codapi.org/

  • Onavo 2 hours ago
    Does it work with the preprocessor?
  • MegagramEnjoyer 2 hours ago
    This is a bit too barebones. At least bring goroutines dude