忘记国旗和脚本:只需重命名文件。
Forget Flags and Scripts: Just Rename the File

原始链接: https://robertsdotpm.github.io/software_engineering/program_names_as_input.html

这个概念提出了一种新颖的程序配置方法:将所有必要信息直接嵌入到文件名中。程序不再依赖于容易丢失或特定于环境的标志或脚本,而是*读取*自身的文件名来确定其行为。 这创造了自包含、可立即共享的执行文件。例如,安装程序可以根据文件名中的模块名称进行调整,人工智能实验运行器可以根据名称中的参数进行配置,简单的实用程序可以由文件名关键词触发。甚至可以通过运行重命名的文件来启动复杂的设置,如P2P VPN隧道。 核心思想是通过将文件名作为程序的接口来消除设置和配置的麻烦,从而实现可移植性、可重复性和易于共享,只需一个重命名的文件即可。它挑战了传统方法,并为各种应用程序提供了简化的体验。

## 忘记标志和脚本:只需重命名文件 - 摘要 最近的 Hacker News 讨论围绕一篇博客文章,文章提出了一种非常规的方法来配置可执行程序:通过重命名文件本身来嵌入参数。程序不再使用命令行参数或脚本,而是读取其文件名来确定其行为。 虽然作者将其呈现为一种潜在的有用技术,但回应大多是批评。提出的担忧包括增加版本控制的复杂性、混淆标识和配置、难以发现入口点以及与标准参数解析相比效率低下。许多评论者指出,这种方法可能导致混乱且难以维护的系统,尤其是在处理复杂的参数或需要共享配置时。 配置文件、包装脚本或利用现有工具(如 `exiftool`,它将选项嵌入文件名中)等替代方案被认为是更实用和可维护的解决方案。一些人承认这个想法的新颖性,将其与 Busybox 或 pip 的入口点等现有技术进行比较,但最终认为这是一种hacky且效率低下的方法。核心观点是,虽然巧妙,但为了配置而重命名文件会带来比解决的问题更多。
相关文章

原文

Programs usually get input from flags or scripts. But there’s another way: a program can read its own filename. That means the entire configuration can live in the file name itself, making programs self-contained, portable, and instantly shareable.

Why not just flags or scripts?

Flags are ephemeral – you have to share the command line or wrap it in a script. Scripts depend on environment, which can break portability. Filenames solve both: the program describes itself, requires zero setup, and any configuration can be shared by simply renaming the file.

Example 1: Reusable installers

Imagine install_PY3_MODULE_NAME.exe. It reads the filename, extracts the Python module name, downloads dependencies, sets up Python if needed, and creates a launcher. Rename it, and you have a new installer for a different project. Icons, mirrors, or other metadata can also live in the file as resources – all self-contained, all shareable.

See my exploration: here

Example 2: AI experiment runners

ML experiments usually require scripts, configs, and data setup. Imagine a single executable:

train---resnet50---lr0.001---batch32---cifar10.exe

It parses its filename, downloads datasets, sets hyperparameters, installs dependencies, and runs automatically. Rename it for a new model, dataset, or parameters.

Share the file, reproduce instantly.

Example 3: Ephemeral utilities

Small ad-hoc tasks can also be encoded in filenames:

compress---photos---high.exe
backup---home---encrypt-aes256.exe
fetch---api.github.com---repos/owner/project---q=stars>100---o=json.exe

Each file does its job immediately. Rename to perform a new task. Share it. No setup, no instructions. Everything is self-contained in the name.

Example 4: P2P VPN tunnels

VPNs between friends are usually tricky to set up. Imagine:

lounge-room---friends-machine---t25565---minecraft.exe
  • First two parts: machine names, automatically registered with a server using ECDSA keys.

  • Third part: ports to open.

  • Optional: description.

Run the file to open one side of the tunnel. Rename for new endpoints or ports. Send to a friend, they open their side, tunnel is connected, game on. No config, no editing, zero friction.

Closing thoughts

This approach collapses configuration, portability, and reproducibility into a single artifact. It challenges conventional assumptions: using filenames as the interface. For installers, AI experiments, utilities, or even VPNs, renaming the file is all it takes to change behavior.

联系我们 contact @ memedata.com