Settings

Theme

Basic MetaProgramming in Zig

openmymind.net

104 points by nalgeon a year ago · 8 comments

Reader

dsp_person a year ago

> I wish there was a way to get Zig code out of comptime

I often just take an approach similar to cog [1], but it's simple enough I prefer to roll my own to do whatever code generation I'm wanting. E.g. write a ~100 line python file that reads source file(s), reads special comments with code gen or introspection instructions, and then insert generated code at some designated point(s).

[1] https://github.com/nedbat/cog

dragonelite a year ago

That was an interesting blog post, hope we will get more intermediate and advance zig usage blog posts and in the future books about zig.

  • anonymoushn a year ago

    The language is deliberately pretty small. "Advanced usage" will tend to have to do with the problem domain and solution architecture rather than with the language.

    • pjmlp a year ago

      Having seen some strange things done with C, on multiprocessor infrastructure using shared memory alongside home grown RPC framework with handles instead of pointers, or regular demoscene stuff, there is enough room for creative advanced usage even with small languages.

      • dragonelite a year ago

        I was more hinting at this books like "Patterns in C" etc. But a more complete use/abuse of zig meta programming would also be nice. Especially for people that have consume more generic code than produce generic code..

        Off course one can just hunt down the advance material looking through discord, read the bigger zig codebases etc but having it all in one place a couple of books that describe and explains is just way better to level up and get rid of the skill issue :)

        • pjmlp a year ago

          Pattern in C can also be provided. :)

          By applying the architecture designs from key references like Edward Yourdon books, which are from the structure architecture wave, that predated the OOP patterns wave.

    • fithisux a year ago

      I like that. Still they have some design issues.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection