http://d.puremagic.com/issues/show_bug.cgi?id=8845
Summary: Can't pass immediate or rvalue args to ref function parameters Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: turkey...@gmail.com --- Comment #0 from Manu <turkey...@gmail.com> 2012-10-17 16:31:24 PDT --- Consider: float length(ref const(Vector) x); float distBetween = length(p1 - p0); or float speed = length(player.getVelocity()); These don't work, forcing this horrible code: Vector diff = p0 - p1; float distBetween = length(diff); Naturally, if I have a series of these operations, I end up with: Vector diff0 = p0 - p1; Vector diff1 = p1 - p2; Vector diff2 = p2 - p0; And it all starts getting very silly, the local namespace gets polluted very quickly, and sensible temporary names often don't even exist for these intermediate concepts, leading to really stupid names, or just random letters. There's no difference in security. Forcing creation of a function scoped variable just increases the probability of name conflict and inconveniences the programmer. It would be nicer if the temporary was only scoped for life within the functions call, and also un-named, so it doesn't pollute the functions namespace. I've heard arguments about the safety of the operation, but the 'workaround' is just to create a temporary, which has identical security properties. It's also no different than passing any pointer normally (a common suggestion), and no reason to significantly inconvenience the programmer. Perhaps this behaviour could be restricted to ref const, or ref in, if we're getting worried about the safety of the operation? That would perhaps even improve on how behaves now. This is particularly common when working with linear algebra. Vectors, matrices, quaternions are surely the most likely to produce this pattern. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------