Software Engineering in Swift, Go and Julia Compared
How do class extensions, duck typing and multiple dispatch compare when extending and reusing existing code?
Object-oriented programming is one way to help you organize large programs, but it is not the only approach. Here I compare Swift, Go and Julia in how they tackle reuse of code. Swift takes the OOP approach and supercharges it with interface and class extensions. Go tries to rethink this whole thing by bringing Duck typing into a statically typed language. Meanwhile Julia rejects the whole OOP paradigm and invents its own: Multiple dispatch.
We’ll go through pros and cons of each approach.
Swift Protocol and Class Extensions
If you want to do classic object-oriented programming, then very few mainstream languages can actually beat Swift. Yes, I will argue that languages such as Java and C# which can most directly be compared don’t compare well. But how about something like Python? It is a beloved object-oriented language. Here the comparison is tricky as Python is a dynamically typed language. Swift being statically typed makes for a better comparison with Java and C#.
But what makes Swift such a powerful Object-Oriented language? Class extensions and protocols are the secret sauce to making Object-Oriented programming really shine in Swift. Here is an example from some recent code. I needed to support binary search on…