google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.26k stars 362 forks source link

Reduntant error return value in getTime() #63

Closed batuhansk closed 4 years ago

batuhansk commented 4 years ago

Hey 👋🏼

I was curious about why uuid.New() may return an error then I noticed that the GetTime() method has an error return parameter.

Is there any acceptable reason to has an error value in the return parameters? There is no returned error in the getTime() method. Only returns nil value at the end of the method.

https://github.com/google/uuid/blob/master/time.go#L66

pborman commented 4 years ago

Historical. This package is quite old and harkens from pre go 1.0 days in which os.Time() was used and could potentially return an error. uuid.New() returns a Version 4 UUID and has no error return while uuid.NewUUID() returns a Version 1 UUID and does have an error return. Version 1 UUIDs are rarely used, people almost always use Version 4 (random). The version 1 implementation is also not 100% correct as it technically requires persistent state outside of the application, probably another reason Version 1 UUIDs are not favored. At this point it would potentially be breaking to remove the error return and there is very little benefit in doing so.