News for hackers. Stuff that matters.
Re:Making Wrong Code Look Wrong (2005) by marcus_holmes on Saturday November 09, 2019 @06:52PM (#21495364)
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? :(

There are no comments on this comment yet.