After a complete crashdown with Rust, I decided to leave that language and give it a try with Zig.
Setting up things I will probably manage.
What I would like to know is what IDE I could use and what people are mostly using.
I have some experience with vscode, but debugging was hardly usable (with Rust).
Any editor/IDE which supports LSP (language server protocol) should be fine to get started with, since the main way to get zig autocomplete/linting is via zls (zig language server).
Also, I suggest using a tagged release of Zig (0.13.0 right now) and the matching tagged zls version. You can still switch to the latest stuff from the master branch whenever you feel like it.
For learning a langue, Iād suggest to not worry about IDEs too much. Smart tooling is great at making a language expert faster in navigating large and complex code bases, but it doesnāt generally help with learning.
So, any text editor with Zig syntax highlighting should be enough to get started.
Name: Zig Language
Id: ziglang.vscode-zig
Description: Language support for the Zig programming language
Version: 0.5.9
Publisher: ziglang
VS Marketplace Link: Zig Language - Visual Studio Marketplace
From there it can manage the zig compiler installation for you (press ctrl + shift +p and āinstall zigā) (if you wish) but it is also very easy to install: https://ziglang.org/learn/getting-started/
So far, the only thing I have needed is VSCode + the Zig extension for VSCode.
I havenāt used debuggers for any language really, perhaps I am missing out.
My suggestions would be to use Vim or Helix, if you like modal editing, I think both editor pair really well with Zig, I go very bare with both, just a theme, the lsp mostly for navigation, and voila. The stdlib is a great place to read and look at idiomatic Zig, you can also feel free to ask here if you have any trouble, this is how Iāve learned the language, for the most part.
Okidoki, Thanks for the answers. I will certainly look at some alternatives and ideas, but probably go for vscode at first.
First I will setup everythingā¦ Be back later, probably next week.
Ok thank you clear, so every struct field is public (!).
In the same directory as my main.zig is now the valid declaration inside rnd.zig.
Why canāt I import
in main.zig
const std = @import("std"); // works
const rnd = @import("rnd"); // does not work
Ok thank you clear, so every struct field is public (!).
Yes, there are not private struct members in zig. Granted modules can be private, so if you are exporting a library, not everything will be visible to the consumer of the library.
One of the reasons is that when you pass around a struct instance, the data is there, so thereās no real guarantee that someone wonāt go in and fiddle with it. As such, rather than provide a somewhat empty promise of privacy, it is on the part of the developer to declare through documentation what is private and what is public.
FWIW, I donāt 100% agree with these arguments, but once you get used to it, itās not a huge deal. It however can be a problem when working with a data structure and not knowing that the internals should not be messed with directly. ArrayList is a common example, where iāve seen many help questions raised because someone was directly modifying the internal buffer of an arraylist rather than using the apiās available.
If you want to see Andrewās reasoning about this, you can read this comment.
Okā¦ Stuff is working but a lot of stuff is not.
In vscode I can run main
and also build zig build-exe main.zig -O ReleaseFast
I also installed āZig Languageā
vscode has an insane amount of options and I cannot distinguish what is vscode and what is Zigā¦
Still missing:
I cannot debug. Is it possible? And how?
Is zig format built in into my zig installation?
I donāt use any formatting because the code gets asymmetrical. (yes the format everyone seems to prefer).
Is it possible to adjust something so that braces are always on new lines?
What is the best way to output the assember code next to my exe? And Is it possible to find the methods in between all the asm statements?
Refactoring / renaming is buggy. Which piece of software is responsible for that?
I would be most grateful if these things can be solved.
After that I will probably have to dive into creating a ābuild.zigā file.
I donāt know about how to set it up on vscode, but Iāve used codelldb (which was made for vscode) to debug zig in neovim.
Is zig format built in into my zig installation?
I donāt use any formatting because the code gets asymmetrical. (yes the format everyone seems to prefer).
Is it possible to adjust something so that braces are always on new lines?
Zig fmt is part of the zig compiler. Itās not required like go, but there are no configurations for it. You either take it or leave it. You might have to turn off auto format in vscode.
Refactoring / renaming is buggy. Which piece of software is responsible for that?
generally language servers handle code actions like rename/etc. Iāve not had many issues with the rename feature, what problems are you having?