News for hackers. Stuff that matters.
Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Saturday February 13, 2021 @01:47PM (#26125636)
Neat concept. Exploring the difference between what successfully compiles vs. what won't seems like a great way of getting more familiar with the language.

I've written a little over 1,000 lines of Zig at this point and I really like it. I think its key feature is a rich compile-time imperative programming environment ("comptime"). If you can have full compile-time imperative code execution, you can get a lot of the benefits of more complicated language features (like C++ templates) "for free."

In C++ templates are "a language within a language", but even templates with all their complexity cannot solve all of the problems you might want to solve at compile-time, so C++ has been gradually expanding its compile-time code execution features so that more and more of the language is available at compile-time (constexpr, consteval, etc). Zig jumps straight to the finish line by making most of the language available at compile-time from the outset, and in doing so avoids the need to add the complexity of templates in the first place.

Having "slices" as a first class type feels like a general and powerful solution to the problems that std::string_view and std::span are trying to solve.

I am comparing Zig to C++ a lot, which many Zig fans would probably take exception to as Zig does not aspire to be a better C++, but rather a better C. Indeed many key C++ patterns like RAII are explicitly out of scope. But to me Zig bridges the gap between C and C++ by solving many of the problems that make C feel too spartan without jumping to the incredible complexity of C++.

There are a few things about Zig that give me pause. I've noticed that compile-time feels like a very lazy environment, meaning that functions do not seem to undergo full semantic analysis unless they are called from somewhere. You can write a function that compiles successfully, leading you to believe the function is syntactically and semantically coherent, only to find that when you add an actual call to that function, the compiler now flags errors inside that function. This adds some friction to development, because the act of writing a function is no longer a self-contained activity. Writing the function feels more like sketching it; later when you actually call it you have a new set of compile errors to contend with.

I also miss tools like ASAN to catch memory errors. I'm guessing things like that will come with time.

Overall I feel very positive on Zig.

Re:Ziglings: Learn the Zig programming language by fixing ti... by kristoff_it on Saturday February 13, 2021 @03:00PM (#26126251)
> I am comparing Zig to C++ a lot, which many Zig fans would probably take exception to as Zig does not aspire to be a better C++, but rather a better C.

I was one of those people that started the idea that Zig should be compared to C more than C++. One day I'll express more clearly what I meant by that, but in the meantime I would say that Zig can and should be compared with C++ too.

More generally I think we got to the point where Zig deserves to be analyzed in it's own right and not as a reflection of another language because, among other things, it leads to this kind of misunderstanding:

> I've noticed that compile-time feels like a very lazy environment, meaning that functions do not seem to undergo full semantic analysis unless they are called from somewhere.

Comptime's lazyness is a necessary feature and not an accident. This is how Zig can avoid having a macro system.

More in general the idea is that you are supposed to write tests for your code, which will then ensure your functions get analyzed, and which in turn will produce documentation for your code. This makes testing more core to the development process than it is in other languages.

I'm not saying everyone has to like this approach, but if you stop at the comparison with C, you risk missing how the design of Zig is able to spiral into an new and radical programming experience.

See for example this Twitch clip from yesterday: https://clips.twitch.tv/RockyLivelyChimpanzeeDoubleRainbow-P...

Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Saturday February 13, 2021 @04:36PM (#26127179)
Totally. Zig is neither a better C nor a better C++, but an entirely new (and better, IMO) concept for how low-level programming can and should be done. Zig is about as simple as C and as expressive and powerful as C++, but it doesn't follow either's design tradition (unlike Rust, which is very much in the C++ tradition), and should only be compared to either one by virtue of all three being low-level languages.
Re:Ziglings: Learn the Zig programming language by fixing ti... by dnautics on Saturday February 13, 2021 @09:45PM (#26129203)
> Zig is neither a better C nor a better C++, but an entirely...

I agree with your point because zig has evolved, but I do think that it is important to note at least for historical purposes, that zig was created literally as a "better c", and a lot of decisions are made because of some specific pain point X or Y in c

Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @05:39PM (#26127675)
What is C++ tradition? Is it that one does not pay for a feature unless one uses it? In practice C++ broke with that with exceptions and RTTI. Even Rust does adhere to it since its standard library assumes infallible allocations making one to pay for not relying on it in the form of having to write an alternative library.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Saturday February 13, 2021 @08:13PM (#26128739)
In all low-level languages you don't pay for what you don't use; that's not a design tradition but a requirement of the domain. I'm talking about the tradition of a low-abstraction, low-level language that has many features so that, when it is read on the page it appears as if it were high-level.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Saturday February 13, 2021 @05:46PM (#26127717)
That would be the case if one wasn't allowed to turn them off.
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @06:21PM (#26128000)
The standard library of C++ assumes exceptions and that dictates code style that, even if one assumes infallible allocations and disable exceptions, one gets suboptimal code. So even with exceptions off one pays the price either in the form of non-standard library or accepting non-optimal performance. And if one has to prepare for fallible allocations, then the standard C++ is of no use at all in practice.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @02:12AM (#26130336)
I assume you aren't that comfortable with ISO C++, the standard does allow for failible allocations.

That is the role nothrow in placement new, and custom STL allocators as language tool.

Additionally plenty of APIs now have exception and error based versions with noexcept.

Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Sunday February 14, 2021 @03:19AM (#26130558)
The fallible allocators require to use exceptions. There is no way to use, for example, C++ containers with fallible allocators and disabled exceptions.

But even with exceptions enabled fallible allocation in practice does not work. There was an article that made malloc to return null randomly. All tested C++ implementations crashed then because they allocated memory when generating exceptions.

Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @03:38AM (#26130640)
Stop talking in circles and point out ISO C++20 sections then.

I am also curious to see how serious was that article.

Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Sunday February 14, 2021 @04:59AM (#26130974)
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p070... - this discusses a lot of issues with exceptions as in ISO C++ and concrete proposals to make exceptions cost-free. The section 4.3.5 discusses specifically memory allocations.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @09:00AM (#26132423)
Including parts that relate to Linux, have nothing to do with C++ and apply to any programming language.

You also skipped the section where Rust in its present state doesn't has any kind of recovery, it just panics.

Re:Ziglings: Learn the Zig programming language by fixing ti... by Quekid5 on Sunday February 14, 2021 @08:00AM (#26132054)
> So even with exceptions off one pays the price either in the form of non-standard library or accepting non-optimal performance.

Holy moving goalposts, batman!

The "don't pay..." thing has only ever applied to runtime, there nothing in there about not having to write more code yourself, etc.

(It's also a bit dubious in the first place. Chandler had a good talk about this at one of the CppCon's, IIRC. Can't be bothered to look it up, but it should be on YouTube.)

Re:Ziglings: Learn the Zig programming language by fixing ti... by aarchi on Saturday February 13, 2021 @03:33PM (#26126585)
> Comptime's lazyness is a necessary feature and not an accident. This is how Zig can avoid having a macro system.

Can you elaborate on lazy analysis replacing the need for macros?

Re:Ziglings: Learn the Zig programming language by fixing ti... by kristoff_it on Saturday February 13, 2021 @04:56PM (#26127348)
Lazyness is what allows you to write code that feels naturally coherent but that would be an error with eager analysis. As an example:

  switch(build.target.os) {
    .Linux => std.os.fork(),
    .Windows => std.os.funcUniqueToWindows(),
    else => @compileError("feature not supported for target os"),
  }
This a simplified example to say that each path that depends on a comptime condition, such as the target OS, for example, feels intuitively consistent but in Zig types can (and do) mutate depending on those conditions and if the compiler were to eagerly check dead branches it would find plenty of semantical errors. In the stdlib you can see how `os` corresponds to a different struct definition depending on the target: https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L5...
Re:Ziglings: Learn the Zig programming language by fixing ti... by AndyKelley on Saturday February 13, 2021 @05:13PM (#26127463)
This definitely does cause problems though; I want to acknowledge that. For example, right now we have an issue that auto-generated documentation does not include unreferenced globals.

I have some ideas to address this, but it does represent a flaw in the status quo design of the language.

Re:Ziglings: Learn the Zig programming language by fixing ti... by JacobCarlborg on Sunday February 14, 2021 @04:17AM (#26130819)
In D, all semantic analysis is performed eagerly (I think), except for templates. D also supports CTFE (Compile Time Function Evaluation), `static if`, `static assert` and a few other language constructs that are evaluated at compile time.

I experimented a bit at how D's documentation generator behaves using these language constructs. Here's a snippet of some D code:

  /// some struct description
  struct Foo(T) // template
  {
      /// some alias description
      alias Result = int;
  
      /// some method description
      Result foo()
      {
          string a = 3; // this does not normally compile
      }
  
      static if (is(T == int)) // evaluated at compile time
      {
          /// some method description 2
          void bar() {}
      }
  
      version (Windows)
      {
          /// some method description for Windows
          void bazWindows() {}
      }
  
      else version (Posix)
      {
          /// some method description for Posix
          void bazPosix() {}
      }
  
      else
          static assert(false, "Unsupported platform"); // evaluated at compile time
  }
When generating documentation for the above code, and `Foo` has not been instantiated, the generated docs will include `Foo`, `Result`, `foo`, `bar`, and `bazWindows`. This is regardless of platform. The return type of `foo` will be `Result` and not `int`. This clearly shows that the D compiler doesn't perform semantic analysis when generating documentation. When doing a regular compilation and `Foo` is instantiated, `bar` will only be included if `T` is an `int`. `bazWindows` will only be compiled on Windows and `bazPosix` will only be compiled on Posix platforms.

Looking at the implementation, the compiler will generate the docs after semantic analysis and only if there are no errors. But, if `Foo` is never instantiated no errors have occurred so it will continue to generate the docs.

On the other hand, if `Foo` is instantiated (and compiles) the compiler will generate docs for the AST after semantic analysis has been performed and `bazWindows` will only be included if the docs were generated on Windows and `bazPosix` will only be included on Posix platforms. What's weird though, is that it seems `bar` will be included regardless of what type `T` is.

Re:Ziglings: Learn the Zig programming language by fixing ti... by IgorPartola on Saturday February 13, 2021 @07:43PM (#26128559)
But you can still check the syntax of that statement without evaluating it all. You might even be able to check if things like std.os exist.
Re:Ziglings: Learn the Zig programming language by fixing ti... by defen on Saturday February 13, 2021 @04:03PM (#26126879)
C macros are lazy, but they also operate at the level of lexical tokens instead of the AST, which means you can use macros to generate C code, but you can't really do it in a way that is guaranteed to be safe.

With Zig you can have a function where some or all arguments are marked as "comptime", which means the values for those arguments must be known at compile time. Combined with the fact that types can be used as values at compile time means that you can use Zig to generate Zig functions in a safe way.

Re:Ziglings: Learn the Zig programming language by fixing ti... by Quekid5 on Saturday February 13, 2021 @03:47PM (#26126721)
I'd appreciate some elaboration on that too. It sounds vaguely similar to SFINAE in C++, but I don't know enough about Zig's compilation model to know for sure.

(I'm vaguely familar with Zig from a talk by the creator about 1½ years ago, fwiw.)

Re:Ziglings: Learn the Zig programming language by fixing ti... by dralley on Saturday February 13, 2021 @04:39PM (#26127206)
Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Saturday February 13, 2021 @03:48PM (#26126735)
I'm not sure how my statement was a misunderstanding if you are confirming that function analysis is in fact lazy.
Re:Ziglings: Learn the Zig programming language by fixing ti... by kristoff_it on Saturday February 13, 2021 @05:04PM (#26127410)
The misunderstanding lies in not realizing how lazy evaluation is an integral part of what makes comptime a useful tool and that removing it would break comptime horribly.
Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Saturday February 13, 2021 @05:22PM (#26127551)
That seems a bit of an overstatement. Calls to sometimes-unavailable functions are but one of the many uses of comptime. It seems entirely possible that lazily-analyzed blocks or functions could be demarcated syntactically (eg. "lazy { }") and that the large majority of comptime evaluation would not need to be inside such a block.
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @02:02PM (#26125789)
Zig compile-time evaluation even allows to construct an arbitrary type like a struct with a platform-specific members all using the same core language. This beats even Rust macros and in retrospect I wonder why this not used in other languages? Even Lisp ended up with macros with own sub language instead of making the core language more useful for code generation. Or consider Go attempts at generics. Something like Zig approach will fit it more I think than various generics proposals.
Re:Ziglings: Learn the Zig programming language by fixing ti... by gmfawcett on Saturday February 13, 2021 @04:16PM (#26127017)
"Even Lisp ended up with macros with own sub language..." I assume you're talking about Scheme approaches like `syntax-case` and `syntax-rules`? In Common Lisp, macros are written in Lisp, the same way you would write runtime code. Unquoting and splicing are part of the core language (e.g. they can be applied to data as well as to code).
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @05:19PM (#26127521)
I was not aware that unquoting in Common Lisp can be applied to data. So it is not a specialized sub language just for macros, but a general purpose template system that could also generate code.
Re:Ziglings: Learn the Zig programming language by fixing ti... by ywei3410 on Saturday February 13, 2021 @10:47PM (#26129494)
It's really a shorthand for writing lists - sexp's are lists, so can use the same syntax.

Macro's in Lisp are essentially "just" functions where the arguments are un-evaluated - you can use all the same functions etc...

Writing a simple Lisp interpreter is really quite educational - when you add macros and quoting into the language, you suddenly have a realisation at how simple it is.

Re:Ziglings: Learn the Zig programming language by fixing ti... by kazinator on Saturday February 13, 2021 @08:15PM (#26128748)
That's right. There is no difference between:

  (defmacro my-quote (x)
    `(quote ,x))
and

  (defmacro my-quote (x)
    (list 'quote x))

That `(quote ,x) is just way of writing (list 'quote x), not a notation for writing macros.

That's it.

Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Saturday February 13, 2021 @02:14PM (#26125890)
I agree it's an idea that seems so natural in retrospect that I'm also curious why it hasn't traditionally been more popular. One possible reason that comes to mind is that an imperatively-constructed type is harder to statically analyze.

But on the other hand, even C++ templates are Turing complete and even C++ parse trees can depend on the output of a Turing-complete evaluation. So it is hard to see what benefit a C++-like template feature is buying in comparison.

Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Saturday February 13, 2021 @04:46PM (#26127269)
Not only was it not "more popular," I am not aware of even research languages taking the idea of general-purpose partial evaluation not through syntax macros to the same lengths as Zig (although that doesn't mean there weren't any). It's possible that no one had thought of that, perhaps because type systems, while known to be possibly considered as a form of partial evaluation, are generally treated and studied as a completely separate concept: partial evaluation is a compilation technology while types are part of the theory.
Re:Ziglings: Learn the Zig programming language by fixing ti... by throwaway17_17 on Saturday February 13, 2021 @10:37PM (#26129417)
I’m not clear on what you define syntax macros, but the compile time evaluation that is present in Zig (based on the example and documentation I’ve seen) are an almost direct implementation of the multistage computation research done late 90s-mid 00s. The papers and such are typically ML based (with a caveat for the early Template Haskell paper in 02) and the underlying constructs of MetaML are very close to what Zig implements. All this work is retroactively semantically underpinned by Rowan Davies and Frank Pfenning work on Modal S4 logic. I don’t know if Andy based Zig on this research, but if he didn’t, the convergence toward the same theory is a great thing to see.

My current work on a visual programming compatible language also uses this strategy for meta programming, so I’m very familiar with the academic literature. It certainly seems that Zig got this right and is doing well implementing it in a way that is usable and understandable.

Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Sunday February 14, 2021 @04:21AM (#26130830)
By syntax macros I mean expressions that can be referentially opaque, i.e. m(a) and m(b) might have different semantics even though a and b have the same reference. Lisp (and C, and Haskell, and Rust) is referentially opaque while Zig is transparent. Opacity is strictly more expressive, but is harder to understand; Zig strives to be the "weakest" language possible to get the job done.

MetaML certainly does seem to be similar to Zig, although the one paper I've now read thanks to your suggestion (https://www.sciencedirect.com/science/article/pii/S030439750...) does not mention introspection and type functions, and another commenter here suggests that it is, actually, referentially opaque.

Re:Ziglings: Learn the Zig programming language by fixing ti... by kazinator on Monday February 15, 2021 @01:31AM (#26139767)
Suppose a and b have the same reference. Zig allows something like { const a = 42; const b = 72; ... } which gives these names new references which they no longer share, in a scope. So the opacity is there in some built-in operators; the only question is whether macros can imitate that.
Re:Ziglings: Learn the Zig programming language by fixing ti... by ymbeld on Sunday February 14, 2021 @04:51AM (#26130941)
It doesn’t seem as general as MetaOcaml. Just two-stage evaluation, and without quote and splice.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Sunday February 14, 2021 @07:03AM (#26131659)
I think Zig's comptime has three interesting features:

1. It is referentially transparent, i.e., unlike Lisp, i.e. nothing in the language can distinguish between `1 + 2` and `3`. This means that the semantics of the language is the same as if everything was evaluated at runtime, and the comptime annotation has no impact on semantics (assuming syntax terms aren't objects and there's no `eval`).

2. It supports type introspection and construction.

3. It doesn't have generics and typeclasses as separate constructs but as applications of comptime.

I think 3 is unique to Zig, but I wonder about 1: is it possible in MetaOCaml, as it is in Lisp, C, C++, Rust and Haskell -- but not in Zig! (or, say, Java) -- to write a unit `m`, such that m(1 + 2) is different from m(3)?

Re:Ziglings: Learn the Zig programming language by fixing ti... by ymbeld on Sunday February 14, 2021 @08:27AM (#26132210)
I don’t know. I think MetaOcaml is strict about inspecting Code terms like Code (1 + 2) and Code 3 (as far as I remember it is not allowed). So no, I don’t think you can distinguish between them.
Re:Ziglings: Learn the Zig programming language by fixing ti... by throwaway17_17 on Sunday February 14, 2021 @01:37PM (#26134841)
I think (again based on examples and docs) that it is actually multistaged. However, this is not apparent because the quote and splice are semi-implicit. The ‘comptime’ keyword is essentially a the quote operator, ie. it produces what is essentially a compile time thunk, lazily capturing the ‘code’ value of the expression defined under the comptime keyword. This thunk is directly analogous to a value of type ‘code a’ in MetaML. Then there is an implicit splice operator in place any time a value defined under comptime is used subsequently. I say it is multistaged because it certainly appears that one can define a comptime variable for some computation and then use that variable in a later comptime definition or expression. So, it looks like a basic data flow analysis to determine dependency is done on the comptime evaluations and those are ordered implicitly. This order would correspond to the more explicit staging syntax of MetaML and the operation semantics that underpin it.
Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Saturday February 13, 2021 @05:08PM (#26127435)
> I am not aware of even research languages taking the idea of general-purpose partial evaluation not through syntax macros to the same lengths as Zig

One that comes to mind is Terra: http://terralang.org/

In retrospect Terra seems a clear precursor to Zig (though I don't know if it was a direct influence).

Re:Ziglings: Learn the Zig programming language by fixing ti... by pron on Saturday February 13, 2021 @08:23PM (#26128809)
I've heard of Terra, but I didn't know it had predated Zig by a couple of years; thought they were introduced at about the same time. And yes, there are certainly similarities, although Terra thinks of itself as two interoperating languages, while in Zig there is just one (although there are things you can only do in comptime so perhaps it's more of a difference in perspective).
Re:Ziglings: Learn the Zig programming language by fixing ti... by ymbeld on Sunday February 14, 2021 @04:47AM (#26130919)
The term partial evaluation tends to be used for research that focuses on automatic evaluation of the static part of the program. When considered as metaprogramming the research would probably discuss type-checking + evaluation as two-stage evaluation, falling under the general umbrella of multi-stage programming.
Re:Ziglings: Learn the Zig programming language by fixing ti... by jeltz on Saturday February 13, 2021 @04:24PM (#26127074)
Tow issues I have noticed with Zig: not as good type signatures for functions and not as good error messages. I am not sure if those are fundamental issues with Zig's apporach or if they can be fixed with more work.
Re:Ziglings: Learn the Zig programming language by fixing ti... by vram22 on Sunday February 14, 2021 @03:52AM (#26130703)
Can you elaborate a bit on the first issue?
Re:Ziglings: Learn the Zig programming language by fixing ti... by jeltz on Sunday February 14, 2021 @06:28PM (#26137316)
Take for example the definition of floor(), how would an IDE or documentation generator see which types are supported? This is just imperative code which is executed at compile time and at least to me it is not obvious how to interpret it when generating the documentation. On the other hand in Rust it is almost always easy to see which types can be used where.

    pub fn floor(x: anytype) @TypeOf(x) {
        const T = @TypeOf(x);
        return switch (T) {
            f16 => floor16(x),
            f32 => floor32(x),
            f64 => floor64(x),
            f128 => floor128(x),
            else => @compileError("floor not implemented for " ++ @typeName(T)),
        };
    }
Re:Ziglings: Learn the Zig programming language by fixing ti... by haberman on Monday February 15, 2021 @01:46AM (#26139846)
This seems reasonable to me. It seems comparable to the following in C++:

    template <class T> T floor(T x) { /* ... */ }
I think a documentation generator could display your Zig signature verbatim and a user could make sense of that.
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @02:19PM (#26125930)
Even Java and Rust ended up with Turing-complete generics.
Re:Ziglings: Learn the Zig programming language by fixing ti... by bobthebuilders on Saturday February 13, 2021 @02:32PM (#26126037)
Java turing complete generics are an edge case though, and never hit during normal compilation.
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @03:02PM (#26126277)
Still the compiler has to deal with that. So one ends up with an interpreter in the compiler for very esoteric and hard to write/read language instead of just embedding an interpreter of a subset of Java.

One alleged benefit of Java constrained genetics is that they allow in theory better error messages. Still in complex cases even after over 15 years with genetics in Java the error messages are not that great. Zig to some extend delegates to the compile-time library authors responsibility of producing good error messages. But then the error messages can be improved without waiting for the compiler to improve its reporting heuristics to cover all edge cases.

Re:Ziglings: Learn the Zig programming language by fixing ti... by bobthebuilders on Saturday February 13, 2021 @07:34PM (#26128506)
Incorrect Java does not have genetics. That is a C++ concept.
Re:Ziglings: Learn the Zig programming language by fixing ti... by mhh__ on Saturday February 13, 2021 @05:16PM (#26127488)
We have a slightly vague proposal in D to basically construct programs as a library at compile time (i.e. we give you an AST, you play with it and give it back, if it's valid it.gets turned into a type).

D has been making structs at compile time for years now, however.

Re:Ziglings: Learn the Zig programming language by fixing ti... by afranchuk on Saturday February 13, 2021 @04:03PM (#26126891)
I would guess one reason it wasn't done in other languages was because people simply didn't have a good cross-architecture JIT compilation resource, and didn't want to write it themselves. LLVM makes this _really_ easy. I realize that Zig is transitioning to an LLVM-optional model now. But, for instance, I've been working on an s-expr language with f-expr application, and this combined with LLVM c bindings allows you to generate arbitrary compile time or runtime code. The JIT portion for compile time code was a single function call in LLVM! I started this a while before Zig came out, but alas I haven't devoted enough time to it over the years...
Re:Ziglings: Learn the Zig programming language by fixing ti... by JacobCarlborg on Sunday February 14, 2021 @04:30AM (#26130869)
This is very common in D and D doesn't not have any macro system. It uses regular syntax (more or less). D was doing this way before Zig existed and before C++ had constexpr. Simple example of platform specific members:

  struct Socket
  {
      version (Posix)
          int handle;
      else version (Windows)
          SOCKET handle;
      else
          static assert(false, "Unsupported platform");
  }
Another example is the checked numeric type [1] in the D standard library. It takes two types as parameters. The first being the underlying type and the second being a "hook" type. The hook type allows the user to decide what should happen in various error conditions, like overflow, divide by zero and so on. The implementation is written in a Design By Introspection style and inspects the hook type and adopts its implementation depending on what hooks it provides. If the hook type implements the hook for overflow, that hook will be executed, otherwise it falls back to some default behavior.

[1] https://dlang.org/phobos/std_experimental_checkedint.html

Re:Ziglings: Learn the Zig programming language by fixing ti... by IgorPartola on Saturday February 13, 2021 @07:40PM (#26128541)
One of the small but really good features of Zig that immediately stood out to me was the fact that there are no implicit function or method calls. my.name will never call a hidden function. As useful as @property is in Python, it really makes it hard to reason about performance of code until you dig all the way through every bit of every class and type.
Re:Ziglings: Learn the Zig programming language by fixing ti... by klyrs on Saturday February 13, 2021 @03:20PM (#26126430)
> You can write a function that compiles successfully, leading you to believe the function is syntactically and semantically coherent, only to find that when you add an actual call to that function, the compiler now flags errors inside that function.

This happens to me pretty frequently in C++. It won't compile with a syntax error, but if you don't call, say, a templated function, then the compiler simply can't know that the stuff you're doing inside is nonsense.

I don't consider this to be friction. I generally know what I've called, and what I haven't. I expect dark code to be bug-ridden placeholders with good intentions.

Re:Ziglings: Learn the Zig programming language by fixing ti... by lenkite on Sunday February 14, 2021 @12:28AM (#26129944)
This will be fixed with C++ 20 concepts right ?
Re:Ziglings: Learn the Zig programming language by fixing ti... by Hoppetosse on Saturday February 13, 2021 @02:25PM (#26125982)
The standard library has a General Purpose Allocator that can catch some of the errors that ASAN can, like memory leaks.
Re:Ziglings: Learn the Zig programming language by fixing ti... by vram22 on Sunday February 14, 2021 @01:15AM (#26130121)
Is Zig's comptime feature like D's CTFE?