# Code review : my first zig project

**URL:** <https://ziggit.dev/t/code-review-my-first-zig-project/9655>\
**Category:** Help\
**Tags:** language, learning\
**Created:** [April 16, 2025, 8:13am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655 "2025-04-16T08:13:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dru-blip](https://ziggit.dev/user_avatar/ziggit.dev/dru-blip/32/5141_2.png) [@Dru-blip](https://ziggit.dev/u/Dru-blip)\
**Post date:** [April 16, 2025, 8:13am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/1 "2025-04-16T08:13:45Z")

</div>

Hello everyone,i’m a newcomer to zig , im trying learn zig by creating a bytecode interpreter by following [crafting interpreters](https://craftinginterpreters.com/) . i wanted to ask for feedback for my project. please guide me how can i write better and performant zig.  
here the link for the repo :  
[zin](https://github.com/Dru-blip/zin)

---

<div class="post-metadata">

**Author:** ![Justus2308](https://ziggit.dev/user_avatar/ziggit.dev/justus2308/32/5305_2.png) [@Justus2308](https://ziggit.dev/u/Justus2308)\
**Post date:** [April 16, 2025, 9:22am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/2 "2025-04-16T09:22:28Z")

</div>

Hey, very impressive project!

From a code-style pov a lot of your structs should be file-level IMO, e.g. unit.Unit, vm.VM, gc.GC etc. The name doubling is kind of redundant.

---

<div class="post-metadata">

**Author:** ![Dru-blip](https://ziggit.dev/user_avatar/ziggit.dev/dru-blip/32/5141_2.png) [@Dru-blip](https://ziggit.dev/u/Dru-blip)\
**Post date:** [April 16, 2025, 10:07am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/3 "2025-04-16T10:07:20Z")

</div>

thank you very much @Justus2308 for taking the time to check it out.

yeah there is a lot name doubling,i thought it would be cleaner, instead of writing

```zig
const lexer=@import("lexer.zig") 
fn demo(tag:lexer.Token.Tag)void{
}

```

everywhere just make it a type alias thing like

```zig
const Token=lexer.Token

```

use this every where in the file.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [April 16, 2025, 10:17am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/4 "2025-04-16T10:17:58Z")

</div>

they’re talking about having a file called `unit.zig` which just contains a struct called `Unit` when you could make the entire file the struct so instead of ` const Unit = @import("unit.zig").Unit` you would do `const Unit = @import("Unit.zig")`.

what you are thinking of is just aliasing which is totally fine

---

<div class="post-metadata">

**Author:** ![Justus2308](https://ziggit.dev/user_avatar/ziggit.dev/justus2308/32/5305_2.png) [@Justus2308](https://ziggit.dev/u/Justus2308)\
**Post date:** [April 16, 2025, 10:18am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/5 "2025-04-16T10:18:50Z")

</div>

Yeah definitely, but what I mean is that instead of having `lexer.zig` and `Lexer` as a struct in that file, you could just have `Lexer.zig` as a [file-level struct](https://ziglang.org/documentation/master/#import). That way your `Lexer` type would just be `const Lexer = @import("Lexer.zig")` instead of `const Lexer = lexer.Lexer`. If `Token` is strongly related to `Lexer` anyway, it could be a type inside that struct and you could still refer to it as `const Token = Lexer.Token`.  
The stdlib frequently uses this pattern (e.g. for [SinglyLinkedList](https://github.com/ziglang/zig/blob/master/lib/std/SinglyLinkedList.zig)). Note how the type itself is the file and includes its sub-types (e.g. `Node`).

---

<div class="post-metadata">

**Author:** ![Dru-blip](https://ziggit.dev/user_avatar/ziggit.dev/dru-blip/32/5141_2.png) [@Dru-blip](https://ziggit.dev/u/Dru-blip)\
**Post date:** [April 16, 2025, 10:26am UTC](https://ziggit.dev/t/code-review-my-first-zig-project/9655/6 "2025-04-16T10:26:31Z")

</div>

Thank you @vulpesx and @Justus2308 .  
Im sorry i didnt get it first ,i thought you are taking about type alias stuff but i understand it now.
