Live data from Hacker News

Solod: Go can be a better C

solod.dev

1–10 of 188 posts

Re: Solod: Go can be a better C

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

Re: Solod: Go can be a better C

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

Re: Solod: Go can be a better C

#4
post #3

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.

[deleted]

Re: Solod: Go can be a better C

#5
post #3

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.

Well, it does say:

"Everything is stack-allocated by default; heap is opt-in through the standard library."

So it supports both stack and heap, and I guess static allocation too.

Re: Solod: Go can be a better C

#8
post #3

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.

Exactly as well as C does, it seems.

    func newPerson() *Person {
        p := Person{Name: "Alice", Age: 30}
        return &p
    }
becomes

    static main_Person* newPerson(void) {
        main_Person p = (main_Person){.Name = so_str("Alice"), .Age = 30};
        return &p;
    }
Quoting the FAQ: "So itself has few safeguards other than the default Go type checking. It will panic on out-of-bounds array access, but it won't stop you from returning a dangling pointer or forgetting to free allocated memory. Most memory-related problems can be caught with AddressSanitizer in modern compilers, so I recommend enabling it during development by adding -fsanitize=address to your CFLAGS."

So saying you get the "safety of Go" is a bit of a stretch.

Re: Solod: Go can be a better C

#9
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.)

Re: Solod: Go can be a better C

#10

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

I’ve been considering using Odin and Raylib for this because of its similarities to Go, but using Go itself is appealing. Do you have any good resources for what you’ve learned, or is it an unexplored frontier?
Post reply on HN