5 ms·
I believe Zig takes a more nuanced and balanced approach to memory safety as a spectrum, rather than the extremes you present of either GC or borrow checker. F
by _vvhw 5y ago
I believe Zig takes a more nuanced and balanced approach to memory safety as a spectrum, rather than the extremes you present of either GC or borrow checker.
For example, Zig offers spatial memory safety, and provides test allocators to catch temporal memory safety issues. That's already an order of magnitude improvement over C.
Memory safety is also just one aspect of safety, whereas sometimes programmers conflate the two. It's important, but things like checked arithmetic should also be right up there, and should be enabled by default in safe build modes. I think Zig's approach here is also spot on, having worked a little in security, where an integer overflow can be almost as dangerous as a buffer overflow. Yet I don't see many other languages taking checked arithmetic as seriously as Zig does.
- pjmlp 5y agoAda, Modula-2 and Object Pascal, minus compile time execution that they lack, and you have Zig almost 40 years ago. Sad that we have to go in circles to keep programming fashion going, instead of adopting best practices from the get go.
- deleted 5y ago[deleted]
- kristoff_it 5y agoA language isn't just a compiler and a spec. I don't know the full history of all these projects, but IIRC Ada's compiler wasn't free for a long time. How you structure the financials and the community around the language has also a gigantic impact on the final result, and this is an area where Zig bringing to the table something completely new. https://ziglang.org/zsf/ https://ziglang.org/zsf/
- pjmlp 5y agoAlthough most people associate Object Pascal to Borland due to the Turbo Pascal branding done by them, the language was originally created to write Lisa OS (Clascal), and then when the project got replaced by Mac OS, with the help of Niklaus Wirth input, Clascal became Object Pascal and was the main language until the C++ rewrite that took place in the early 90's. Outside Apple computers, the dialects created by Borland gained such following, specially in Europe, that Turbo Pascal became the official Pascal dialect, even though Extended Pascal fixed most of the original design flaws. Naturally they going enterpreisy lost the crowd to VB and VC++ folks (later .NET). Modula-2 did have some nice offerings, specially on Amiga, but on the PC and Mac, Turbo/Object Pascal made it irrelevant as it offered all the improvements Modula-2 brought to the table (no one cared about co-routines on home computers back then). Ada was the only one from those that yeah, actually quite expensive, and I think only SGI and SUN had UNIX compilers for them, with HP having BASIC and Pascal compilers for their OSes. Then there was the Amsterdam Compiler Kit, the "LLVM" for the 1980's, which had support for C, Pascal, Modula-2, Occam, and BASIC. Looking forward to see how Zig evolves, specially regarding issues like #2301.
- klyrs 5y agoYou say "minus compile time execution"... but when you take comptime away from Zig, you lose both generics and compile-time reflection. The remaining language is C without a preprocessor. So, yeah. Strip out the most useful and innovative feature from the language, and it looks primitive.
- pjmlp 5y agoThe languages I mentioned all got generics during their lifetime, so yeah they were all more powerful than C. C won due to UNIX, had UNIX not been a kind of free beer that companies could build their workstations with and universities avoid paying for commercial OSes like VMS, history would have taken a different path.
- klyrs 5y agoWhat about compile-time type reflection? Also, lisp has pretty much always been more powerful than C. But what zig brings to the table is an extremely simple language which is also very powerful. Much of the power results from the entire language being available at compile time. You seem so ready to throw that away in favor of could-have-been nostalgia, I wonder if you've taken the time to understand what you're criticizing.
- pjmlp 5y agoI was quite clear that compile-time type reflection was the only thing missing. Zig isn't the only AOT compiled language with compile-time type reflection in 2021, and exactly because of could-have-been nostalgia, we don't need newer systems programming languages that don't have an answer for use-after-free in safe code. https://github.com/ziglang/zig/issues/2301 https://github.com/ziglang/zig/issues/2301 https://github.com/ziglang/zig/issues/1966 https://github.com/ziglang/zig/issues/1966 Naturally I have taken the time, and did not come out impressed, given my background and programming language beliefs. However as I say in another thread, other people seem to be happy with such shortcomings.
- pcwalton 5y agoAdding bounds checks and ASan is not an order of magnitude improvement over C. Chrome, for example, is doing all of this already in C++ in a more advanced way than anything I've seen in Zig. Clang offers UBSan [1], which is extremely advanced. Yet it is not enough. It is not a "nuanced and balanced" approach: Zig is simply not memory safe. [1]: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#...
- AndyKelley 5y agoIf you're shipping a game that runs on a player's computer, you're most likely going to make production builds with -O ReleaseFast (safety checks off). Rust is overkill for this use case. The only benefit memory safety brings to this use case is making debugging easier. But if we're measuring how debuggable a language is, there are many more factors, such as iteration speed due to compilation times.
- pcwalton 5y agoMemory safety also adds reliability, by catching bugs statically that you didn't catch during (automated or manual) testing. It's the same argument as for static typing. It's of course true that some developers may judge the tradeoffs differently for their individual projects—that's why they're tradeoffs! But there are benefits to memory safety that go beyond security.
- Shadonototra 5y agothe only memory safety gamedev needs are bound checking and use after free protections everything else is just bloat and noise that hurts iteration time and even if one would still value them, you'd need to check only once for whatever memory check you want to run, when you build your allocators for example, and not at every builds, and you could even write the logic yourself and have a debug allocator to ensure memory safeties you want sub second and not "double digit seconds" build times it takes one to try to make a game to trully understand why iteration time is far more important that anything else (other than performance of course) you don't want to wait multiple seconds everytime you change the speed of your character, or tweak the rendering/AI code that's why then some devs end up using scripting language and they loose all the advantages of their native language, because they want to speed up iteration time that's why i personally stick to D for my game, my engine + game fully rebuild in under 1 second you don't get to create memory bugs when you work on your gameplay code ;)