What are performance and maintenance considerations when using Scala structural types?

My colleagues will not allow me to use them for both reasons. :(

+7
source share
3 answers

The performance consideration is that methods in a structural type are invoked by reflection, which is much slower on the JVM than a regular method call. See this answer and comments for more details.

+9
source

I found that when I need structural types, it is almost always because the library I wanted to use was not designed properly (for example, the absence of superclasses in cases like StringBuilder / StringBuffer).

Therefore, if you want to use structural types for other reasons, this could be a design issue that would be more serious than configuration or performance considerations. A Scala type system is powerful, and using structural types is a bit like a “failure” to get the right “normal” facility. Therefore, if you have code that seems to “require” structural types, try to analyze why this is so, and perhaps ask the community if it can be improved ( https://codereview.stackexchange.com/ seems good place for this) if you are stuck.

By the way, everyone is inclined to overuse the function that he just “crashed”, for example. newbies coincide like crazy as soon as they get the concept, even if there are better ways (for example, in the case of Option functions like map, flatMap, foreach ...).

+9
source

It also depends on how much you use them. M. Odersky and G. Dubochet have some guidelines in their report .

+4
source

All Articles