Bill Venners from Artima recently published « How Scala Changed My Programming Style« . This echoes the advise that you should « Learn a new language every year (Pragmatic Programmers) », but this time, this was about Scala (of course):
How did Scala change how I think about programming? In short: I learned to appreciate the functional style. The functional style of programming emphasizes immutable objects, variables that can be initialized but not reassigned (final variables in Java), transformation of data structures, and methods and control constructs that result in a value but have no side effects.
In my programming experience I also changed my Java programming style toward a more functional style thanks to many other influences than learning a new language: patterns and APIs primarily, and even the default suggestions of tools.
Patterns
Some patterns books implicitly document patterns about how to adopt some of the benefits of the functional style in any language, in particular the pattern Immutable (Grand), or Side-effect free functions (Evans), Pipes and Filter (Hohpe), etc.
Classic design patterns such as Iterator, when combined with Decorator, easily yield a functional style of chaining elements together; when also combined with Strategy, for instance for the criterion to filter an Iterator with (in other words a predicate), you can get an equivalent of the higher-order map and filter methods Collect and Select on a collection, and so on.
API
The Apache Commons Collections API provides « standard » interfaces and implementations for this approach, with the interfaces Predicate, Closure and Transformer, the powerful FilterIterator and many other convenient ready-to use classes. This API really suggests to think differently than the usual imperative style.
Recent approaches such as Linq or Quaere « add a querying syntax reminiscent of SQL » to .Net and Java applications, and allow « you to filter, enumerate and create projections over a number of collections and other queryable resources using a common, expressive syntax ». Again, these APIs do suggest to manipulate objects and data in a typical functional style.
Tools
Even an IDE such as Eclipse, when using its default code completion templates often suggest the use of final. Tools such as Checkstyle or PMD also do so. Lots of small hints that together can eventually lead you to have a deeper look at what is functional programming.
Final word
I have to admit however that the authors that I read most were themselves often strongly influenced by Smalltalk, which has a strong functional potential… Also it is rather easy to regard patterns or even APIs as other languages: patterns can form a pattern language, and an API can be considered a kind of DSL
Since we adopted this functional style in my team our code got really smaller, clearer, less buggy (thanks to immutable and side-effect free methods) and much easier to extend, maybe at the cost of more (extremely small) Java classes: but who cares?


