Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Using parens to pass type arguments was one of the things that turned me off on Zig. For a language that prioritizes "no hidden control flow," it sure did a lot to make various syntax conventions _masquerade_ as control flow instead.


> Using parens to pass type arguments was one of the things that turned me off on Zig.

It's just regular comptime function calls which happen to have parameters or return values which are comptime type values (types are comptime values in Zig). I find that a lot more elegant then inventing a separate syntax for generics, and it lets you do things trivially which are complex in other languages (like incrementally building complex types with regular Zig code).

It might be unusual when coming from C++, Rust or Typescript, but it feels 'natural' pretty much immediately after writing a few lines of generic code.


What do you mean? It is control flow. Generic functions are just higher-order functions that get evaluated at compile time.


It is an interesting question of definitions. Is control flow only at runtime? Is `#if` control flow in C?

If I had to define it, I would go with runtime-only, but I could see the other way too.


Macros can have control flow, so compile-time control flow is definitely possible, but perhaps we trained ourselves to not think of control flow in this way because using complicated compile-time logic is generally frowned upon as a footgun.

Perhaps Zig is the language that on purpose blurs the line between what runs when (by basically having what looks like macros integrated into runtime code without any conspicuous hashtaggy syntax), and so a Ziggy would not see compile-time control flow as something weird.


Zig’s comptime is just code that runs at compile time. Unless we have another term, we must call it control flow


[flagged]


I don't get it. Their reply looks normal to me.

Is it because they disagree with you?

I take these instances as learning opportunities and that makes me want to comment more, not less.


Like what?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: