3 ms·
Quick question about golang. In your code, go.user / user.go You have a Boolean function Guest(). Is this a common practice in Golang vs. writing it as IsGuest
by salimmadjd 13y ago
Quick question about golang. In your code, go.user / user.go
You have a Boolean function Guest(). Is this a common practice in Golang vs. writing it as IsGuest() ?
Thanks for sharing, BTW!
- carbocation 13y agoI'm not sure if this is wholly idiomatic. I based it on the following from "Effective Go" [1]: > There's nothing wrong with providing getters and setters yourself, and it's often appropriate to do so, but it's neither idiomatic nor necessary to put Get into the getter's name. Since I view "is/has" as derivatives of "get", I opted to omit the "is" from Guest(). But I'm open to hearing other opinions. There is probably plenty that is un-idiomatic all over this code and one of the reasons I put it out there is to get feedback. 1 = http://golang.org/doc/effective_go.html#Getters http://golang.org/doc/effective_go.html#Getters
- deleted 13y ago[deleted]
- mseepgood 13y ago"GetX" is not idiomatic, but "IsX" seems to be idiomatic: http://golang.org/pkg/net/#IP.IsGlobalUnicast http://golang.org/pkg/net/#IP.IsGlobalUnicast
- TylerE 13y agoSeems redundant. A boolean function is by definition asking a yes/no question.
- Jabbles 13y agoYes, although return u.Id == 0 would be even more idiomatic :)
- carbocation 13y agoHeh, true. Guest() exists because: (1) the html/templates are very limited in terms of in-template logic; and (2) I wasn't initially sure that u.Id == 0 would be the defining feature that determines that someone is a guest. So far, it seems to work well enough.