Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A lot of these bloated patterns that got popular in the Java world have shorter, simpler alternatives when programming in a functional style. You often don't need multiple child classes to implement a template method if you can just pass a function to the constructor. You don't need a BananaFactory if you can just inject a createBanana function.

Remarkably many Gang of Four design patterns are unneeded once you can pass functions around. The C# world is now learning this: when C# 1 and 2 were popular, the ecosystem went right after Java in the kinds of boilerplate that the author describes. Now, many years of Func and Action goodness later, there's a large part of the community that codes way more to the point, and this part is growing. People who release C# libraries in 2014 with factories adapters and multiple layer inheritance hierarchies are laughed at.

Since Java 8, Java too has an accessible way to pass functions around. Not really functions, because Java, but in practice it works the same way. This means that there's nothing technologically that's holding the Java community from making these improvements, too.

I hope it happens.



I don't think Android supports Java 8, though.


I don't think Android supports even Java 7. Sure, maybe source level but AFAIK invokedynamic and method handles are still missing.


There's a thing called RetroLambda which purports to be a backport of lambdas to older versions of the runtime/platform.

However hopefully now ART is successfully launching they'll go back to upgrading the base foundation and move it beyond Java 6.


I thought there was some work to support Lambdas in ART?


There is a retro-lambda library that allows to write lambda expressions. It is compiled to jdk 6 compatible bytecode though.


I like your comment. Do you have any examples of C# libraries that use the ideas you're talking about? Or even better - do you know of a tutorial or something where I can clearly see the two approaches compared and contrasted?


Nancy: http://nancyfx.org

Contrast that with Microsoft's WCF: http://www.codeproject.com/Articles/105273/Create-RESTful-WC...

Quartz: http://www.quartz-scheduler.net (hint: it's gigantic)

Contrast with

        private void ScheduleRepeated(Action task, TimeSpan interval)
        {
            Task.Run(async () =>
            {
                while (true)
                {
                    await Task.Delay(timeSpan);
                    task();
                }
            });
        }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: