My co-workers wont let me use them on both grounds. :(
Structural typing as defined by Wikipedia “A structural type system (or property-based type system) is a major class of type system, in which type compatibility and equivalence are determined by the type's structure, and not by other characteristics such as its name or place of declaration “ Structural types in Scala ...
Gettings Our Ducks in a Row Fortunately, Scala allows us to write idiomatic code to achieve the same results as duck typing.
A performance consideration is that the methods in a structural type are called via reflection, which is a lot slower on the JVM than a regular method call. See this answer and comments for detailed info.
I found that when I need structural types, it's almost always because a library I wanted to use isn't designed properly (e.g. missing superclasses in cases like StringBuilder / StringBuffer).
So if you want to use structural types for other reasons, it might be a design problem - which would be more serious than configuration or performance considerations. Scala's type system is powerful, and using structural types is a little bit like "giving up" to get it right with "normal" means. So if you have some code that seems to "require" structural types, try to analyse why it is that way, and maybe ask the community if it can be improved ( https://codereview.stackexchange.com/ seems like a good place for this) if you are stuck.
BTW, everybody tends to overuse a feature he just "grokked", e.g. beginners pattern match like crazy once they get the concept, even if there are better ways (e.g. in case of Option functions like map, flatMap, foreach...).
It also depends in how much you use them, M. Odersky and G. Dubochet have some benchmarks in their report.
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