digitalmars.D.bugs - [Issue 12837] New: Deprecate individual unit getters on Duration and
- via Digitalmars-d-bugs (36/36) Jun 01 2014 https://issues.dlang.org/show_bug.cgi?id=12837
https://issues.dlang.org/show_bug.cgi?id=12837 Issue ID: 12837 Summary: Deprecate individual unit getters on Duration and rename its get to getOnly Product: D Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: jmdavisProg gmx.com Okay. Duration currently has long total(string units)() safe const pure nothrow {} and long get(string units)() safe const pure nothrow {} It then has a series of wrappers around get for get!"weeks"(), get!"hours"(), etc, which bear the unit names - weeks, hours, etc. I have a similar type in C++ at work, which does not have the wrappers, and what I have found is that people consistently misuse get, thinking that it's total, and it keeps causing bugs. I don't know that that's happening with get much with core.time.Duration, because we have the individual unit wrappers, but I fully expect that folks are misusing those the some way. That being the case, I think that we need to change these functions on Duration to make this clearer and prevent such bugs, which are often hard to track down. So, I propose that we add getOnly (which is the same as get) and deprecate get (which probably won't cause many folks to change their code, since almost everyone will probably be using the wrappers) as well as deprecate all of the individual unit wrapper functions. This _does_ make code that uses them longer - e.g. d.getOnly!"hours"() instead of d.hours - but odds are that in most cases where they're used, it's a bug anyway, and they should have been using total. So, this will cause some folks to change their code, but in a lot of those cases, it will probably catch bugs for them. --
Jun 01 2014