3 ms·
The author mentioned zig. And zig would get this right you can just write `setThreatLevel(.midnight)` But where zig breaks down is on any more complicated infe
by pacaro 2y ago
The author mentioned zig. And zig would get this right you can just write `setThreatLevel(.midnight)`
But where zig breaks down is on any more complicated inference. It's common to end up needing code like `@as(f32, 0)` because zig just can't work it out.
In awkward cases you can have chains of several @ statements just to keep the compiler in the loop of what type to use in a statement
I like zig, but it has its own costs too
- atiedebee 2y agoI'm not very in the loop regarding zig at the moment, but coming from C I would think you could just use 0.0 or 0.0f? Is that not the case?
- frankjr 2y agoDepends on the context but in general Zig wants you to be explicit. Writing 0.0 is fine at comptime or if you're e.g. adding it to an already known float type, but defining a runtime variable (var x = 0.0; ...) will not work because x doesn't have an explicit type (f16, f32, f64, f80, or f128?). In this case, you would need to write "var x: f32 = 0". You could write "var foo = @as(f32, 0)" but that's just a weird way of doing things and probably not what OP meant.