Skip to content

Instantly share code, notes, and snippets.

@electrum
Created July 21, 2014 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electrum/d2f7668f2a7eb95420a9 to your computer and use it in GitHub Desktop.
Save electrum/d2f7668f2a7eb95420a9 to your computer and use it in GitHub Desktop.

Code generated from protobufs:

public String getSomeId() {
	if (someId_ instanceof String) {
		return (String) someId_;
	}
	ByteString bs = (ByteString) someId_;
	String s = bs.toStringUtf8();
	if (isValidUtf8(bs)) {
		someId_ = s;
	}
	return s;
}

vs.

func (m *SomeData) GetSomeId() string {
	if m != nil && m.SomeId != nil {
		return *m.SomeId
	}
	return ""
}

Which is easier to understand and be sure is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment