logoalt Hacker News

Solod: Go can be a better C

197 pointsby koenglast Monday at 4:38 PM133 commentsview on HN

Comments

ventanatoday at 7:02 AM

Translating a language into a different language is a popular thing to do these days, but still not a very easy one. I feel it's like peeling an infinite onion of misery. First, you write a parser of your source language, figure out the translation of the instructions, and emit the code in the target language, and you're very happy when your translated Hello world compiles.

Then, a user (like me) tries writing something like

  package main
  
  func main() {
    register := 42
    println(register)
  }
well, oops.

  /tmp/solod_build3904763637/main.c: In function 'main':
  /tmp/solod_build3904763637/main.c:6:21: error: expected identifier or '(' before '=' token
      6 |     so_int register = 42;
        |                     ^
  /tmp/solod_build3904763637/main.c:7:29: error: expected expression before 'register'
      7 |     so_println("%" PRIdINT, register);
        |                             ^~~~~~~~ (exit status 1)
OK, now you grab the list of reserved words of the target language, which is not always an easy thing to do, and rename type names and variables as needed.

The next bad thing is when you step on your own toes and see that the new names you invented, like `so_int` or `so_println`, will inevitably pollute the global namespace. We'll either cross our fingers and hope that no one will create a variable named `so_int`, or we'll need to add all our new kind-of-reserved words to our already big list of exceptions.

I'm sure there are multiple levels of complexity beyond this.

Not trying to say that seeing a bunch of new translators from language A to language B is bad: not at all! It really seems that this is one of the popular usages of the agents, and a rewarding one. But doing it without hidden bugs is kinda hard.

show 5 replies
pjmlptoday at 5:19 AM

Go is a better C already, designed by C authors themselves, with other UNIX key figures.

Which while some of the design decisions might be debatable, they actually knew what C is all about, informed by their own experience with what worked in C, Alef and Limbo, across UNIX, Plan 9 and Inferno.

show 2 replies
kitdtoday at 5:56 AM

The idea of using a subset of an existing popular language is very wise IMHO. We can (and apparently are) debating the merits of the language runtime, but what a subset gives you is immediate access to a large pile of existing tooling that you'd have to write yourself, eg linters, formatters, lsps, etc. Stuff that is purely source-oriented.

That hadn't really occurred to me before.

aarvin_roshintoday at 1:28 AM

The author's original blog post, which goes into some more detail: https://antonz.org/solod

benjiro29today at 11:25 AM

The problem with these type of new / transcompile languages is not the langue, its the lacking libraries and 3th party assets. Great if just want the most basic hello world programs, but the moment you need ... for example a http server. Then your often with:

a) none

b) http 1.1

c) ... forget about more

Maybe you need rar support ... O well, ... And then you always enter the world where you need to start linking external libs, and then your mixing not just the base language and the transcompile but also whatever interface for calling those external libs.

Ironically, with LLMs being around, your often better to just have it write whatever is missing. Until you find out then, that the language misses some feature.

O great, you needed crypto support. Ok let the LLM write it for you, its only 100x slower then whatever was written years ago and had tons of enhancements and edge cases fixed.

At that point, you can just tell a LLM to write in C from the start, and be done with it. lol.

Transcompile languages have always had tons of issues, and there is a reason why non became popular. Haxe comes to mind. How many years this exist and barely anybody knows it. Because your often just better writing in the original language and fixing the issues, or picking a better fitting language for your project.

show 1 reply
bb88today at 12:19 AM

How does it deal with pointers if everything is stack based? You can't really return a pointer to something on the stack because it could get overwritten between when you return it and when you access it.

show 3 replies
gnulltoday at 5:23 AM

> So is for Go developers who want systems-level control without learning a new language. And for C programmers who like Go's safety, structure, and tooling.

Wut?

Also, how do you preserve garbage collector semantics without garbage collector?

show 1 reply
RossBencinatoday at 6:49 AM

The "a better C" meme needs to die. It's ill defined. Everyone wants something different. For me, GC disqualifies any language as a better C. Bjarne Stroustrup promoted C++ as a better C. But C++ killed off some of C's killer low-level features like type-punning via unions. Indeed it's only in recent years that low-level memory manipulation, such as std::start_lifetime_as and the implicit lifetime rules were standardised. The whole strict aliasing fiasco made C and C++ permenantly worse. Some people say Zig is a better C, but it is certainly not a minimal language, if that's how you define better. For me a better C would have an abstract model that matched machine-level memory access (i.e. no type-based alias analysis) would be as minimal as C in terms of feature set, would clean up C warts like operator precedence, and would be as deterministic as possible (e.g. deterministic memory layout, including bit fields, would be possible without hacks)...

show 1 reply
throwway120385today at 1:05 PM

Does it generate the same extremely fat binaries? I've seen Go binaries get into hundreds of megabytes for things you could do with C/C++ with a few megabytes. Most of it seemed to be string tables and other things that could be reduced but not eliminated with compression.

