News for hackers. Stuff that matters.
Re:Zig 0.3.0 Released by unique_id on Friday September 28, 2018 @11:08AM (#18093974)
If anyone is interested, I'm using Zig full-time. I switched from C# to C++ for game development but I had immense difficulty accepting the language, so when I heard of Zig I gave it a go and I've been very happy with it.

This is a serious project that I'm working on. The 'engine' uses the Vulkan graphics API, cache efficient design, scales to the number of cores, game logic is multithreaded, AVX is used, and so on.

I only mention this to hopefully get people interested in Zig. I'm not ready to share screenshots yet and I'm certainly not going to be advertising my game here.

Re:Zig 0.3.0 Released by keldaris on Friday September 28, 2018 @11:31AM (#18094199)
I've followed Zig's progress with some enthusiasm, but would have considered it too immature for a serious project at this point. In that vein, a few questions about your experience:

1) What's your workflow like in terms of tooling? Coming from C# and C++ people are typically used to great IDE support, debugging and profiling tools, etc. Zig doesn't have any of that. How do you work around it and do you find the experience reasonably productive?

2) How do you deal with the language still rapidly evolving? Do you run the latest nightlies or freeze a particular compiler version and update periodically?

3) What are the most important things Zig gets you over the traditional gamedev approach of using a restricted subset of C++ (in some cases literally just C with function/operator overloading for basic math and a few other convenience features)?

Re:Zig 0.3.0 Released by unique_id on Friday September 28, 2018 @12:14PM (#18094574)
1) When I programmed in C++ I was using Vim and the YouCompleteMe plugin for IDE-like features. Now I use Vim + CTags. For CTags I use the following which uses the Zig standard library to parse Zig code: https://github.com/isaachier/ztags. In the future there will be support for the Language Server Protocol.

2) I git pull every few days to run on the latest compiler. The bugs that I've hit have been minor inconveniences, nothing serious. I think Andrew would agree with you though that Zig is probably too immature for a serious project at this point. The transition to the self-hosted compiler has yet to take place, that compiler is in its infancy.

3) I'm afraid that my verbal inability will never do Zig justice. The built in slices and optionals are really nice. Pointers are non-null by default (but can be undefined). Stack traces on crashes. Much better casting in my opinion (once I got used to it). Error handling that's similar to Herb's C++ deterministic exception proposal. No headers. Not having to decide between fast compile times and comfortable printing. Defer statements instead of destructors or nothing work really well in my opinion. Built in testing (maybe not something you use much in gamedev). +% means add with overflow, + means overflow is undefined. Everything feels nicer, that's as good as I can put it.

edit: You can Ctrl+F "pub fn" to browse all public functions. Great when browsing Github. It's easy to grep for the definition of anything. Overflow and other undefined behavior is detected in debug mode, this saves me so much time. Guaranteed inline is nice. No more make/cmake and manually listing which files to compile.

Re:Zig 0.3.0 Released by keldaris on Friday September 28, 2018 @04:09PM (#18096637)
Thank you for the detailed responses. One, possibly silly, followup question, since you mentioned using AVX. If I understand correctly, Zig deliberately avoids macros, metaprogramming and doesn't have operator overloading. Given those limitations, how do you deal with vector math over different SIMD widths without insane verbosity? I feel like I'd be tempted to write a simple code generator before starting on something like that.
Re:Zig 0.3.0 Released by unique_id on Friday September 28, 2018 @05:07PM (#18097074)
Zig has extensive metaprogramming support.

For SIMD I'm using ispc which is a shader-like language/compiler from Intel. You write your code from the point of view of a single SIMD lane and the compiler takes care of the rest. Intel kind of screwed the project over with their stupid naming and terrible website but it's a very cool project. I take the resulting object file and link it with the rest of the project. This is very different from trusting a compiler to vectorize your code, with a shading language you know it's going to vectorize. What's absolutely brilliant is when you start to use divergent control flow and see how well it handles it.

https://pharr.org/matt/blog/2018/04/18/ispc-origins.html

Re:Zig 0.3.0 Released by eggy on Friday September 28, 2018 @11:31AM (#18094200)
I am very interested. I support Zig on Patreon, because I really believe Andrew has hit the sweet spot when you are looking at staying with C, or C++, or moving on to Rust, but can't quite get it. I have been playing recently with Lua/Terra for game dev stuff (scriptable and low-level, but no big user base yet), but I am really a Lisp guy. Zig may help me to bridge a few of my toy program ideas and aspirations to go bigger as you have.
Re:Zig 0.3.0 Released by azhenley on Friday September 28, 2018 @11:19AM (#18094083)
Any particular reason why you chose Zig over Nim? Or Go or Crystal?

I've been trying out all of these languages but haven't decided which one to dive into completely.

Re:Zig 0.3.0 Released by TurboHaskal on Friday September 28, 2018 @11:25AM (#18094143)
Nim, Go and Crystal are garbage collected.
Re:Zig 0.3.0 Released by dom96 on Friday September 28, 2018 @12:22PM (#18094625)
Nim has a soft real-time GC designed for game development. https://nim-lang.org/docs/gc.html

I'd also be curious why the OP decided not to use Rust.

Re:Zig 0.3.0 Released by eggy on Friday September 28, 2018 @11:55AM (#18094418)
I tried, and really liked Nim, and I believe the custom GC settings would allow for game dev for the types of games I try and make, however, I am biased against the sort of Python syntax and prefer Lisps or standard C-style syntax. This is totally subjective. I can't speak to Go or Crystal, although Go looks like C to me!
Re:Zig 0.3.0 Released by techntoke on Friday September 28, 2018 @02:48PM (#18095955)
Please PM or share with me some more info. I am interested in possibly using Zig for a UI Vulkan framework.