Zig in Depth: comptime Part I

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ธ.ค. 2024

ความคิดเห็น • 11

  •  ปีที่แล้ว +9

    Just a little bug in your code : you write 'other.x - other.x' and 'other.y - other.y' (instead of 'other.x - self.x' and 'other.y - self.y' in the .Float tag of your revised distance method :)

    • @dudethebuilder
      @dudethebuilder  ปีที่แล้ว +6

      Oh that was totally intentional to see if you guys are paying attention... lol Just kidding. I fixed it in the code repo. Thanks for the heads up!

  • @dawid0115
    @dawid0115 3 หลายเดือนก่อน

    second example blew my mind 😱 im very interested in learning zig now!

  • @petervancaeseele9832
    @petervancaeseele9832 หลายเดือนก่อน +1

    The version of Zig I'm using (0.14 dev) uses .int and .float (lowercase). I'm not sure when that breaking change was made but hopefully this helps some people.

    • @dudethebuilder
      @dudethebuilder  หลายเดือนก่อน

      Yes, during this 0.14 dev cycle, all standard library enum fields were normalized to lowercase. Good catch!

  • @makroshlyta
    @makroshlyta 11 หลายเดือนก่อน

    I notice my object type returned as Point using @import("Point.zig") and point with @import("point.zig") and my file is just "point.zig". I was expecting an error loading a reference with wrong name and the object to identify himself with the name given inside the file. Feels too much Visual Basic for a language that don't want to acknowledge strings.

    • @dudethebuilder
      @dudethebuilder  11 หลายเดือนก่อน +1

      Yeah, Zig's anonymous structs and their naming rules are indeed a bit strange. Takes getting used to them.

  • @deadmarshal
    @deadmarshal ปีที่แล้ว +2

    Maybe the devs could make the @sqrt builtin generic too? 🤔

    • @dudethebuilder
      @dudethebuilder  ปีที่แล้ว +7

      Good observation. I believe builtins like @sqrt that perform numeric operations are implemented using hardware-level instructions (where available) that make them extremely fast, and the types on which these operations perform are hard-wired, in this case floats only. In the std.math namespace you can find equivalent functions that do work with other types.

  • @phat80
    @phat80 3 หลายเดือนก่อน

    you so slooooow… 🤦‍♂️