show 1 reply
ericydtoday at 1:19 PM

I know this is probably a bad question but it says that this language would be good for C developers who like Go's safety. Isn't Go's safety achieved by its garbage collection, which is eliminated in this language? What elements of Go are safer than C which would be preserved in this subset language?

Rexxartoday at 11:23 AM

Very interesting. I have a personal experimental project to convert go to c++ but it's less advanced than this (https://github.com/Rokhan/gocpp). My initial intention was to manage garbage collector with some smart pointer or something like Boehm GC but I've still not reached the point where it's the main problem to solve.

leecommamichaeltoday at 12:02 AM

I really like this idea. I was reading a post earlier about how Go generics are implemented, and how they're sort of leveraging root GC-types in the "runtime" to avoid the same bloat as monomorphization causes in, say, C++. I wonder how Solod will do that? I guess plain monomorphization? I guess that's fine since C compilers are so speedy.

jay_kyburztoday at 1:31 AM

I've been using Go and Raylib to make a game lately and I really don't have a problem with garbage collection. It's so fast that it's not having an impact on my frame rate.

I was a little worried at the start because nobody would normally consider Go for games, but I did a bunch of tests and found it's just no big deal.

(I'm focused on game play and not interested in pushing hardware to its limits.)

show 1 reply
pillmillipedestoday at 7:41 AM

I doubt that it can. so in addition to C's quirks (which I know about), I have to care about go's quirks and solod's quirks as well? and for what? there's no solod-to-regular-go interop aiui, so just some tooling and the standard library?

raluktoday at 6:35 AM

At first glance looks like stipped C++ with minor differences. For example go have row polimorphism compared to OOP in C++. What else is there that C++ does not have?

djha-skintoday at 2:52 AM

It cannot be a better C. You cannot implement exceptions in it using set jump for example, but the biggest problem is memory management. You can't implement your own arena allocator in golang.

show 2 replies
faangguyindiatoday at 1:45 AM

i've been using Go on backend now all the time.

Wish something like this existed instead i am stuck with flutter and react native on Mobile.

When will a time come when i can use some functional languages like Haskell or a plain boring language like Go for making apps with OTA ability for mobiles.

As vibe coding takes over, app store approval will become slowerer and OTA is really great when you need to make quick changes!

You can OTA each day and do base app release to store once each week.

i think this maybe the space where very little work is being done.

show 1 reply
Decabytestoday at 12:20 PM

I did this with a python languah

heyitsdaadtoday at 1:13 AM

Insert Look What They Need To Mimic A Fraction Of Our Power meme here.

rao-vtoday at 7:35 AM

Arn't goroutines the killer feature of go? Don't see how you'd get them with this approach.

Onavotoday at 2:14 PM

Does it support pointer arithmetic?

throwaway81523today at 10:14 AM

This looks silly. It's about a Go subset with no GC and various other restrictions that make it map onto C. But then you have most of the problems of C. It's unclear what the advantages are supposed to be. Rust or Ada seem way preferable, depending on the application area.

pulkastoday at 9:11 AM

bun tried hard to be written in zig.

eventually, they fell back to rust.

there's a lesson here: subset languages are fine for experiments and small projects, but they're rarely the right choice for production software.

...and C still can't be replaced. it's still the language of choice for mission-critical systems and low-level problem solving.

show 4 replies
ghthortoday at 4:31 AM

This is a very exciting project; love writing go with the tooling, but I miss writing C from my getting started days

jdw64today at 9:02 AM

NO Developers who use a particular language reshape their mental model to fit that language. Go is centered around its runtime. If you switch to C11, do you really need to be thinking about a goroutine scheduler, never mind garbage collection? Even just looking at example code, would a Go developer ever think defer pool.free is necessary? The mental model is completely different.

pulkastoday at 9:07 AM

no it cant.

Panzerschrektoday at 5:42 AM

Yet another attempt to reinvent a better C. Curious, but unpractical. If one need a better C, C++ should be used instead.

show 2 replies
smalljelly2018today at 7:46 AM

[dead]

kyo5uketoday at 10:54 AM

[flagged]

thot_experimenttoday at 3:41 AM

It cannot. C is a wonderful language that makes me smile every time I pick it up. A truly universal tool that lets you go wherever your heart desires. Go is a prison designed to enforce a bleak uniformity on all of it's users. For only by painting everything a uniform gray can we ensure we are all equal.

lionkortoday at 9:19 AM

Go is not like C in any way. It doesn't feel like C, it feels like C# with mediocre syntax changes and extremely explicit error handling -- like someone took the bad parts of C and added them to a high level language.

I don't get it at all. Green threads are cool, but again, it's easy to write unsafe concurrent code in Go, so why would I choose it over e.g. Rust (where its hard to write unsafe concurrent code) or C++ (which gives me more control)?