hamming.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package hamming

import (
	"errors"
)

const testVersion = 4

func Distance(a, b string) (int, error) {
	if len(a) != len(b) {
		return 0, errors.New("Not the same length")
	}
	bRuneSlice := []rune(b)
	hamming := 0
	for i, byte_ := range a {
		if bRuneSlice[i] != byte_ {
			hamming += 1
		}
	}
	return hamming, nil
}

Comments

The Go style guide specifies camel case for all names:

[T]he convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.- Effective Go

Names here refers to anything that you would name: types, functions, methods, variables (whether they're package level or local), and constants.

Note that constants is included in the above list. A lot of languages use ALL_CAPS for these, but Go uses mixedCaps for unexported constants and MixedCaps for exported ones--same as any other name.


This is an automated nitpick. Read more about this experiment.

rikki- commented 23 April 2016 at 16:00 UTC

You're not logged in right now. Please login via GitHub to comment