|
|
|
|
|
by jcelerier
2327 days ago
|
|
> assert(std.meta.trait.isSignedInt(@TypeOf(val))); well yes, that's my point. You could also write void signedIntsOnly(auto val) {
static_assert(std::is_integral_v<T> && std::is_signed_v<T>);
}
in C++ but it's quite preferable to refactor this inside the types themselves (for the same reason that you want to refactor any other kind of code in general - besides you don't want to go read the implementation of your functions every time do you ? IDEs show us only prototypes for a reason).How would you for instance specialize a generic function in Zig ? Does zig accept fn complexmathoperation(val: var) void {
if(isInt(@TypeOf(val))) {
}
}
and in another module fn complexmathoperation(val: var) void {
if(isSomeKindOfLibrarySpecificMatrix(@TypeOf(val))) {
}
}
and properly dispatches between both ?I'd be hard pressed to say that it is "as powerful" given what I'm seeing for now. |
|
The IDE can be changed to show you assertions in addition to the signature, just as it also shows doc comments. That the signature is special isn't some law of nature, it's just habit (and users of untyped languages don't even have those).
> How would you for instance specialize a generic function in Zig ? ... and properly dispatches between both ?
No, you'd need a single definition with a comptime branch.
> I'd be hard pressed to say that it is "as powerful" given what I'm seeing for now.
What you're seeing is personal taste. In my taste, that Zig doesn't allow overloading and has clear dispatch is clearer is more preferable (in fact, it's touted as one of Zig's biggest strengths); in yours, it is less preferable. That's perfectly OK, but it's got nothing to do with expressive power (which has a pretty good and precise definition: https://youtu.be/43XaZEn2aLc). There is a reason why some languages are more complicated while others are simple -- some people aesthetically prefer the more complex languages while others prefer simpler ones. What is impressive about Zig is that despite being simple, it's not giving up power, at least in those aspects I mentioned. C, another simple language, cannot do those things.