Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Type Naming Conflict when Using @Future #181

Open
dwtj opened this issue Mar 26, 2017 · 0 comments
Open

Prevent Type Naming Conflict when Using @Future #181

dwtj opened this issue Mar 26, 2017 · 0 comments

Comments

@dwtj
Copy link
Collaborator

dwtj commented Mar 26, 2017

Consider the executable capsule program seen below.

It uses an @Future procedure. When a compilation unit both declares an @Future procedure and also uses an @Future procedure, that compilation unit will likely need to use two types both named Future

  • java.util.concurrent.Future
  • org.paninij.lang.Future

However, because both of these types are named future, they cannot both be imported. Thus, the author of the code needs to decide which of these two types they need to fully qualify. (In the are fully qualified.)

This is rather awkward, and is likely to be confusing to some programmers.

We should probably rename @Future to prevent this common understandable naming conflict. (Alternatively, we could choose to use our own future type, something other than java.util.concurrent.Future, but I prefer the former.) Unless I am mistaken, I think that we can't use a type as both an annotation and a "normal" Java interface type.

package issue;

import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.paninij.lang.Capsule;
import org.paninij.lang.CapsuleSystem;
import org.paninij.lang.Local;
import org.paninij.lang.Root;

public class Main {
    public static void main(String[] args) {
        CapsuleSystem.start(Client.class, args);
    }
}
@Capsule class SquarerCore {
  @org.paninij.lang.Future
  int[] getSquares(int[] arr) {
    for (int i = 0; i < arr.length; i++) {
       arr[i] = arr[i]*arr[i];
    }
    return arr;
  }
}

@Root @Capsule
class ClientCore {
  @Local Squarer s;
  void run() {
    Future<int[]> f = s.getSquares(new int[] {1, 2, 3, 4, 5});
    try {
        int[] arr = f.get();
        System.out.println(Arrays.toString(arr));
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant