3 ms·
const x: i32 = 92; D has less syntax: const int x = 92; Just for fun, read each declaration out loud.
by WalterBright 1y ago
const x: i32 = 92;
D has less syntax:
const int x = 92;
Just for fun, read each declaration out loud.
- WalterBright 1y agoZig: const std = @import("std"); D: import std;
- brabel 1y agoI think this is not equivalent because in D, this imports all symbols in the package `std` while in Zig, you just get a "struct" called `std`. I think the equivalent D is: import std=std;
- WalterBright 1y agoWhat I wrote is equivalent to the zig declaration. Google says: const my_module = @import("my_module.zig"); This allows you to access pub (public) declarations from my_module.zig through the my_module identifier.
- brabel 1y agoYes, but how is that equivalent? Zig: const std = @import("std"); pub fn main() !void { // std is like a namespace here std.debug.print("Hello, World!\n", .{}); } D: import std.stdio; void main() { // no namespace here, "writeln" and everything else in "std.stdio" is imported writeln("Hello, World!"); } The closest to Zig in D would be: import io = std.stdio; void main() { io.writeln("Hello, World!"); }
- WalterBright 1y agoYou can write in D: std.stdio.writeln("Hello, world!");
- WalterBright 1y agoZig: fn ArrayListType(comptime T: type) type { D: T ArrayListType(T)() {
- dpassens 1y agoI don't know D but shouldn't that be struct ArrayListType(T) { ?
- brabel 1y agoWalter is showing the equivalent function declaration... you will eventually create a generic type as you say, but in the Zig example, that was a function, not a struct.
- dpassens 1y agoIf my understanding of D's template syntax is correct, then Walter is showing a the declaration of a function called ArrayListType which is generic over T and returns a T. The original Zig code returns the struct type itself, so it is functionally equivalent to my example, provided I understood how D templates work.
- brabel 1y agoThe Zig code returns any `type`, it's impossible to say what that is without looking at the implementation. It can be different types completely depending on the comptime arguments. But I agree it probably returns a struct type. Assuming that's the case, you're right and the equivalent would be: Zig: fn ArrayListType(comptime T: type) type { D: ArrayList!T ArrayListType(T)() { But now the D version is more specific about what it returns, so it's still not exactly equivalent.
- dpassens 1y agoNo, you misunderstand. The function doesn't return any type, it returns _a_ type. Types are values in Zig and returning them from function is how generics are implemented.
- IshKebab 1y ago"less syntax" isn't necessarily better. The goal isn't to have as few characters as possible.
- WalterBright 1y agoI agree. I'm not a fan of minimized syntax (see Haskell). But I am a fan of easy to read syntax!
- johnisgood 1y agoTrue, it is subjective. I prefer C, Go, PHP, ... and OCaml, Erlang, Elixir, Perl, and sometimes Ada and Common Lisp. I like the syntaxes of each, although Ada is too verbose to me, and with Factor and Common Lisp I have a skill issue.
- tmtvl 1y agoIf it were we would all be using APL.
- deleted 1y ago[deleted]