Fantom scripts are great! I can quickly whip up a file of Fantom code to try things out, or write examples for other people to use; and not have to worry about build scripts or pods (which also helps ease newbies into Fantom). But I have a couple of questions / suggestions:
1. Transient Pod Names
Is there any reason why transient pods have illegal pod names?
If I create the script below in a file called Example.fan and run it:
class Example {
Void main() {
echo( typeof.pod.name ) // --> Example_0
}
}
It shows that transient pods have the illegal _underscore_ character. I know I've been disgruntled and caught out by this before, though right now I can't remember the exact circumstance.
Implementation Notes
Should the offending _ be removed from transient pod names, there is a possibility of pod names clashing. For example, I may already have a pod named Example0. But then again, that is what the numeric suffix is for. The suffix could be incremented until a unique name is found.
It may also be nice to append the word Script to the pod name to make it clear where it came from. Example.fan --> ExampleScript0
2. JS files
Fantom scripts are often used to run example code, to quickly show off pods and libraries. Given how popular web apps and domkit are, it'd be great if a script could start up a webserver and serve up @Js classes from same script.
But because transient pods don't have a backing store, looking for files inside them results in an Err:
Pod.find("Example_0").file(`Example_0.js`)
sys::Err: Not backed by pod file: testG_0
fan.sys.Pod.loadFiles (Pod.java:387)
fan.sys.Pod.file (Pod.java:370)
...
Implementation Notes
Now that immutable Bufs can imitate Files, I was thinking that perhaps transient pods could utilise this to have a backing FStore and be more like regular pods.
3. One file, one script
Scripting languages have proven quote popular of late (Ruby, Python, etc...) and in a similar vein it's really convenient to run Fantom files.
But a constraint I often run in to, is being limited to one file. For example, take AppBuilder.fan - it's a nifty script that takes a single pod and packages up a runnable Fantom application by zipping up the Fantom environment - but it only zips up pods, jars, and config files that your application has dependencies on.
The issue is that the AppBuilder.fan file is not re-useable. I have to customise the top of the file and have an ugly === DO NOT EDIT BELOW THIS LINE === comment. If I update the AppBuilder script then it's not just a case of copying the file over. No, I have to edit and cut'n'paste the contents over.
It would be really cool if scripts could import, or use, other scripts.
Implementation Notes
Maybe a form of using could be used to reference scripts (or directories) to be imported:
using [script] path/to/another/script.fan
If scripts are compiled to Buf backed files (as per Note 2) then the script pre-processor could scan the script files for the above using statements and generate a list of source files to be compiled.
brianMon 16 Oct 2017
It shows that transient pods have the illegal _underscore_ character. I know I've been disgruntled and caught out by this before, though right now I can't remember the exact circumstance.
I'd be curios to know why? It works kind of like Java where we use synthetic names that are ok for lookup, but not ok for source code. That makes it safe and avoids complicated attempts to find a unique name which might conflict with pods already loaded; or those you might load in the future (potentially impossible to check for)
Maybe a form of using could be used to reference scripts (or directories) to be imported:
I seriously doubt we will build a new whole parallel infrastructure into Fantom just to avoid compilation and the module system already in place. Its the complexity of preloading all those scripts to get static types which makes it unfeasible.
Although if your types are statically available you can do things at runtime like what the build::FanScript class does
SlimerDude Wed 11 Oct 2017
Fantom scripts are great! I can quickly whip up a file of Fantom code to try things out, or write examples for other people to use; and not have to worry about build scripts or pods (which also helps ease newbies into Fantom). But I have a couple of questions / suggestions:
1. Transient Pod Names
Is there any reason why transient pods have illegal pod names?
If I create the script below in a file called
Example.fan
and run it:It shows that transient pods have the illegal
_underscore_
character. I know I've been disgruntled and caught out by this before, though right now I can't remember the exact circumstance.Implementation Notes
Should the offending
_
be removed from transient pod names, there is a possibility of pod names clashing. For example, I may already have a pod namedExample0
. But then again, that is what the numeric suffix is for. The suffix could be incremented until a unique name is found.It may also be nice to append the word
Script
to the pod name to make it clear where it came from.Example.fan --> ExampleScript0
2. JS files
Fantom scripts are often used to run example code, to quickly show off pods and libraries. Given how popular web apps and domkit are, it'd be great if a script could start up a webserver and serve up @Js classes from same script.
But because transient pods don't have a backing store, looking for files inside them results in an Err:
Implementation Notes
Now that immutable Bufs can imitate Files, I was thinking that perhaps transient pods could utilise this to have a backing FStore and be more like regular pods.
3. One file, one script
Scripting languages have proven quote popular of late (Ruby, Python, etc...) and in a similar vein it's really convenient to run Fantom files.
But a constraint I often run in to, is being limited to one file. For example, take AppBuilder.fan - it's a nifty script that takes a single pod and packages up a runnable Fantom application by zipping up the Fantom environment - but it only zips up pods, jars, and config files that your application has dependencies on.
The issue is that the
AppBuilder.fan
file is not re-useable. I have to customise the top of the file and have an ugly=== DO NOT EDIT BELOW THIS LINE ===
comment. If I update the AppBuilder script then it's not just a case of copying the file over. No, I have to edit and cut'n'paste the contents over.It would be really cool if scripts could import, or use, other scripts.
Implementation Notes
Maybe a form of
using
could be used to reference scripts (or directories) to be imported:If scripts are compiled to Buf backed files (as per Note 2) then the script pre-processor could scan the script files for the above
using
statements and generate a list of source files to be compiled.brian Mon 16 Oct 2017
I'd be curios to know why? It works kind of like Java where we use synthetic names that are ok for lookup, but not ok for source code. That makes it safe and avoids complicated attempts to find a unique name which might conflict with pods already loaded; or those you might load in the future (potentially impossible to check for)
I seriously doubt we will build a new whole parallel infrastructure into Fantom just to avoid compilation and the module system already in place. Its the complexity of preloading all those scripts to get static types which makes it unfeasible.
Although if your types are statically available you can do things at runtime like what the
build::FanScript
class does