SIP-18. Why?

SIP-18 is a Scala Improvement Proposal. Its intent is … well … to be honest. I don’t get it. But the plan is to introduce a feature in Scala which would disable some of Scalas features. In order to turn these features back on you would have to import them with statement like these:

import language.macros

import language.{structuralTypes, existentials}

So this feature is rather simple and kind of obvious to understand. But what is its intent? The proposal itself says:

The hope is that this will provide a good balance between the wish to provide the most powerful abstraction facilities possible and the wish to control of these features by making their usage more explicit.

Smart people say when looking for the real reason for anything one shouldn’t stop at the first answer to the question “why?” but instead ask again: Why does anybody whish to make the usage of these features more explicit?

It’s quite easy for structural types to creep into a public API unintentionally [..] To give you an idea of the magnitude of the problem, the textual representation of the inferred type was 225kb. Yes, kilobytes.

So there is actually good reason for a way disable some features for those that don’t want punch holes in their feet. We have a problem and we have a solution so everything should be fine, right? I don’t think so.

Lets look at possible alternative solutions first.

code reviews and proper education of developers … mmh, ok that won’t work in most cases.

tools separate from the the language. I think Scala has a perfect setup for this. It allows compiler plugin and naive as I am I would think it should be perfectly feasible to write a tool or a compiler plugin that checks for usage of certain features. It would easily enforceable by a continuous integration setup which by now everybody should use who is working on some serious code.

Lets look at the consequences of the proposed solution second.

It is another language feature, so it makes the beast that is so difficult to tame for many even more difficult. And it is a bad kind of feature in itself. It uses an existing Feature (Imports) in order to do something completely different than the normal usage does (enabling of features vs. managing of namespaces)

It is zero protection for those not understanding the risk or willing to take it or both, even when they are only the minority of the team (note this is not possible with a compiler plugin or a separate tool used in the CI build)

It makes usage of the existing features even more difficult, because now all the little hints and tips found in the internet fail to mention that from version X on you have to make an import to use a certain feature. I’m already waiting for the stackoverflow questions “I want to do Y and do just as described HERE and it doesn’t work”

There is a never ending discussion going on if Scala is complex or complicated or difficult. I think this SIP acknowledges this to be true. Which is a good thing (the acknowledgment). After all you don’t make guns saver be telling everybody these things are harmless.

I think the idea is that these features are hurting the language’s adoption, its maintainability, tooling, and performance. This is a step to remove them without actually removing them. They should probably just deprecate them and print out warnings when you are using them but that probably wouldn’t solve the tooling and tooling performance issues.

I have witnessed the miraculous psychological effect of SIP-18. One colleague – who was averse to Scala out of fear that certain language features would be employed to excess – was visibly moved when he learned of “import language” His face lit up with a smile when I told him about it. He was immediately suggesting that we could set up Jenkins to sound the alarms if someone committed code using a feature we wanted to police. Weeks later he has emerged from Martin’s class at Coursera an enthusiastic advocate of the language.

I know a single anecdote is not data, but I’m certain that had I come to him suggesting that we write a compiler plugin it would not have had the same effect. SIP-18 makes solving the problem something an intern can do using grep.