After using zig for a few projects, it's amazing how it feels similar to C when coding.
The feeling to micromanage every details instead of focusing on the actual business logic?
Zig: The Modern Alternative to C
31–40 of 181 posts
Re: Zig: The Modern Alternative to C
#32Earlier quoted context omitted.
The point that paragraph is trying to make but articulates imperfectly is that you explicitly pass an Allocator to the stdlib routines that allocate -- rather than having them allocate on the heap implicitly.
So you have coloured functions? The red that can allocate, and the blue that cannot?
In any case it's not nearly as limiting as the 'red-blue' async-await color split in other languages, and I can't think of a single downside of explicitly passing allocators into stdlib modules instead of having a hidden global allocator.
The approach to always pass allocators isn't all that Zig specific either, it's also a good library design practice in pretty much all other languages which allow explicit memory management.
Re: Zig: The Modern Alternative to C
#33That article is about control flow and syntax, which isn't a big problem. What matters is data. So what does Zig have that C doesn't? - Arrays and slices. A slice is a pointer and a length. There's subscript checking on slices. You'd expect that the preferred operation would be to take a slice from a slice, but the documentation does not mention that option. This may be a documentation error. There is a ".." operator…
> No objects, just structs C doesn't have 'objects' either, just structs. In Zig you can add functions to structs though, and you have UFCS syntax sugar, both together is pretty close to class methods ;) Those sentinel terminated arrays are a killer feature for C API interop, since you don't need to allocate separate C strings on the stack or heap just for passing string literals into the C API (Zig string literals a…
Just being pedantic, nothing to see here.
Re: Zig: The Modern Alternative to C
#34Earlier quoted context omitted.
> No objects, just structs C doesn't have 'objects' either, just structs. In Zig you can add functions to structs though, and you have UFCS syntax sugar, both together is pretty close to class methods ;) Those sentinel terminated arrays are a killer feature for C API interop, since you don't need to allocate separate C strings on the stack or heap just for passing string literals into the C API (Zig string literals a…
Technically C has objects. That's any chunk of memory with a type, size, alignment and duration. Incidentally C++ has exactly the same definition. Just being pedantic, nothing to see here.
Re: Zig: The Modern Alternative to C
#35Earlier quoted context omitted.
> No objects, just structs C doesn't have 'objects' either, just structs. In Zig you can add functions to structs though, and you have UFCS syntax sugar, both together is pretty close to class methods ;) Those sentinel terminated arrays are a killer feature for C API interop, since you don't need to allocate separate C strings on the stack or heap just for passing string literals into the C API (Zig string literals a…
Technically C has objects. That's any chunk of memory with a type, size, alignment and duration. Incidentally C++ has exactly the same definition. Just being pedantic, nothing to see here.
Isn't that just "a variable"?
Re: Zig: The Modern Alternative to C
#36What is Zig's async story? Is there something like Go's coroutines?
No, it's 'code transform' async-await as is fashionable these days, but with the advantage that it's 'color blind' (the compiler will do the async transform or not based on the caller's expectation). See: https://kristoff.it/blog/zig-colorblind-async-await/
Re: Zig: The Modern Alternative to C
#37Earlier quoted context omitted.
Technically C has objects. That's any chunk of memory with a type, size, alignment and duration. Incidentally C++ has exactly the same definition. Just being pedantic, nothing to see here.
C++ has syntax for adding functions to objects and type system support for deriving object types from other object types and overriding those member functions. There are some who consider these a rather important thing.
Re: Zig: The Modern Alternative to C
#38Earlier quoted context omitted.
Technically C has objects. That's any chunk of memory with a type, size, alignment and duration. Incidentally C++ has exactly the same definition. Just being pedantic, nothing to see here.
> That's any chunk of memory with a type, size, alignment and duration. Isn't that just "a variable"?
int * int_ptr = malloc(sizeof(int));
int_ptr is a variable (and also an object), the pointed to memory is an object but not a variable.Re: Zig: The Modern Alternative to C
#39Is it a good alternative to Go? How is interoperability?
It is not an alternative to Go same as C++ or Rust is not really an alternative to Go. They are on a different level, but can do the same job. Though I could argue that Tcl could be an alternative to Go, I think many would not agree. Zig has manual memory management, doesn't have much of a runtime (no CSP out of the box) and above all is not mature yet (breaking changes do happen). As of now it has one of the best st…
TCL is an elegant scripting language, very LISP-y, where most data structures are lists of strings.
Go on the other hand is more like a modern mix of C and Pascal with GC and lots of convenient libraries, and which builds statically.
The performance of TCL and Go are also a world apart.
Re: Zig: The Modern Alternative to C
#40Earlier quoted context omitted.
Technically C has objects. That's any chunk of memory with a type, size, alignment and duration. Incidentally C++ has exactly the same definition. Just being pedantic, nothing to see here.
> That's any chunk of memory with a type, size, alignment and duration. Isn't that just "a variable"?