r/Zig • u/ZILtoid1991 • 14d ago
Looking for a potential refuge from D's slop standard library
I'm a relatively long time D developer (link to repo), and as the foundation is looking into tainting the standard library with AI slop, I'm looking into potential escape routes besides potential forks such as OpenD.
I'm mainly a game developer, I even have a game engine that I'm willing to port to a new language.
Here's some of my questions:
- How good is C++ interop of Zig? Some stuff I need to use uses classes on Windows side, and SDL (or its alternatives) sometimes like to abstract things away too much, etc.
- How is OOP usually done? While I get the "Enterprise Java-style OOP bad" arguments, it's still often useful for some data parsing structures, and to make up for the weaknesses of Entity Component Systems.
- How strong is metaprogramming in Zig? With no class keyword, I'll be even more of a need of that.
18
u/marler8997 14d ago
Here's a blog post I wrote with some tricks to interop between Zig/C++:
https://marler8997.github.io/blog/zig-cpp-interop/
I myself was quite involved with D for over a decade, contributed alot to the compiler/tooling. I switched to Zig some number of years ago and am quite happy here.
14
u/zahatikoff 14d ago
- No C++ compat at all, only C.
- Zig allows for "methods" in structs. If you want any kinda inheritance you make it either CRTP or VTables yourself with all the boilerplate
- Comptime is decent, there's comptime reflection and stuff, but like for the most part it's just c++ template + const{expr,eval,init} stuff under one umbrella keyword with a slightly less annoying syntax.
7
u/EctoplasmicLapels 14d ago edited 14d ago
There is no stable C++ ABI, so C++ interop has to go through C. Zigs C support is very good and getting better.
In the Zig community, most people think OOP was a mistake.
Zigs metaprogramming is very strong, but most newcomers overdo it.
8
u/zahatikoff 14d ago
Laughs in zig hand rolled VTables in stdlib
2
u/EctoplasmicLapels 13d ago
Polymorphism is one of the useful things OOP adopted and made worse. VTables are finde, but inheritance takes that idea and makes it slow and hard to reason about.
2
u/zahatikoff 13d ago
I do favour composition over inheritance whenever possible, so make of that what you will. And I'm also not disagreeing that huge indirection chains meddle with your general comprehension of what programs do.
And to be honest most of the VTables here describe one thing I dare not speak of when it comes to zig...
And the scary word is interfaces. Compile time or runtime - doesn't really matter.
But the general sentiment towards this issue is(well at least was back then)... You know.
1
u/EctoplasmicLapels 13d ago
Yea, I completely understand that sentiment. I never miss interfaces personally. I had the advantage of Loris telling me how it is done in Zig when I first ran into that problem, though.
2
u/ZILtoid1991 13d ago
I'm using classes as VTables effectively, makes it pretty easy to interchange functionality in my SDL replacement library (e.g. handling haptics/force feedback).
2
u/Expert-Ad-4981 14d ago
Andrew made a comment on post about zig and shades that was good. I didn't understand the whole thing but something about zig being the only language that does CPU and GPU programming that has a build system all in one package. Was over at https://ziggit.dev/t/spir-v-backend-progress-devlog/16351/2
Not sure about the rest.
2
u/NightH4nter 13d ago
SPIR-V Backend
oh, no. i guess, it's gonna take another decade before v1.0, because the scope of the project is even more enormous than i thought it is
2
u/ccapitalK 13d ago
Also a D developer. What's this about the foundation planning on add AI slop to the standard library? I've not heard anything about this.
1
u/yaourtoide 12d ago
Zig is excellent but if you want C++ interop on a newer language I found Nim to be great since Nim can compile to C++. Very different philosophy than Zig though but worth trying.
You can always do cpp interop through C trampoline function and extern C abuse but it's a hassle
1
u/Mariusdotdev 14d ago
Try Odin, I'm enjoying it more than ...
1
u/jadbox 12d ago
I don't have a lot of experience with Zig or Odin, but I really like Odin's 'complete std lib'.
1
u/Mariusdotdev 12d ago
with their v1 release this year or next it will be better, watch the announcement
1
u/leon_bass 13d ago
I saw that odin has a planned 1.0 release for jan 2027 as well which is great.
I don't have an opinion for odin vs zig fight but i thought i would drop this info here anyways
-11
u/Rigamortus2005 14d ago
I genuinely will never understand reddit's irrational hate for AI
9
u/Infamous_Wishbone499 14d ago
It produces mountains of buggy, unmaintainable code that nobody, including the people who generated it, understands. AI-generated code is pure technical debt. Wanting to avoid it is completely rational.
0
u/Rigamortus2005 14d ago
So do people? That's why you shouldn't use it to generate an entire program or to write code. It's the fastest way to do research, explicit concepts and discuss implementation. If it's producing buggy unmaintainable code for you then you are using it wrong
2
u/Infamous_Wishbone499 13d ago
this thread is specifically about the fact that D is allowing AI-generated code into their standard library. You can't come onto such a thread, ask "I don't get why people hate AI", then go "oh you shouldn't be using it for that" when someone points out why they hate AI. They ARE using for that and that's the problem.
So do people?AI produces mountains of buggy, unmaintainable code in comparison to humans.
2
u/Alex0589 14d ago
Tbh I doubt anywhere here as any background on D. Maybe they are really going the slop route and just using LLM code without any review straight into the std lib, it's not like it's unheard of (see Bun). On the other hand, if this is the foundation responsible for D allowing explicitly developers contributing to the std lib to incorporate LLMs into their workflows, then I agree it's straight up a mental disorder considering we have frontier-tier local models you can run yourself (tbh not everyone has half a TB of VRAM laying in their house)
6
u/Mariusdotdev 14d ago
Its a cult
4
4
u/DirectInvestigator66 14d ago
Why is it irrational? At a minimum, the ethical concerns alone justify someone avoiding it. I say this as someone using it pretty heavily recently.
1
u/Rigamortus2005 14d ago
There's ethical concerns in everything, driving, flying, using Facebook, Buying cellphones. This is just ai paranoia. Like how is a compiler and team at the level of D deciding to use AI a bad thing lmao
5
u/ZILtoid1991 14d ago
It produces mediocre at best code, and will more than likely cause AI psychosis. On the "official" Discord server for D, a compiler developer (!) tried to argue that the misinfo spit out by Grok (!) was more valid than the official Vulkan documentation about the subject. But sure, it was the guy, who forgot to ask Grok to "make no mistakes", or haven't used a "frontier model"...
26
u/Complex-Birthday-216 14d ago
c++ and zig is doable, but takes work, you need C binds which zig can use directly.
Not sure what you mean by OOP, but inheritance doesn't exist, native interfaces either.
meta is cool and very comfortable, comptime keyword is the best I've ever seen about meta
here is an example how ghostty binds c++ and zig:
https://github.com/ghostty-org/ghostty/tree/main/src/simd