News for hackers. Stuff that matters.
Re:Zig in 30 Minutes by WhoCaresLies on Sunday January 03, 2021 @02:39AM (#25620273)
why do you pass an empty struct

```

    std.debug.print("hello world!\n", .{});
```

that kind of extra typing is what turn me off to be very honest, other than that, zig seems like C and Swift had a baby, pretty nice

another thing:

```

const LikeAnObject = struct{

    value: i32,

    fn print(self: *LikeAnObject) void {
        std.debug.print("value: {}\n", .{self.value});
    }
};

```

Why don't make the self: *LikeAnObject implicit?

Again, this focus on extra typing only just add noise in my opinion, function is already wrapped inside the struct, i feel like it HAS to be implicit

-- EDIT --

One last thing:

```

    for (array) | value | {

        std.debug.print("array {}\n", .{value});

    }
```

Not a fan of the | | syntax, it doesn't feel natural

```

    for (value in array)
```

Here it is pretty clear what it does

-- EDIT 2 --

```

const std = @import("std");

std.debug.print("hello\n", .{});

```

is import the right word here? feels like it should be ``use`` since you'll use them this way: ``std.debug.print``

``import`` would be to make all the types directly visible and use this way: ``debug.print``

Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @02:48AM (#25620317)
That not an empty struct, rather an empty anonymous array. It's there because zig doesn't have overloaded function params. Print must take two arguments.

The || syntax is used elsewhere in zig, if statements, catch, switch, etc.

There's no requirement for a function inside a struct to act on the contents of structs, so it's reasonable to use structs as namespaces. This is what is happening when you @import, for example. The imported file becomes a struct.

This is quite different from a lot of other PLs, but it is pleasantly consistent when you get used to it.

There is a usingnamespace keyword to make a structs public contents spill out into the current scope. It's to be used sparingly.

Edit: I'm wrong! It's an anonymous struct with number fields, not an anonymous array.

Re:Zig in 30 Minutes by WhoCaresLies on Sunday January 03, 2021 @05:10AM (#25620841)
so it's not a type safe language if they use anonymous struct everywhere

also why ask for a parameter when it is not needed? print vs printf in C

Re:Zig in 30 Minutes by AnIdiotOnTheNet on Sunday January 03, 2021 @10:15AM (#25622189)
Anonymous struct/tuple/array is a convenience feature that can only be used for values.

Consider the above code without it:

  std.debug.print("hello world!\n", struct{}{});
Now add a value:

  std.debug.print("{}!\n", struct{string: []const u8}{ .string = "hello world"});
Quite unwieldy. Zig used to have variadic functions and it was difficult to work with, complicated metaprogramming, and made how things work less obvious during reading. It was also pretty much only ever used for the "print" function.
Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @01:18PM (#25623655)
> so it's not a type safe language if they use anonymous struct everywhere

It's compile-time checked. The example shows a compile time error when the struct fields are not completed by the anonymous struct

Re:Zig in 30 Minutes by cassepipe on Sunday January 03, 2021 @06:29AM (#25621173)
printf in C makes use of variadic arguments (man 3 stdarg) which Zig does not allow (unless you are using a C function) for safety reasons.
Re:Zig in 30 Minutes by friend-monoid on Sunday January 03, 2021 @07:48AM (#25621462)
Well, on the upside on the ‘for’ syntax, it allows you to say “for (objects) draw” instead of “for (object in objects) { draw(object); }”. So it’s not all bad.

Edit: also, the print stuff, I feel that’s in line with the Zig Zen - make the language simple to understand. Now the print function has a very clear type. Otherwise you need a “smart” print function (like Rust does with a macro or C does with varargs). Easier to understand, not easier to type.

[dead]
Re:Zig in 30 Minutes by AnIdiotOnTheNet on Sunday January 03, 2021 @10:23AM (#25622249)
You're probably being downvoted because, while your first two questions are reasonable, your two edits are just low-effort low-value syntactical nitpicking.
[dead]
Re:Zig in 30 Minutes by detaro on Sunday January 03, 2021 @10:00AM (#25622114)
hm, somehow you immediately before this one have 2 comments where you criticize Zig that are not downvoted in your comment history?
Re:Zig in 30 Minutes by pfalcon on Sunday January 03, 2021 @10:22AM (#25622237)
Oh, so you really expect every comment not singing hymns to Zig to be downvoted? ;-) Well, they now are.