"Jonathan M Davis" <jmdavisp...@gmx.com> wrote in message news:mailman.117.1331079921.4860.digitalmar...@puremagic.com... > On Tuesday, March 06, 2012 17:00:19 Brad Anderson wrote: >> I wasn't around for the creation of datetime but I'm curious why a boost >> datetime-like duration construction shortcut approach to durations wasn't >> used. That is, you can write weeks(1), months(6), years(10), hours(17), >> minutes(12), etc. (although there is now days(int) for some reason). > > Because then you've got incredibly common names used as top-level symbols.
In this case, I can't imagine that would be a realistic problem in practice. There aren't many things that can be called, for example, "hours": 1. There's the concept of the duration itself, which is already covered by std.datetime and core.time, so nobody needs to reinvent that wheel (and if they do, they're not going to be importing std.datetime anyway). 2. There's "number of hours". In which case there's plenty of options: A. Change it to "numHours" or something descriptive like "hoursOfPlaytime" (which is a better idea anyway - if you're in the habit of using vars named like "hours", those can just as easily collide with each other as they can collide with "std.datetime.hours"). B. Keep it "hours" and remember this isn't C++: We have many excellent features for dealing with symbol name-collisions. And in many/most cases, you'll never even have a collision anyway. 3. Nothing. That's it, just those two: The "concept of hours as a duration" and "number of hours". Thie first is a complete non-issue, and the second is a miniscule issue at most. I think the name collision issue (is this case) is just worrying over nothing. > It's also not generic at all. As it stands, you can have a function which > does > dur!units(value). You can't do that with weeks(1), months(6), etc. > First of all, I can't imagine that would be needed frequently enough to justify having to always use "dur" or "duration". Second, as I said in another post, just drop this in: alias duration!"years" years; alias duration!"months" months; alias duration!"weeks" weeks; alias duration!"days" days; alias duration!"hours" hours; alias duration!"minutes" minutes; alias duration!"seconds" seconds; alias duration!"msecs" msecs; alias duration!"usecs" usecs; alias duration!"hnsecs" hnsecs; All (real) problems solved.