From ce730ad4d540986968a0f5e4e6d2d79d348b366d Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 1 Sep 2022 20:12:04 +0000 Subject: [PATCH] Update 'Style Guide' --- Style-Guide.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Style-Guide.md b/Style-Guide.md index 679e734..e5d9956 100644 --- a/Style-Guide.md +++ b/Style-Guide.md @@ -16,6 +16,43 @@ For example: func Parse (modulePath string) (tree *SyntaxTree, err error) { ``` +Documenting struct member variables and enum values is also a very good idea: + +``` +// TypeKind represents what kind of type a type is +type TypeKind int + +const ( + // TypeKindBasic either means it's a primitive, or it inherits from + // something. + TypeKindBasic TypeKind = iota + + // TypeKindPointer means it's a pointer + TypeKindPointer + + // TypeKindArray means it's an array. + TypeKindArray +) + +// Type represents a type specifier +type Type struct { + location file.Location + + mutable bool + kind TypeKind + + // only applicable for arrays. a value of zero means it has an + // undefined/dynamic length. + length uint64 + + // only applicable for basic. + name Identifier + + // not applicable for basic. + points *Type +} +``` + ## Inline Comments Comments within the actual code are generally all lowercase, and do not end with a period. They should provide a high level description of what code is doing. This goes without saying, but be sure to include a good amount of these, as other people *will* read your code. @@ -103,4 +140,20 @@ func someFunc( Obviously, these examples have been condensed way below 80 columns for dramatic effect, but you get the idea. -Other stylistic choices don't matter as much, since all of the code will be gofmt'd at some point. It is, however, a good idea to adopt the gofmt style at least to some degree, so your code will look similar before and after. \ No newline at end of file +Other stylistic choices don't matter as much, since all of the code will be gofmt'd at some point. It is, however, a good idea to adopt the gofmt style at least to some degree, so your code will look similar before and after. + +# "Enums" + +Go does not have support for enums, but you can still make things that are effectively enums. This is done by creating a new type with the desired name, and basing it off of an `int` primitive, then definind a `const` block of pre-defined values for it. + +``` +type Color int + +const ( + ColorRed = iota + ColorBlue + ColorGreen +) +``` + +All enum values the ARF compiler are prefixed with the name of the enum they belong to, as shown above. \ No newline at end of file