TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Perfect language to use for hopefully widespread Unix prog?

3 点作者 sunmountain超过 16 年前
Imagine you need to write a program (script, if you like), which needs to run on as many *nix clones as possible out of the box.<p>Which language would you choose ?<p>Perl, Shell, C/C++ with binaries pre-compiled ?

4 条评论

SwellJoe超过 16 年前
If the project is larger than trivial: Perl, unless you need an X-based GUI.<p>Shell has the problem of being inconsistent across several platforms.../bin/sh on Linux systems (except Ubuntu) is BASH, but on FreeBSD, Solaris, and others it is a classic shell. If you are extremely careful, you can write in very standard sh, but it's a pretty challenging language to build anything bigger than 100 lines or so (I built our installer in sh, and I've regretted it ever since it grew up to about 300 lines...it's now at 1143 lines, and I'm in the midst of translating it to Perl, where it will be dramatically shorter and more powerful.<p>Anyway, Perl is pervasive, and has been backward compatible for about a hundred million years. I have code that I wrote 11 years ago that runs unmodified on modern Perl 5.10. This means that if you target, say, Perl 5.8, you can expect your program to run on any system that has pretty much any Perl version less than 7 years old. (If you go back too far, you lose a lot of really nice features that make programming in Perl enjoyable. Unicode didn't get perfected in Perl until 5.8.2, I think, maybe 5.8.4, so we consider that our baseline and what we target.)<p>Python, while it's very nice and also widely available on many platforms, is <i>not</i> particularly backward compatible. If you target Python 2.4 or 2.6, it will not run on Python 2.2. If you shoot for a least common denominator, you will <i>still</i> find there are some incompatibilities. I worked on several Python projects a few years ago during the transition from 1.5 to 2.0, and that code required serious changes...then several minor changes from 2.0-&#62;2.2-&#62;2.4. I wasn't around on those projects when 2.6 came along, nor 3.0, but I get the feeling that both required some changes and brought some incompatibilities. While this may lead to a cleaner language, it means you have numerous concerns about cross-platform compatibility, and your testing requirements go <i>way</i> up. My Perl testing environment consists of a Perl 5.8.mumble installation, and nothing more. If it runs there, I know it'll run on every version from then up to 5.10.x, which spans about seven years worth of Perl versions.<p>Binaries are practically impossible for this task. People expect native packages, which are extremely time-consuming to build and test. Linux distros break backward compatibility in their libraries regularly, so you'll have to ship statically linked binaries. On platforms that don't break backward compatibility, like Solaris, you still have to assume a pretty minimal environment, since those systems are quite anemic on the library front, so again, you're shipping statically linked binaries. And, the moment you get a customer that wants it for some whacked out platform like HP/UX on Itanium, you'll be kicking yourself...and you <i>will</i> get customers running bizarre systems, if you call yourself cross-platform.<p>If you need an X-based GUI, Tcl/Tk might still be the best choice (five or ten years ago it was the only sane choice for such a creature). Perl has good bindings for Tk and WxWindows, but neither is likely to be available. Python has Tk bindings out of the box, so if you hate Tcl, and like Python, and need a GUI, this might push Python into the lead. The biggest problem with Tcl is that it's just not very active or growing. Perl and Python, on the other hand, have very vibrant communities. All are pretty good languages, though, in their own way...though I never really got the hang of Tcl whereas Perl and Python seemed pretty natural.<p>To pile on the anecdotal evidence, my co-founders project, Webmin, is probably one of the most cross-platform pieces of software in existence...supporting at <i>least</i> 150 different operating systems and versions (the last time I counted in 2003, it added up to about 150 variants, not including architectures, and probably 30 or 40 new variants have been added since then). It's about 350,000 lines of Perl, plus a touch of sh for the installer.<p>Of course, this assumes all things being equal. Do you hate Perl? If so, it's probably not worth working in it just for compatibility (though I suspect you don't know modern Perl very well, if you truly hate it). You can just tell your customers to install Python, if they don't have it, or upgrade if they do. I find the two languages roughly equal in terms of how much I like working with them, and how productive I can be.<p>The other cool choices, like Ruby, Lua, Lisp, Haskell, all have the problem of being unavailable, by default, on most UNIX systems...and so you'd have to support your users in installing the language, as well as your app.
评论 #471555 未加载
davidw超过 16 年前
Depends what it needs to do, of course. Can you tell us a bit more?
cperciva超过 16 年前
C has worked pretty well for me.
评论 #471552 未加载
评论 #471553 未加载
评论 #471630 未加载
RiderOfGiraffes超过 16 年前
Python
评论 #472116 未加载