2

What would all you guys say is a good (preferably easy) language for writing CLI applications? Something that runs fast, the less dependencies at runtime the better, and (this goes lower on the list)of thess logic required for argument handling the better.

Comments
  • 0
    PHP
    Golang
    Swift
    Python
    Bash

    Depends what you're doing at the cli level.
  • 1
    Ruby
    Python
    C++
  • 0
    @C0D4 php? Swift? I'm talking in general, forget what it interacts with, what would be the language of choice?

    @Root but can you say compile ruby to a binary? Or does it also need a runtime (like Python)?

    C++ I've got to learn some day
  • 1
    @chabad360 how does it not matter what it's being used for?

    Yes php can be ran at cli and swift is open source so can also be used in cli.

    Honestly, if you're just making a cli tool just for the sake of it, use anything you're already comfortable with.
  • 1
    @chabad360 Ruby needs the interpreter. However, there is a (very alpha) variant called Crystal that's statically typed and compiles.
  • 0
    @C0D4 it does matter sometimes, but I'm generally making some small tools, and (at least) in my case it doesn't really matter.

    @Root thanks for that! I'll definitely have a look. One question tho: Is it fast?
  • 2
    @chabad360 I can't speak to Crystal, but plain Ruby is probably more than fast enough for whatever you're doing? But if you need pure speed, the answer is always C. Or Assembly.
  • 0
    @jurion I plan on trying it out actually, but it makes it very annoying to distribute...
  • 1
    @Root ik, I would actually like to learn assembly at some point (soon).
  • 2
    The C family does pretty well here. The major operating systems all have advanced console control APIs available in c/c++. There are lots of curses libraries in every language but not many Windows libs so you may need c/c++ for that. That being said, I think your BEST bet is c#

    It has cross-platform basic console control available out of the box and isn't too difficult to write. It's overlooked in CLI because it's way more often used in GUI but C# is very very good for the basic program's needs.
  • 0
    @AlgoRythm I have learnt C#, and as I use Linux I've been hunting for a good excuse to work with it again. But do you know any good ways for handling arguments?
  • 1
    @chabad360 I've actually never really used them much. My design is to set up a faux GUI in the console and accept user input that way.

    In what way do you need to handle arguments? When I have done it, I just iterate over them manually at startup and analyze them. If they start with a single dash I analyze them character by character, and double dashes are human readable so I just do string comparisons.
  • 0
    @AlgoRythm my main issue with that, is if you want to use such a tool in a script, it's down right impossible...

    That's an obvious approach, but I find it to be a massive pain...

    Maybe when I'm bored, I'll write a lib do handle it...
  • 1
    @chabad360 shouldn't be too hard of a lib. But I think dealing with arguments is a pain, any way that you slice it.
  • 0
    @AlgoRythm true, but if you, say make it virtually autonomous, and all you have to say is what are the expected args and what needs to happen, you avoid that issue entirely.
  • 0
    Ocaml, scala
  • 1
    @chabad360 some libs you can check out: https://stackoverflow.com/questions...
  • 0
    Python and it's argparse library make writing CLI applications pretty straightforward. There's also lots of guides and tutorials.
  • 0
  • 0
    I'd vote for Bash, Python and Go.
  • 0
    Pretty much any language would work just fine here tbh. I'll pitch in Haskell and the Haskeline library for CLI programs.

    Minimum runtime dependencies would probably be systems languages like C, C++, Rust etc. since most of their dependencies are in the OS itself.
  • 1
    @SunnySoldier357 thanks a lot for that!

    @simondo92 yes I know of it, and I actually like it, aside for one thing... Speed. Any Python CLI I've encountered, is slow...

    @ethernetzero Bash is good for scripts not CLI apps. Python, see above. Go I've never tried and I want to learn it, but do you know if any good ways for parsing arguments?
  • 2
    @chabad360 Does your idea of a “CLI app” require the app itself to be compiled in binary form? Because I disagree. You can definitely write a CLI app using Bash, and you can definitely parse arguments using the getopt builtin command, and it's not even a hard thing to do at all.

    Also, dismissing Python because it requires having a runtime installed is the same argument that could be made about .NET. Entire applications, both GUI and CLI, are written in Python and you might not even know it. The argparse library, that comes bundled with Python already, is really good for argument parsing.

    About argument parsing in Go, it already comes with a module for that, called flag. There are third party modules out there that add features to it, but it already comes with batteries included.
  • 1
    @ethernetzero no, it doesn't need to be compiled, but that happens to be faster, easier to distribute (like a bash script or python script, but see my issues below).

    I know what you can do In bash, I've tried it alot, but it's really not very convenient at all, and requires a fair amount of extra logic just to work, plus getopt/s has its own set of issues.

    Pythons main issue isn't that it requires the runtime, it's that it's slow, dotnet isn't. When I first encountered the argparse lib I really liked it, but then again, it's just slow...

    Great to know about Go, once I sit down and actually learn it, I'll definitely have a look at that.
  • 1
    @chabad360 You could have a look at the command line extensions package on nuget
  • 0
    @Krokoklemme I actually came across it recently, and plan on trying it out
Add Comment