Object-Functional and Beyond
Object-oriented and functional programming were once seen as rivals. Objects hide changing state behind methods, and functions avoid state altogether. A newer generation of languages combines them on purpose, and a few research languages go further and mix even more models.
What Defines the Family
- Objects and functions are equals. You can model a domain with classes or interfaces and transform its data with lambdas and pipelines, in the same file.
- Immutability is easy. A short keyword (
val,let) declares a fixed value, and data classes or records make immutable structures cheap to write. - Algebraic data types and pattern matching. A sealed hierarchy or an
enumlists every case, and the compiler checks that each one is handled. - Null handled by the type system. A value that can be missing has a different type (
T?,Option), so forgetting to check is a compile error. - Type inference. You write few annotations, so the code stays short even though it is statically typed.
Representative Languages
| Language | Why study it |
|---|---|
| Scala | Objects and functions unified on the JVM, with case classes, traits, and a powerful type system. |
| Kotlin | A pragmatic, concise blend with null safety and coroutines, and full Java interoperability. |
| Swift | Value types and protocol-oriented design, with optionals and closures, for Apple platforms and beyond. |
| F# | Functional first on .NET, with units of measure and object support when you need it. |
| Oz (Mozart) | A research language that puts functional, object, logic, constraint and concurrent models in one kernel. |
How They Compare
| Language | Platform | Leans toward | Signature feature |
|---|---|---|---|
| Scala | JVM, JavaScript, native | Both equally | Traits, case classes, givens |
| Kotlin | JVM, Android, JavaScript, native | Objects, with functional tools | Null safety, coroutines |
| Swift | Apple platforms, Linux, Windows | Objects and protocols, with functional tools | Value types, optionals |
| F# | .NET | Functional first | Units of measure, pipelines |
| Oz | Mozart virtual machine | All models | Dataflow variables, one kernel |
Beyond Object-Functional
Object-functional languages combine two paradigms that already share a lot: both are about organising data and behaviour. Oz is different. It was designed to show how many paradigms (functional, object-oriented, logic, constraint, concurrent) can grow out of one small kernel language. That makes it less practical for production, but excellent for seeing how the models relate to each other.
Trade-offs
- Many ways to do one thing. A language that supports both styles lets teams write very different code, so conventions matter.
- Learning both worlds. You need to understand classes and also immutability, higher-order functions and type inference.
- Performance. Most of these languages use a garbage collector or reference counting, which gives less control than the systems family.
Go back to Popular Hybrid Languages or the PGP roadmap.