www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9214] New: TickDuration.to should probably be a property

reply d-bugmail puremagic.com writes:
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



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: -------
Dec 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9214


Jonathan M Davis <jmdavisProg gmx.com> changed:

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



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: -------
Dec 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9214




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: -------
Dec 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9214




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/ab9c275962667c0430b3b04b05e566825e91c7aa


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




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Dec 27 2012