stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [STUMP] Style question: FFI vs. CLI


From: Shawn Betts
Subject: Re: [STUMP] Style question: FFI vs. CLI
Date: Thu, 12 Apr 2012 22:18:43 -0700

On Thu, Apr 12, 2012 at 1:34 AM, Duncan Bayne <address@hidden> wrote:
> Guys,
>
> I have a style question, being new to CL and StumpWM: should I be
> using FFI to invoke the XRandR libraries, or should I be shelling out
> to the xrandr CLI tool and parsing the output?

It's always better to go FFI rather than parsing command output.
You'll get more precise access to features, better error handling, and
faster functions.

> My (strong) gut feel is that it'd be better to use the XRandR
> libraries ... but playing devil's advocate there's already a perfectly
> workable CLI tool for XRandR, and it seems pretty easy to invoke such
> things & parse the output (see e.g.
> http://news.ycombinator.com/item?id=1851948).

If you don't already know cffi or a specific lisp's ffi then it might
seem like writing a ffi program is hard. I have tried calling shell
commands and parsing output and have switched to directly calling
library functions through an ffi every time. Writing foreign function
code is easy--as long as it's a C library. Unless the command line
tool does a bunch of work that you really don't want to rewrite in
lisp there is no reason I can think of that you'd want to parse
another program's output. I guarantee you'll spend at least as long
dicking with regex's or wishing the tool had some switch or option
it's missing. In the end the ffi program will be more robust and give
you greater flexibility. It's worth doing if possible.

That said if your needs are simple maybe just calling the cli tool is easier.

-Shawn



reply via email to

[Prev in Thread] Current Thread [Next in Thread]