Skip to content

More descriptive code samples #284

@ellnix

Description

@ellnix

Going through this guide and enjoying it so far. I'm writing this issue to ask whether it would benefit the website if the code samples used more descriptive names for things like constants, variables, and tests. In quite a few cases it feels like they were written temporarily and not refactored.

I would be happy to make PRs toward this, just thought I'd make an issue first to make sure that this is something worth doing.

Examples:

Current:

test "hmm" {
    Mode.count += 1;
    try expect(Mode.count == 1);
}

Suggestion:

test "enum namespaced variable" {
    Mode.count += 1;
    try expect(Mode.count == 1);
}

Current:

test "automatic dereference" {
    var thing = Stuff{ .x = 10, .y = 20 };
    thing.swap();
    try expect(thing.x == 20);
    try expect(thing.y == 10);
}

Suggestion:

test "automatic dereference" {
    var p = Point{ .x = 10, .y = 20 };
    p.swap();
    try expect(p.x == 20);
    try expect(p.y == 10);
}

The official zigs documentation on structs also seems to use Point as an example, not that it really matters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions