Thread overview
[Issue 9214] New: TickDuration.to should probably be a property
Dec 27, 2012
Andrej Mitrovic
Dec 27, 2012
Jonathan M Davis
Dec 27, 2012
Jonathan M Davis
Dec 28, 2012
Jonathan M Davis
December 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9214

           Summary: TickDuration.to should probably be a property
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-26 17:51:54 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9214


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-12-26 21:43:00 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9214



--- Comment #2 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-12-26 22:27:55 PST ---
https://github.com/D-Programming-Language/phobos/pull/1038

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9214



--- Comment #3 from github-bugzilla@puremagic.com 2012-12-27 08:01:24 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9214


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------