| « Announcement: Content Survey Results | A Clean Install » |
"I've lost the will to live," Reacher writes, "or at the very least, debug my coworker's code."
"Whenever this coworker works on a new project, he always insists upon adding in Utils.cs. It's a collection of static methods that he's been building up since a CS class at university, and contains all sorts of useful helpers like this...
public static double Add(double firstNo, double secondNo)
{
double total=firstNo+secondNo;
return total;
}
public static double Add(double[] valueArray)
{
double total = 0.00;
foreach(double val in valueArray)
{
total+=val;
}
return total;
}
public static double Multiply(double num1, double num2)
{
return num1*num2;
}
"Time and time again, he claims they're useful 'in general'...
Re: They're Useful... In General
2008-04-14 08:05
•
by
fraserofthenight
(unregistered)
|
|
Why write something passe like "(a + b) * c)" when you could write the much more descriptive "Utils.Multiply(Utils.Add(a, b), c)". Plus, with the Utils class there's no longer any need to worry about that pesky order of operations. Truly only a brillant mind could have come up with that.
|
|
I think I get it, the real WTF is that he didn't use operator overloading to create his routines.
|
|
If you combine this re-write from Trondster:
public static double Add(double firstNo, double secondNo) { double total = Add(new double[] {firstNo,secondNo}); return total; } with this rewrite from Grovsey: public static double Add(double[] valueArray) { double total = 0.00; foreach(double val in valueArray) { total = Add(total, val) } return total; } you would really be getting somewhere! |
| « Announcement: Content Survey Results | A Clean Install » |