Hacker News new | past | comments | ask | show | jobs | submit login

I'm a fan of Go's "go run". For example, you can do:

  go run main.go
or:

  go run ./cmd/server
When invoked this way, Go compiles your code behind the scenes, but you don't have to create a binary.

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:

    #!/usr/bin/env gorun

    package main

    func main() {
      println("Hello world!")
    }
[1] https://github.com/erning/gorun



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);
        }
    }


Dub's documentation should use some love...


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: