D's default package manager already allows you to write code like this which 1. runs the code like a script 2. downloads dependencies if they are required.
#!/usr/bin/env dub
/+ dub.sdl:
name "allthepythons"
dependency "d-glob" version="~>0.3.0"
+/
import std.stdio : stdout;
import glob : glob;
void main () {
foreach (entry ; glob("/usr/local/bin/python*")) {
stdout.writefln("%s", entry);
}
}
Re:My Vision of D’s Future
by 1980phipsi on Tuesday October 15, 2019 @08:58PM
(#21265943)
Dub's documentation should use some love...
Re:My Vision of D’s Future
by paulddraper on Tuesday October 15, 2019 @05:48PM
(#21264264)
D already works like this.
Scala (Ammonite) works like this.
The author isn't complaining about keystrokes; he wants the compile + run process to be faster. Using an interpreter instead of a compiler would make it faster.
Java has the same now (since Java 9 I think).
So you're saying it's as simple as:
java build ./app/ ./app
That's impressive if true as last I worked with Java it was a mess
Not quite. You can run `java Foo.java` and it will compile and execute the class file (and remove it when done).
D compilers do work as a shebang already.
I actually use this for all of my complicated build scripts and just use make to glue them together. For instance I have a stack name from computer,branch,sha,username that I calculate so I have a different stack per thing I'm working on. I tried getting that to work with awk fu but doesn't work the same on every platform, so instead "go run cmd/get_stack_name/main.go" instead. Fast and like it.
This means Go lends itself pretty well to ad-hoc scripting or writing small script-like tools.
Unfortunately, Go doesn't support shebang lines, but with gorun [1] you can:
[1] https://github.com/erning/gorun