Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

I use Deno for this. It's the only scripting system where you can actually have a single file script with no compilation needed and use third party libraries reliably.

You also get great static types which is nice.



view as:

Interesting! I knew F#, C#, and Elixir supported this scenario, but good to know Deno has this as well :)

Do F# and C# really support it? How do you specify dependencies from within the script?

Yeah! F# has native support[1] and C# can do it with a third-party tool[2]. For both, the syntax for referencing a third-party NuGet package inside the script is e.g.:

    #r "nuget: Newtonsoft.Json"
[1]: https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp... [2]: https://github.com/dotnet-script/dotnet-script

Very interesting, thanks for the info!

Deno is pretty nice for that. There are other systems that automatically satisfy dependencies for single-file scripts. I have gathered a list at https://dbohdan.com/scripts-with-dependencies. I am not sure about their individual reliability, because I have only written one example for most of them, but some are old, have users who rely on them for work, or both.

Great list! I tried a couple of these and found a big issue is IDE support - might be worth checking which ones have IDE support.

Also it seems like F# and C# should be on the list (see other comments in this thread).


Thanks!

It didn't cross my mind to add IDE information. (I don't use an IDE, which may be a mistake. I want to give IntelliJ IDEA a serious try.) I'll be honest: I probably won't add this information. Sorry. N projects × M IDEs is a sizable number of fields to keep accurate by hand, and I've learned this kind of maintenance is best avoided.

I have tried https://github.com/dotnet-script/dotnet-script. It seemed like it could not download dependencies when you ran the script, only reference already installed dependencies. At that point I stopped and did not add it to the list, since it would not qualify. I may have been wrong. I have a mental note to look at it again.

I'll see what F# does. It may work differently from how I understood dotnet-script to work. (It isn't the criterion for inclusion, but as someone who enjoyed writing Standard ML and not so much Haskell, I am actually interested in F#.)


Yeah fair enough. Based on my experience anything that's a third party tool won't have IDE support and is really a bit useless. Even Deno is slightly annoying because it obviously conflicts with the official Typescript IDE support, so at least in VSCode you have to enable it on a workspace-by-workspace basis. And I've had one project where I had "normal" NPM-based Typescript and a Deno script, and it just doesn't work.

F# support looks really interesting though; I'm definitely going to check it out.


I was wrong about dotnet-script: it does download dependencies. (Which makes more sense than the alternative. It would need a good reason to not copy this feature from F#.) I have added C# and F# to the list.

Legal | privacy