-
Notifications
You must be signed in to change notification settings - Fork 34
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
Backend-specific source files #500
Comments
One way to do it would be to have the |
I side with @tombentley here, except I suppose a more correct name would be |
But do we want to add |
@quintesse if we do backend-specific in the same source folder using subfolders like you propose then stuff will be in different packages, like I really think putting them in separate source folder is cleaner. I don't think we need |
One aspect of using different directories would be that eclipse would show multiple source folders. That's annoying a lot of the time (I certainly find it annoying that half of ceylon.language is in |
How many modules do you expect with backend-specific stuff, aside from the SDK and a few others? |
For JVM backend -- quite a few, if we're lucky :) |
The truth is that none of us can know that. What we do know is that the easier it is to write modules for multiple backends the more portable modules will be written. |
It's already trivial to write JVM-specific modules because the JVM compiler includes java files by default. It's only marginally harder to write multi-backend modules. |
Well the idea was to ignore that folder and treat the code in it as if it were in a directory one level higher. But I agree it might not be the best option either. But if right now we are able to write:
and make it work, then it would be a shame that to make it work for multiple backends we have to do:
because suddenly we have different Ceylon implementations and are forced to maintain them in different folders away from all the other files. |
Now hopefully with Another thing I can think of (that doesn't seem very nice either) is:
But at least all the files would be together. |
Nice, I would like that. To me the most comon story for And this would serve my purpose perfectly! |
Tako: it would more look like:
And then again you only need the two |
|
Stef, the only thing you changed is the location of the native files, which shouldn't matter. You still need to move the files away to a different folder than the code that's actually using it (in your case |
Well, I find it quite nice that I don't see JS files when I'm working on the Ceylon parts. |
well, I think we are mashing together here 2 separate use cases for "native" code n ceylon project. I am mostly interested in the case where I need to provide native implementation of a platform specific feature, while you are probably just talking about a module that wants to compile to both, JVM and JS backend, so that you could write both server side and client side code in Ceylon. In my case, the |
@gavinking we're still waiting for your take on this. |
I don't really see why there would be specific ceylon sources for a particular backend. If this is to avoid to include too many sources in a compilation to java or to js, I would rather use several modules:
But maybe I'm missing something Do you have use cases / examples of were this would be needed? |
Yes, when you write a Ceylon implementation class that interacts with native stuff. Interacting with a Java API in one case, and with dynamic JS stuff in the other case. |
But like @loicrouchon syas, in that case you could use 2 different modules (something we want to implement anyway). So we'd be talking about the case where we want to have 2 different Ceylon implementations, but they are so trivial that we don't want to turn them into separate modules. So is it worth it to add these backend-specific source folders? (Remember that we'd still be able to have a single Ceylon file interfacing with 2 different native implementations using |
Well, it allows you to write trivial implementations that talk to different backend-specific stuff while writing only Ceylon and not a line of Java or JS. That appeals to me a lot. |
You mean without using any native implementation at all, just different behaviour depending on the backend? Hmmm okay, but that seems like something that you could trivially handle within a single source folder with a simple if-statement, which is something that at least won't confuse Eclipse. |
No you can't because you'd have to import backend-specific stuff and when compiling the code each backend compiler would not be able to typecheck the other backend-specific part. |
Import backend specific stuff? Meaning different |
If you have a module that depends on backend-specific modules, it definitely needs backend-specific code to interact with those backend-specific modules. But have you guys considered just using
Of course we could do something more typesafe than that, if you think it matters. But this splitting stuff across multiple source dirs thing feels overengineered to me... |
Yes, you can do it like this for example (directly from my test module): test.ceylon: shared void run() {
testNative();
}
native("jvm") void testNative() {
myprintJvm(NativeCode().test());
}
native("js") void testNative() {
dynamic {
myprintJs(nativeCode());
}
} and then have: NativeCode.java: public class NativeCode {
public String test() {
return "This is a native Java class";
}
} and: nativecode.js: function nativeCode() {
return "This is a native JavaScript function";
} (you'll need to have the latest code though, I just fixed a bug related to this) |
Oh, so you can. How does the IDE behave in this case? I expect it not to see |
The IDE hasn't changed behaviour for what was already there. |
…ation for that backend (ceylon/ceylon-spec#500)
…wrote the existing one to use it (#500)
Ok, the IDE problem is now fixed. |
…wrong backend but all of them (see ceylon/ceylon-spec#500 and ceylon/ceylon-spec#1286)
…larations without a header (ceylon/ceylon-spec#500 and ceylon/ceylon-spec#1286)
We need to figure out how to have certain files only compiled for certain backends. It could be as simple as saying
.java
files for the JVM backend and.js
files for the JS backend, but we may also want different Ceylon source files for different backends, as glue or something.The text was updated successfully, but these errors were encountered: