Bug 9214 – TickDuration.to should probably be a property

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-26T17:51:00Z
Last change time
2012-12-27T20:45:19Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-12-26T17:51:54Z
Example from datetime: import std.datetime; import std.stdio; import std.conv; void main() { int a; void f0() {} void f1() {auto b = a;} void f2() {auto b = to!(string)(a);} auto r = benchmark!(f0, f1, f2)(10_000_000); writefln("Milliseconds to call fun[0] n times: %s", r[0].to!("msecs", int)); } 2.060: test.d(12): Error: not a property r[cast(uint)0].to If we want to preserve this syntax we have to make the `to` function a property. Or we can change the code sample.. but I kind of like the way it's written.
Comment #1 by issues.dlang — 2012-12-26T21:43:00Z
to makes no sense as a property. It's a conversion function, not an abstraction for a variable. If anything, the example needs to be changed. Now, there's a decent chance that with what a lot of people think about UFCS and templated functions that using to without the parens for the function call won't be necessary long term, but if it's a property, then it'll likely be required to not have the parens long term, and given that to is a conversion function, I really don't think that makes sense. If you want a property, then use one of the property functions which wrap to (msecs, seconds, etc.). I think that I'll just create a commit which changes the example to use the property function instead of to, since that's cleaner anyway.
Comment #2 by issues.dlang — 2012-12-26T22:27:55Z
Comment #3 by github-bugzilla — 2012-12-27T08:01:24Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/ab9c275962667c0430b3b04b05e566825e91c7aa Fix for issue# 9214. I don't think that it makes any sense for core.time.TickDuration.to to be a property, since it's a conversion function, not an abstraction for a variable. However, it _does_ make sense for the example to use one of TickDuration's property functions instead (it makes the code cleaner too). So, I've done that. And if the property debate results in non-property functions being allowed to be called without parens (as currently seems likely), then anyone wanting to use the to function without the extra parens can do so then. https://github.com/D-Programming-Language/phobos/commit/e2833961c765f228df6fa08828ec5f8d947cb16c Merge pull request #1038 from jmdavis/9214 Fix for issue# 9214.