9 ms·
IMHO those "language designer trivia" are interesting to read and think about but in the end irrelevant for popularity (and I think Zig will be popular). My per
by flohofwoe 6y ago
IMHO those "language designer trivia" are interesting to read and think about but in the end irrelevant for popularity (and I think Zig will be popular). My personal favourites so far are:
- The language is really simple and "enjoyable". Writing C++ often feels like puzzle solving to me even after 25 years. From the little Rust I've written so far, I got the same impression. Writing Zig is like writing C or Go but even more straight-forward. The language completely "disappears" while coding.
- The simple integration with C, Objective-C and C++ doesn't get enough credit (disclaimer: I haven't tried C++ yet). Even if Zig aims to replace C, I think the reality will be that most cross-platform / "cross-language" libraries will continue to be written in C, and most "serious" Zig projects will actually be mixed-language projects. Most other languages are too much trapped in their own ecosystem and aim to "rewrite the world" (which won't happen of course).
- Integrating the build system into the compiler and standard library is the right way to do it (not a feature unique to Zig, but if the C/C++ world is looking for the right way to solve the "build system problem", this is it).
...lots of other cool stuff in Zig to write about such as the incredibly simple module system, the comptime-, reflection- and generics-features, but IMHO the only feature that really counts in the end is: ergonomics.
This is the one thing that matters and where Zig beats the more "powerful" alternatives.
- samatman 6y agoTo add to what you're saying, Zig (and only Zig) is a plausible contender for replacing C, exactly because consuming a Zig .o file from C is roughly as simple as consuming a C .o from Zig. So if you have a C program, and you want to dip your toes in Zig-land by writing the next library in Zig, you just can. If you chose Rust instead, you're going to have a bad time.
- drewm1980 6y agoLearning how to write memory safe code in Rust is a challenge at first, but it buys you access to an ecosystem of transitive dependencies that are (mostly) efficiently implemented and interconnected through memory safe API's. That advantage remains even if you have you have to manually define an unsafe C API for the rust code you added to your codebase.
- fluffything 6y agoThe same is true for C++, Rust, etc. Obviously, you can’t expect people that didn’t managed to learn these languages to know that. But if that’s your killer Zig feature, lots of languages have it.
- MaulingMonkey 6y ago> If you chose Rust instead, you're going to have a bad time. Naw. /* main.c */ #include <stdio.h> #include <stdint.h> uint8_t answer(); int main(int argc, char** argv) { printf("%d\n", answer()); return 0; } // example.rs #[no_mangle] extern "C" fn answer() -> u8 { println!("The answer is:"); 42 } # test.sh rustc --crate-type staticlib -o example.a example.rs gcc main.c example.a -lpthread -ldl ./a.out $ ./test.sh The answer is: 42 Workflows using `cargo` instead of `rustc` are also sane and easy.
- deleted 6y ago[deleted]
- pasabagi 6y agoI found it very difficult to deal with C macros, though. That said, I have no idea how zig deals with that problem either.
- exyi 6y agoThis seems like unsolvable problem - if you'd want to allow calling C macros from your new language, you would have to be C superset. So no memory/thread/... safety, weird syntax inherited from C, ...
- rcxdude 6y agoIt's probably impossible in general, but you could probably deal with a bunch of common cases fairly easily (like constants)
- skohan 6y agoThis was one of the most redeeming things about Objective-C. It is a superset of C, and when I was working with it, I found myself writing the high-level stuff in ObjC, but with a lot of pure-C functions sprinkled in. It was really nice for working with C libraries like OpenGL, because you could find an example online and directly apply it without going through any kind of translation step. It was a really cool feature to have.
- NOGDP 6y agoWhat are the flaws/weak points of Zig?
- ternaryoperator 6y agoThe ones I've seen are not Zig-specific, but rather attendant to any language in early stages: a small development team, very limited tooling. (To be fair though, the dev team has done an amazing job banging out good code.)
- rubiquity 6y agoI love Zig. Occasionally I wish it had interfaces because that’s how my brain designs software components. You currently achieve the same runtime characteristics of interfaces by using a function property on a struct. It’s a great language though and a ton of fun. It’s so easy to dive into a codebase quickly which I value as a very distracted dad. The standard lib is a joy to read too.
- throwaway17_17 6y agoCan you explain what you mean when use the term interfaces? I’m just curious as to what your describing. Also, do you mean use a function property on a struct in Zig specifically to capture the operation of such an interface?
- deleted 6y ago[deleted]
- mypalmike 6y agoI assume interfaces refers to runtime polymorphism.
- deleted 6y ago[deleted]
- AndyKelley 6y agosearch for "design flaw" on the issue tracker
- creata 6y agoMaybe C "disappears" while coding, but I'd much rather it stuck around to help me out. When writing C, I have to carefully make sure that each resource has been freed/closed (but not too soon!), that I'm not mutating or holding onto anything I'm not meant to, that I've accounted for every exception that I can result from a given call, and so on. Can Zig handle some of that bookkeeping for me?
- crowhack 6y ago"I have to carefully make sure that each resource has been freed/closed (but not too soon!)" You can use defer keyword to free right after allocating and it won't be called until the function/program completes. You can use debug or testing allocators to ensure no memory is left unfree'd or double free'd. The std lib has a large selection of custom allocators that you can use depending on your needs. One great one is an "Arena Allocator" which is just a linked-list of allocations that can be free'd at one time, versus tracking all these individual allocations. And if none of these allocators fit your needs, the interface to define one is pretty easy to implement. https://ziglang.org/documentation/0.7.1/#Choosing-an-Allocator https://ziglang.org/documentation/0.7.1/#Choosing-an-Allocat... "I'm not mutating or holding onto anything I'm not meant to" Not really sure Zig can help you with this one. With great power comes great responsibility, or something like that. "that I've accounted for every exception that I can result from a given call" Zig does not have exceptions, but it does have error types which functions can return. From the function definition you usually can determine all the errors that can possibly be returned, unless the function definer use'd the catch all ! error type. Regardless, it is still much better than regular exceptions because - you know by the function def that an error could be thrown, the compiler forces the caller to account for a possible error by "unwrapping" the return value - an error happening just passes back a different type to the caller and in combination with the above, you can never "miss" an error https://ziglang.org/documentation/0.7.1/#Errors https://ziglang.org/documentation/0.7.1/#Errors Also Zig switch statements without an else ensure you handle every possible value so if you forget to handle one possible error (based on the type), it will throw a compile error. https://ziglang.org/documentation/0.7.1/#toc-Exhaustive-Switching https://ziglang.org/documentation/0.7.1/#toc-Exhaustive-Swit...
- fctorial 6y agoRust is a lot easier than C++, although there is an initial slightly steeper learning curve.
- djeiasbsbo 6y agoIt's hard, coming from C because C is a small language with not many keywords. As a hobby programmer I did not know about generics and such and the differences between pointers and references. Learning Rust kind of feels like brute-forcing my brain until it sticks. But I can't say it isn't fun and exciting!
- deleted 6y ago[deleted]
- stjohnswarts 6y agoRust has a steeper learning curve initially but when you're over the hump you don't see mountains in the distance like you do in C++ :)
- iFreilicht 6y agoAnd I feel like, while Rust also has you puzzle-solve a little and jump through hoops initially, you quickly start to appreciate all the safety that gains you. And I value that a LOT. Though I have to say, Zig looks awesome. Both Rust and Zig get me really excited to code more after getting frustrated with god-awful python codebases.
- jcul 6y agoI'm about to start a little fun project where it would be nice to be able to interact with C++ object files. I was planning on using Nim but might give Zig a try also. It looks really cool. I feel like Nim and Zig both fill a similar niche, maybe Zig aiming more towards the lower level / even embedded. That's just my impression, not having used either in anger. I agree on the C++ puzzle solving thing, though in a way it's almost part of the appeal!
- xigoi 6y agoAs a Nim user, I think Nim and Zig fill quite different niches. Zig is made specifically for low-level programming with some higher-level constructs, whereas Nim is very general-purpose.
- fluffything 6y agoIf this is a language for people that didn’t managed to learn C++, D or Rust... lots of questions quite unfavorable for Zig pop up. I’d just remove that sentence. even if the language is great, if all the ecosystem is written by people that didn’t manage to learn C++ in 25 years, I can’t really trust any library there