A solution that's been kicking around for a while:
For Go 2 (can't do it before then): Change the definition to “lower case letters and are package-local; all else is exported”. Then with non-cased languages, such as Japanese, we can write 日本语 for an exported name and 日本语 for a local name. This rule has no effect, relative to the Go 1 rule, with cased languages. They behave exactly the same.
为了说明类型声明,我们将不同温度单位分别定义为不同的类型:
gopl.io/ch2/tempconv0
// Package tempconv performs Celsius and Fahrenheit temperature computations.packagetempconvimport"fmt"typeCelsiusfloat64// 摄氏温度typeFahrenheitfloat64// 华氏温度const(AbsoluteZeroCCelsius=-273.15// 绝对零度FreezingCCelsius=0// 结冰点温度BoilingCCelsius=100// 沸水温度)funcCToF(cCelsius)Fahrenheit{returnFahrenheit(c*9/5+32)}funcFToC(fFahrenheit)Celsius{returnCelsius((f -32)*5/9)}
fmt.Printf("%g\n", BoilingC-FreezingC) // "100" °C
boilingF := CToF(BoilingC)
fmt.Printf("%g\n", boilingF-CToF(FreezingC)) // "180" °F
fmt.Printf("%g\n", boilingF-FreezingC) // compile error: type mismatch
var c Celsius
var f Fahrenheit
fmt.Println(c == 0) // "true"
fmt.Println(f >= 0) // "true"
fmt.Println(c == f) // compile error: type mismatch
fmt.Println(c == Celsius(f)) // "true"!
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
c := FToC(212.0)
fmt.Println(c.String()) // "100°C"
fmt.Printf("%v\n", c) // "100°C"; no need to call String explicitly
fmt.Printf("%s\n", c) // "100°C"
fmt.Println(c) // "100°C"
fmt.Printf("%g\n", c) // "100"; does not call String
fmt.Println(float64(c)) // "100"; does not call String