OdeToCode IC Logo

Trouble, Trouble, A Quintuple of Double

Tuesday, June 26, 2012
Func<double, double, double, double, double> distance = 
(x1, y1, x2, y2) =>
Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));

A lady once asked me if this code was perfectible
if the Quintuple Of Double was somehow susceptible
to replacing with code still likeminded yet loveable
for the Quintuple Of Double offered feelings of trouble.

delegate double TwoPointOperation(double x1, double y1, 
double x2, double y2);

TwoPointOperation distance =
(x1, x2, y1, y2) =>
Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
I told her the code was still quite correctable 
a delegate type would make her worries reversible
and the one thing worse than a Quintuple Of Double
is the Sextuplet Of Object, then you know you’re in trouble.

Gravatar Steve Ruble Tuesday, June 26, 2012
The parameter order in delegate signature doesn't match the lambda signature. The delegate goes (x1, y1, x2, y2), but the lambda goes (x1, x2, y1, y2). That'll probably make it difficult to invoke the distance instance correctly.

Unless I'm missing the point of the poem...
Gravatar Manu Temmerman-Uyttenbroeck Tuesday, June 26, 2012
Great! Code rapping!
Gravatar Anthony Mills Tuesday, June 26, 2012
Double, double, toil and trouble,
Fire burn and cauldron bubble...
Gravatar scott Wednesday, June 27, 2012
@Steve: ah, yes, that was unintended.
Comments are closed.