From fb812fc1fca2a752872e53047a15c0ff35091feb Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Avoid these words in type names:
+Everything is a value, all types are data, everything is context, all logic manages state. + Nothing is communicated by using a word that applies to all types.
+Temptation to use "utilities", "miscellaneous", or somebody's initials + is a failure to categorize, or more commonly, overcategorization. Such + declarations can live at the root of a module that needs them with no + namespace needed.
+ {#header_close#} + + {#header_open|Avoid Redundant Names in Fully-Qualified Namespaces#} +Every declaration is assigned a fully qualified + namespace by the compiler, creating a tree structure. Choose names based + on the fully-qualified namespace, and avoid redundant name segments.
+ {#code_begin|exe|redundant_fqn#} +const std = @import("std"); + +pub const json = struct { + pub const JsonValue = union(enum) { + number: f64, + boolean: bool, + // ... + }; +}; + +pub fn main() void { + std.debug.print("{s}\n", .{@typeName(json.JsonValue)}); +} + {#code_end#} +In this example, "json" is repeated in the fully-qualified namespace. The solution
+ is to delete Json from JsonValue. In this example we have
+ an empty struct named json but remember that files also act
+ as part of the fully-qualified namespace.
This example is an exception to the rule specified in {#link|Avoid Redundancy in Names#}. + The meaning of the type has been reduced to its core: it is a json value. The name + cannot be any more specific without being incorrect.
+ {#header_close#} + {#header_open|Whitespace#}