6 ms·
More or less OT. I keep hearing about both Zig and D as interesting C-like low level languages with better satefies/ergonomics. I wonder if someone who's famil
by sdfghswe 3y ago
More or less OT.
I keep hearing about both Zig and D as interesting C-like low level languages with better satefies/ergonomics. I wonder if someone who's familiar with both would like to discuss the main differences...?
- Sharlin 3y agoZig is C-like. D is C++-like. Zig has first-class compile-time metaprogramming. D is a kitchen sink language; it has many more features than even C++ does. Zig is minimalistic and strictly imperative rather than multi-paradigm. D has a cult following but hasn't really taken off. Zig is a relative newcomer trying to prove itself.
- systems 3y agoi think the term "D has a cult following" is a bit harsh D's community is small, that is it, nothing cult like, they dont over defend D most of the community seem to be happy using other languages etc .. but i agree with D being a kitchen sink language, trying to be many things, but never being the absolute best at anything, which i think is why it never really took off i am really hopeful for Zig, trying to be a more pragmatic C replacement
- Semaphor 3y ago> i think the term "D has a cult following" is a bit harsh D's community is small, that is it, nothing cult like I think "cult following" is used here like you would for movies, it’s not actually cult-like, it’s more that it’s a rather small, close-knit community.
- pron 3y ago> Zig is C-like Only in the sense that the language is simple and small, but C pays for that by being inexpressive (you can find families of C++ programs for which an equivalent C program would require exponentially more code). Zig, on the other hand, is small and simple while being just as expressive as C++. It achieves that through a remarkable observation: many primitive features can be avoided with a powerful enough compile-time computation mechanism with introspection. Zig is so revolutionary in its design that it's hard to compare it to anything else. Or, put another way, any comparison is sure to miss out on some very foundational piece. So yes, in some sense Zig is like C (simple, low-level), but it's as expressive as C++. In another sense, Zig is like Scheme (minimalistic elegance), and yet it feels familiar and it does not rely on macros for its core power. In other ways it's like Go (easy to learn, easy cross-compilation), but it gives full control and is more flexible. At this point, Zig is sui generis.
- 1980phipsi 3y ago> Zig is so revolutionary in its design that it's hard to compare it to anything else. I mean, Zig has an interesting combination of functionality, but I wouldn't say that the individual pieces are revolutionary. Who knows though, the whole could be more revolutionary than the sum of it's parts...
- ngrilly 3y agoZig's take on comptime is quite new (which is the main point of the article being discussed). Error handling and async/await as well.
- 1980phipsi 3y agoZig's take on comptime is slightly different from C++ and D, but that doesn't make it revolutionary. It has first class types, which allows you to pass them to a function along with normal function parameters, instead of having a separate syntax for it like C++ and D. But it's not really new.
- pron 3y agoThat's a little like saying that smartphones weren't really new because we had mobile phones and calculators and cameras and video cameras and handheld games before. Zig's comptime is revolutionary and really new in that it replaces many other separate features and is the basis of Zig's minimalism. Figuring out how to discard features is much more difficult than adding them, and simplicity is something that's impossible to add once it's lost. The message is not the existence of a rather general compile time execution, but that with a particular design of such a mechanism you can do away with other things.
- deleted 3y ago[deleted]
- pron 3y agoTo say something truly original you don't have to invent new words.
- 1980phipsi 3y agoI agree with most of this, but I would say that D was probably designed to be an alternative to C++ or Java. Zig shares many of C's design philosophies, though I think D's syntax is a little closer to C's than Zig's is to C's. D also has a betterC mode that removes some of those "kitchen sink" features, but I couldn't say how popular it's use is. Many people who use D like some of those features. Zig's more minimalistic approach to language features is closer to C's approach. Zig likely has been influenced by D (among other languages), but I wouldn't be surprised if D's new importC functionality has been influenced by Zig. I don't use D (or C or C++) at work, but learning D and using it at home has made me a much better programmer in the languages I use for work. Maybe I would have learned those lessons with C or C++, but I guess I took more easily to D than them.
- Sharlin 3y ago> I agree with most of this, but I would say that D was probably designed to be an alternative to C++ or Java You're agreeing with me then! D was pretty explicitly created due to WalterBright's (incidentally a prolific 60k+-karma HN user!), frustration with C++ and presumably the problems that stem from its requirement to maintain almost a 100% C compatibility. Bright is the founder of Digital Mars, a small company developing C and C++ (and D) compilers, so he has first-hand experience. Since 2007 D has been co-developed by Andrei Alexandrescu, a well-known C++ expert and one of the pioneers of template metaprogramming.
- esjeon 3y agoD is a GC-based C++/Java-like OOP language. People used to call it "a C++ done right", but it was never simple and didn't have any clear edges against its competitors. TBH, one simply should not build on top of C++ - it's a beast that no one can comprehend, and it only keeps growing. In case of Zig, I think it's a very good modern C alternative. Zig can do what C can do, can interoperate w/ C (e.g. importing C headers), and offers new features that are useful (comptime, slices, error type). It's like Go, but without GC and a large runtime.
- sdfghswe 3y agoOh many I was loving your description of Zig up until when you said "it's like Go"...
- Guvante 3y agoI haven't heard of Zig referred to as like Go except in the concept of trying to replace C. (Rust is more aiming for C++)
- esjeon 3y agoYeah, it may sound weird, but there were days when Go was considered a C replacement - which turned out to be quite false. There’s a dialect - TinyGo - sorta carries the old vibe(?), but the upstream never picked up the idea.
- optymizer 3y agoHaving written a few toy compilers for C, to me D is the most elegant of the C families of languages. For example, consider the versatility of the '.' operator. It does pointer dereference, static field access and class/namespace member/method access. In all those cases I want to access "a thing from this other thing". Having 3 operators in a language (., ->, ::) is easier for a compiler writer but it puts more cognitive load on the developer. Now consider type extensions. As a language designer you could think: "if a developer wishes to add methods to a type Vector that exists in a third party library, then in their project, the developer would use some special syntax" like maybe: class Vector { void json() { ... } } and maybe the developer also needs to have it even repeated across a header file and an implementation, but... why? It's an idea, but it's not a law of the Universe. There is a better way. Instead, the compiler can help you out. Just declare a regular function anywhere like so: void json(Vector v) { ... } which is not special in anyway, and then be free to invoke it as: json(v); or v.json(); Why if it isn't our familiar dot operator! It also does type extensions via some syntax sugar? What an elegant solution. This is just one feature of D, and it's filled with features. Though I don't really use D in my day to day work, it's wonderful to see how the authors thought about hard problems in language design and implemented elegant solutions. I think D deserves more recognition for the things it absolutely hit out of the park as a general purpose programming language.
- ksec 3y agoWell WalterBright could have answered that. But since HN has started taking a piss out of WalterBright replying in every single Zig ( or Rust ) threads he stopped commenting on most if not all Programming languages topics. Sigh.
- saagarjha 3y agoThere are productive ways to comment on threads without being a shill for your own thing.
- deleted 3y ago[deleted]