3 ms·
In Go: type Password string type Name string func SayHello(name Name) { fmt.Println("Hello %s",string(name)) } func Login(password Password) bool { if
by marcus_holmes 7y ago
In Go:
type Password string
type Name string
func SayHello(name Name) {
fmt.Println("Hello %s",string(name))
}
func Login(password Password) bool {
if bcrypt.magicstuff([]byte(password)){
return true
}
log.Println("error: wrong password: ", string(password))
return false
}
Now the type system does know whether it's a name or a password, and will throw a compiler error if you try to use the wrong one in the wrong place.
edit: really HN, no code formatting options? :(