‹ BackHN Continuity

Thread

cp: -r or -R?

125 points · 107 comments · zdw

  1. dataflow · · focus · HN ↗
    Kind of off topic, but why in the world in 2026 do POSIX utilities still rely on global variables to pass around state? Is it too complicated to pass around a struct address in C or something?
    1. turtledragonfly · · focus · HN ↗
      I think there is a class of programs where globals are not so terrible. In particular, one-shot programs that do a task and then exit (like `ls`, `cp`, etc).

      You may also notice that some of these utilities will allocate memory, then never free it. They just let the OS handle that on program shutdown. That is also generally not recommended in arbitrary code. But again, it's fine for a one-and-done sort of program.

      For these cases, the whole program is essentially one function call, and the global namespace is essentially the "body" of that function (hand waving a bit).

      It's all a bit subjective, of course (:

      1. Bjartr · · focus · HN ↗
        Reminds me of the story of the memory leak in a missile guidance computer. It was determined that in the worst case scenario not enough memory could leak fast enough for it to be a problem between missile launch and impact. So they just let the explosion handle the garbage collection
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.