💾 Archived View for bbs.geminispace.org › u › drh3xx › 1481 captured on 2024-05-26 at 16:52:46. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-10)

🚧 View Differences

-=-=-=-=-=-=-

Comment by 🐐 drh3xx

Re: "Zig and Vlang?"

In: s/OpenBSD

@jeang3nie the main draws of vlang for me are: 1. immutabilty by default, 2. heavily inspired by go, 3. work on a standard ui module and 4. unlike zig it has a pkg system much like go, rust etc... zig definnately has more momentum though and has the advantage of multi os/arch targets out of the box with great c integration (even targeting several libc implementations) without resorting to something like ffi or cgo.

🐐 drh3xx [OP/mod]

2023-06-03 · 1 year ago

4 Later Comments ↓

🦀 jeang3nie · 2023-06-03 at 12:45:

@drh3xx I can see the appeal of an included ui module, since that is something lacking in a lot of newer languages. As for immutability by default:

var x = 5; // mutable
const y = 42 // immutable

That's pretty easy to work with to me. Coming from Rust before I started working with Zig I was so used to keeping things immutable wherever possible that I got in the habit of using `const` until I ran into a spot where it wasn't possible. It's nice that Zig allows to do things like this (which is very Rust-like):

const res = if (x == y) "yak" else "buffalo";

This type of pattern can work even with blocks or loops, and includes features like breaking out of an outer loop from an inner loop using labelled blocks. All of it leads to 99% of the time being able to use const instead of var.

One thing Zig took from Go is `defer`, which makes cleanup code nice and easy.

const w = "world";
const hello = fmt.allocPrintZ(allocator, "Hello, {s}!", .{w}) catch return;
defer allocator.deinit(hello);

I think Zig borrowed from a lot of places ranging from C++ to Go to Rust. It even influenced a few recent Rust features (Rust got labelled blocks a few releases back). Anyway, I'm pretty sure that even without saying it explicitly most of these newer languages have cross pollinated with each other a lot.

In the end it's really just bytes though, so if you like the way V lets you work with them that's totally fine.

🐐 drh3xx [OP/mod] · 2023-06-03 at 16:42:

@jeang3nie yeah I can use const; the (admittedly only potential) problems are when you forget to use const and then either yourself or a contributor change a var/pointer/etc... which should never have been changable. Imutability by default is just another nice safety net but not essential. The fact Zig has a nice built in test framework is a big plus for it. Defer is definately a nice addition to any language. I think I'm leaning more toward Zig even though it's going to need work on OpenBSD; I did spot the Capy UI toolkit which needs some work too but seems usable for basic GUI cross platform even now.

🦀 jeang3nie · 2023-06-03 at 16:53:

@drh3xx capy is using gtk3 under the hood, but doesn't provide anywhere near the functionality of using gtk directly. I had hand written bindings to gtk3 and vte that were being used in Zterm, but I always knew that was a dead end. The best gtk path in Zig right now is zig-gobject. It's doing what I really should have done and using gobject-introspection to machine generate the zig bindings.

— https://github.com/ianprime0509/zig-gobject

🐐 drh3xx [OP/mod] · 2023-06-03 at 17:04:

@jeang3nie thanks for the link I'll check it out later.

Original Post

🌒 s/OpenBSD

Zig and Vlang?

💬 drh3xx [mod] · 11 comments · 1 like · 2023-06-02 · 1 year ago