fishy commented on PR #3812: URL: https://github.com/apache/thrift/pull/3812#issuecomment-5587904435
The discussion of whether to use type alias in go had came up before and rejected. The reason we don't want it is it will lose some compile time enforcement. For example, someone can have this typedef in thrift: ```thrift typedef i64 TimestampMilliseconds ``` With the current not-type-alias implementation, we the generated go code is: ``` type TimestampMilliseconds int64 ``` It's convertible with int64 but _not the same type_. so when using it, you mostly are required to use an explicit typecasting like this ```go obj.StartTime := package.TimestampMilliseconds(t.UnixMilli()) ``` while this won't compilre: ```go obj.StartTime := t.UnixMilli() ``` as `t.UnixMilli()` gives you `int64` not `TimestampMilliseconds`. now imagine if someone has a bug and used [`UnixNano`](https://pkg.go.dev/time#Time.UnixNano) instead. With forced explicit casting, it's very obvious at a glance that there is a bug: ```go obj.StartTime := package.TimestampMilliseconds(t.UnixNano()) ``` You lost that when using type alias. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
