Is there already any collection of best practices for languages like Scala?
I've found a work on design patterns for functional languages, Design patterns for functional strategic programming. There's GoF design patterns for OO languages. But are there any patterns for functional-OO hybrids? All I've seen is this list. What is known?
In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID. The functional programming community has design patterns and principles as well.
Decorators are wrapper functions that enhance the wrapped function. You don't change the original function behavior, instead you decorate it with new behavior, achieving extensability and composability.
Two patterns from Bill Venners; I think both are heavily used in ScalaTest:
Stackable Trait (similar in structure to the decorator pattern, except it involves decoration for the purpose of class composition instead of object composition).
Selfless Trait (allows library designers to provide services that their clients can access either through mixins or imports).
Type safe builder
Independently Extensible Solutions to the Expression Problem - just like the "Scalable Component Abstraction", it's not a pattern catalog, but it also deals with similar problems (e.g. the Visitor pattern)
Deprecating the Observer Pattern - an alternative to the Observer.
We can also consider the Scala emulation of Haskell type classes a design pattern. The first description (that I could find at least) is in Poor Man's Type Classes. Quite some blog entries are also available with this topic.
And I think I'm not completely wrong if I also mention the various monads. You can find a lot of resources dealing with them.
While not directly a design pattern catalog itself, the paper "Scalable Component Abstractions" (Martin Odersky; Matthias Zenger) examines three building blocks for reusable components:
And it revisits several design pattern (publish/subscribe, subject/observer, Context/Component) to illustrate and understand what language constructs are essential to achieve systems of scalable and dynamic components.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With