Comments by "" (@pierreollivier1) on "Is 2024 The Year Of Zig ?" video.
-
25
-
2
-
1
-
@maleldil1 From my own experience, I vastly prefer Zig over C. I've been doing C for years, and it's just not a good language. Zig offers better ergonomics, and tooling, to help us be productive. There are a range of errors that are hard to make in Zig when you have a C background. Zig is ofc still a young language. But it's by far the most promising than any of the new languages I've tested, except for maybe ODIN which is really good but doesn't really align with what I believe a programming language should do. Zig is also far more predictable when it comes to the assembly output. It's easily readable, and cheaply testable. The std is filled with a ton of different DTS for quick prototyping and experimentation. Some solid testing and debugging tools, builtin sanitizer, etc. I love Rust too and I think it's a fantastic language, but I think it's a matter of philosophy. I prefer to have high level of control over my code. I think Rust is amazing at rewriting stuff, but Zig is definitely the one I would choose to replace C.
1
-
1
-
@earx23
This is how you would do it in C for toy projects, it's so easy and so good.
const std = @import("std");
const my_c_source_files = [_][] const u8 {
"src/main.c",
"src/helper.c",
"src/error.c",
"src/server.c",
};
const my_c_flags = [_][] const u8 {
"-Wall",
"-Wextra",
"-Werror",
"-fsanitize=memory",
"-fsanitize=integer",
"-fstrict-overflow",
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "my_app",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true, // you can statically link libc
});
// this works like a for each
for (my_c_source_files) |file_path| {
exe.addCSourceFile(.{
.file = .{
.path = file_path, // you add your path
}
, .flags = my_c_flags, // your flags
});
}
Plus on top of that with the zig build system and the ability to interract and talk to C you can use Zig's integrated testing framework to call and test your C code easily. It's so cool. and managing dependencies is not an issue anymore you can just use build.zig.zon to describe where to fetch your dependencies
1
-
1