logoalt Hacker News

Solod – A subset of Go that translates to C

166 pointsby TheWigglestoday at 12:48 AM41 commentsview on HN

Comments

ridiculous_fishtoday at 3:35 AM

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...

show 4 replies
Retr0idtoday at 2:06 AM

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.

show 3 replies
0xmrpetertoday at 5:08 AM

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.

tidwalltoday at 2:08 AM

"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.

leecommamichaeltoday at 10:55 AM

If this sounds good to you, you would like the Odin programming language.

MYEUHDtoday at 2:25 AM

Related and currently on the front page: https://news.ycombinator.com/item?id=47627595

thefoundertoday at 2:06 PM

As a Go developer I would use this unless...I would have to build the std libraries myself. Now I also wonder how this compares with tinyGo. Why would you pick one over the other...

voidUpdatetoday at 7:18 AM

I'm reminded of the tools in programs like Ghidra or IDA which can take assembly code and convert it into a C-like language. If you could create one of those tools that also takes in the source file so that it names things somewhat reasonably, could you create an anything to C translator? As long as the original file compiles to assembly, that is

show 1 reply
remywangtoday at 3:14 AM

Anton also wrote the fantastic codapi [1] for embedding executable code snippets with wasm

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

weitzjtoday at 6:20 AM

Love it. And from my experience the need for Go Routines is not that urgent.

Sure when I started Go there were Go routines plastered everywhere. And now I think harder: “do I really need a go routine here?”

joshuaharttoday at 8:50 AM

Interesting approach. What was the main motivation for targeting C specifically instead of something like LLVM or WASM as an intermediate?

show 1 reply
numlock86today at 5:14 AM

> 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.

xentripetaltoday at 7:36 AM

Somewhat similar language, https://vlang.io

It’s a mix of go and rust syntax that translates to C

jimgilltoday at 6:41 AM

Might this help in memory leaks in go ... what will happen to the code that translated to pointers ....wrong conversation...CODE CRASH??

cptmurphytoday at 3:39 PM

This is more interesting project: https://git.urbach.dev/cli/q

Suractoday at 6:59 AM

I seem too stupid. Why not use C11 in the first place? Can anyone explain?

matthewmuellertoday at 6:01 AM

Love the design considerations here!

vaughantoday at 5:42 AM

We need this for TypeScript.

WalterBrighttoday at 6:38 AM

Translating code to C usually results in some nearly unreadable code. I submit the C++ to C translator, cfront, as evidence. I've looked into using C as a target backend now and then, but always "noped" out of it.

I was pleasantly surprised to discover, however, that C code can be readily translated to D.

show 1 reply
Onavotoday at 2:38 AM

Does it work with the preprocessor?

MegagramEnjoyertoday at 3:10 AM

This is a bit too barebones. At least bring goroutines dude

show 1 reply
Sarthakofficialtoday at 5:44 AM

[flagged]

melodyogonnatoday at 8:11 AM

[dead]