Hi all,
I want to know why Golang do not have type-embeded consts or variables 
(Just like static values and method build-in classes in object oriented 
languages like C++)
This feature helps us define type-shared valuse, and do not increase size 
of instanced objects. Unfortunately Golang do not have this feature, and 
this made us difficult to extend an exsists package outside the origin ones.
For example, type std.time.Duration is a well-designed type to mesure time, 
but package std.time has pre-defined time period consts from Nanosecond to 
Hour, but I found I need some more time period consts such as Day or Week.
So I tried to extend my own Duration type from std.time.Duration:
type Duration time.Duration
And then, I have my own wonderfull Duration type benefit from 
std.time.Duration.
But the trouble is, I can't inherit the corresponding consts defined for 
std.time.Duration in package std.time.
So I have to define my own time period consts like this:
const (
Nanosecond = Duration(time.Nanosecond)
Microsecond = Duration(time.Microsecond)
Millisecond = Duration(time.Millisecond)
Second = Duration(time.Second)
Minute = Duration(time.Minute)
Hour = Duration(time.Hour)
Day = 24 * Hour
Week = 7 * Day
)
This make my code ugly.
Exactly, I desired my extension code can be like this:
type Duration time.Duration
const Duration.Day = Duration(time.Duration.Hour*24)
const Duration.Week = Duration(Duration.Day*7)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to