News for hackers. Stuff that matters.
Re:I finally understand why I'm not allowed to use Lisp by fleitz on Sunday February 20, 2011 @06:15AM (#2241650)
A better question is whose going to maintain all those for-loops that are buggy because human error means even a basic thing like a loop will get screwed up. Managers are always talking about code reuse but as soon as you pass a function, they are like "Woah thats crazy how can we maintain that"

Only managers would think that

  int accum;
  for(int i = 0; i < arr.length; i++){
    accum += arr[i];
  }
is more readable and maintainable than...

  arr.sum(x => x)
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.
Re:I finally understand why I'm not allowed to use Lisp by thomasz on Sunday February 20, 2011 @11:14AM (#2242170)
This was written in May 2007. C# 3.0 was released in August. We are talking about c# 2.0 here. No Lambda syntax, no Linq, no Type Inference, no nothing. Anonymous methods were clearly intended to handle events, and even that was discouraged in favor of On_SomethingHappend(...) methods in the MSDN docs.

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.
Re:I finally understand why I'm not allowed to use Lisp by fauigerzigerk on Sunday February 20, 2011 @06:29AM (#2241662)
Are you explaining the difference between code you have to write and debug and code that someone else has already written and debugged?
Re:I finally understand why I'm not allowed to use Lisp by fleitz on Sunday February 20, 2011 @06:58AM (#2241703)
What I'm saying is that passing functions (or functional programming) allows you to reuse a lot more code than typical imperative programs with a lot less effort. I personally find the functional style to be much more readable and don't understand why everyone has such a problem with the maintainability of code written in a functional style even if it's a mostly imperative language.
Re:I finally understand why I'm not allowed to use Lisp by DougBTX on Sunday February 20, 2011 @08:58AM (#2241852)
I'm not sure where managers come into the discussion, but the second example is good, but even better like this:

     arr.sum()
Re:I finally understand why I'm not allowed to use Lisp by siika2000 on Sunday February 20, 2011 @10:11AM (#2241990)
In what language are arrays of numbers their own class?
Re:I finally understand why I'm not allowed to use Lisp by IDisposableHero on Monday February 21, 2011 @08:53AM (#2245366)
That would be legal in C# 3.5 or later.

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...

Re:I finally understand why I'm not allowed to use Lisp by IDisposableHero on Monday February 21, 2011 @11:36AM (#2245973)
It looks like there's two directions for a language's type system to go:

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.

Re:I finally understand why I'm not allowed to use Lisp by siika2000 on Sunday February 20, 2011 @10:38AM (#2242050)
Re:I finally understand why I'm not allowed to use Lisp by sophacles on Sunday February 20, 2011 @11:03AM (#2242123)
In dynamic languages where arrays can be homogenous, the array can still have a sum method, it just assumes decent coercion rules and overloaded + (or it barfs...).