When OO and FP meet: returning the same type

In the left corner, we have Functional Programming. FP says, “Classes shall be immutable!” In the right corner, we have Object-Oriented programming. It says, “Classes shall be extendable!” The battlefield: define a method on the abstract class such that, when you call it, you get the same concrete class back. In Scala.Fight! Here comes the … Read moreWhen OO and FP meet: returning the same type

Data Exposure and Encapsulation

TL;DR – Scala lets you expose internal data, then later change underpinnings while maintaining the same interface. The functional Way is an open Way. Internal data is available to anyone who wishes to extract it. “But what about encapsulation??” – horrified OO programmer“We do not fear your code, for you cannot screw up our immutable … Read moreData Exposure and Encapsulation

What FP taught me about OO: Liskov Substitution Principle explained

TL;DR – functional programming taught me that LSP is a special case of PLS: Principle of Least Surprise. One thing that bugs me while reading Java: I’m reading along, come to a method call, ctrl-click on the method name, and get a list of implementations of the interface. IntelliJ can’t tell me exactly what will … Read moreWhat FP taught me about OO: Liskov Substitution Principle explained

Functors: What the funk for?

For all the programmers who don’t deeply grok the lambda calculus terminology — Say you are about to call a method on a container, and that container can give you something back of type Tweet. What you really want isn’t a Tweet, but some part of it, say Tweet.getId(). What if, instead of getting the Tweet … Read moreFunctors: What the funk for?

Abstraction goes both ways

Abstraction is critical to programming. It is the core activity we use to make more interesting and complex programs. Most of us understand abstraction as finding commonalities between different concepts, and modeling these as an inheritance hierarchy. If you are a retail store, then toy cars, trash cans, and pillows are all sellable items.  Thus, … Read moreAbstraction goes both ways

Mental revolution

The book Structure of Scientific Revolutions (1962, Thomas Kuhn) brought the word paradigm into common use. Ideas from fifty years ago about research science apply today to computer science and the software industry. This is one parallel Kuhn makes, extended to illuminate how we think about programming. The human mind does not perceive objects incrementally, … Read moreMental revolution

The confluence of FP and OO

Michael Feathers has a great blog post up today about how object-oriented and functional programming styles are suited to different portions of an application. Specifically, the object-oriented style fits the high-level application components. The original intention of OO was for objects to pass messages to each other, which is suited to a SOA style and … Read moreThe confluence of FP and OO