Skip to content

Feature request: support for specifying the strategy on a per local-surgery basis #9

Open
@andrewdbate

Description

@andrewdbate

Currently, optimization strategies are specified by an import, such as:

import scalaxy.streams.strategy.safer

However, this results in all optimizations in scope being performed using the same strategy. Usually, this either means all optimizations in the same file have the same strategy applied, or you have lots of imports in local scopes (e.g., within methods) .

What’s more, both the Eclipse and IntelliJ plugins for Scala have an imports cleanup tool that automatically remove unused imports. You would not expect that running this tool would change the semantics of your code, but with strategies specified this way, it can.

Although Scala language features can be turned on with imports, the IDE tools have support for this, and thus do not remove such imports (and even if they did, you would get compile time errors or warnings). In all likelihood, given the current rate of plugin development for Scala, it is unlikely that the Scala plugins will support Scalaxy strategy imports any time soon.

Therefore, I would like to suggest that strategies can be additionally specified as follows:

optimize (safer) {
   // code goes here
}

That way, the IDE can never mess anything up. Also, if you specify the strategy at the local surgery site, then this should override the strategy imported (if any). This would allow you to write things like:

import scalaxy.streams.strategy.foolish
optimize {
  // Code here
}
…
optimize (safer) {
   // More code here
}
…
optimize {
   // Even more code here
}

I believe that since the semantics depends on the strategy used, it is quite important to have the strategy specified as close as syntactically possible to where local surgery is performed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions