Update 'Style Guide'
parent
ff3e494804
commit
ce730ad4d5
@ -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.
|
||||
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.
|
Reference in New Issue
Block a user