His code must have looked like this:
public delegate TResult Func<T,TResult>(T input);
public delegate TResult Func<T,U,TResult>(T inputA, U inputB);
public static TResult Fold<TAcc,T>(IEnumerable<T> collection, TAcc state, Func<TAcc,T,TAcc> f)
{
TAcc acc = state;
foreach(T item in collection)
{
acc = f(acc,item);
}
return acc;
}
//[...]
public int FunctionalMasturbation()
{
int totalWithdrawed = Fold<int,int>(0,_withdrawals,
delegate(int acc, int value)
{
return value+acc;
}
);
//...
}
This is an abomination. Right, for developers with a background in FP, than it's pretty clear what's going on, even if it looks like puke. But in 2007 you could hold a conference for all .net devs with knowledge of Functional Concepts in a telephone booth. arr.sum()Though technically it's not that "array of numbers" is a class, but that array of T implements the interface IEnumerable<T>, and Sum() is extension method defined for IEnumerable<int>
It's even in the standard libs, you don't have to build it. Documentation is here: http://msdn.microsoft.com/en-us/library/system.linq.enumerab...
1) strict typing, but with lots of constructs (e.g. inheritance, interfaces, generics, extension methods) to work around that strictness so that you can do what you want, if you understand the rules and syntax to get it to compile.
2) loose, "duck typing" so you just do what you want, but without compiler checking that it's possible, and with the posibility that it fails at runtime if the right method isn't found.
C# is in the first direction.
http://www.cplusplus.com/reference/std/valarray/valarray/sum...
Only managers would think that
is more readable and maintainable than... Oh look and even though I've written a million for loops depending on the language there is a bug because i didn't intialize accum.