Comparison of TickDuration and StopWatch.peek

Jonathan M Davis jmdavisProg at gmx.com
Tue Feb 28 11:40:35 PST 2012


On Tuesday, February 28, 2012 20:14:14 Matej Nanut wrote:
> So I can call any (void) method without parenthesis without -property?
> I guess I'll just add -property to all my programs from now on. But
> why isn't .peek() a property? In std.container, for example, the
> BinaryHeap has a .front property (even though it isn't declared as
> such on dlang.org, but the comments say it is one). I find .front and
> .peek have more or less the same meaning, obviously for different data
> structures. The time complexities are probably different as well. But
> I find the meaning to be synonymous. Although this might be a re-run
> of the .by(Value|Key) debate a while ago.

In some cases, you can debate ad-naseum as to whether something should be 
considered a property or not. In the case of peek, SHOO made it a normal 
function, so that's the way that it is. It _is_ different from front, however, 
in that it will return a different value every call if the stopwatch is still 
running, and I could see someone thinking that that would make it so that it's 
not a property. It's certainly debatable though.

> I will create a report later this evening: should it be about D not
> having the same lvalue semantics as C++ or the actual implementation
> of opCmp for TickDuration?

Give your code example and mark it as a druntime bug. It's TickDuration that's 
the issue, not the lvalue semantics. For better or worse, D is not going to be 
changed to allow you to pass rvalues to const ref like C++ will let you do. It 
will continue to insist on lvalues for all ref parameters, const or otherwise.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list