• glad_cat@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    2
    ·
    1 year ago

    I hate videos that try to talk about programming concepts. Also it would be better if we had a real comparison between Nim and Zig as it seems that they try to fill the same void in programming languages.

    • Paradox@lemdro.id
      link
      fedilink
      English
      arrow-up
      6
      ·
      edit-2
      1 year ago

      Well, one major difference between nim and zig is that nim has codegen features built in, and the ergonomics are so simple around them you’ll wind up using them without knowing.

      Nim, if you just start calling functions in your code, will evaluate them at compile time. This means you can use loops and other constructs to generate bits of code. This is similar to how it works in Ruby and Elixir (and python too IIRC).

      So you can do this contrived example:

      for i in [a, b, c]:
        proc i =
          echo "Generated proc"
      

      That code probably wont work, but you can see the utility on being able to generate stuff inside your source code.

      Zig explicitly has chosen to not have codegen features. The reasoning is that it keeps the language simpler, and is inline with Zigs efforts to stay away from macros and templates. The closest you can get is the comptime keyword, which evaluates it’s right at compile, but it’s very limited