Live data from Hacker News

Why are there both TMP and TEMP environment variables? (2015)

devblogs.microsoft.com

41–50 of 102 posts

Re: Why are there both TMP and TEMP environment variables? (2015)

#41

Earlier quoted context omitted.

Well, they are supposed to be all in .config, problem is many app developers think they are special little boys that deserve its own directory

It all sounds so easy, until you learn about the XDG Base Directory Specification[1]. You're actually supposed to do a whole song and dance around a hierarchical set of environment variables, associated defaults, and resolution orders. Interfacing with people is never easy. [1]: https://specifications.freedesktop.org/basedir/latest/

No. Actually, it's easy. Just check for directory env or use a fallback. For example here's how you'd do this in bash:

    export CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
    export CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
    ...
XDG_*_DIRS are a bit more complicated, but nothing that can't be solved with a simple for-loop in any modern programming language.

Re: Why are there both TMP and TEMP environment variables? (2015)

#42

Earlier quoted context omitted.

If people just followed the XDG Base Directory Specification, config file littering would be a non-issue. More and more projects adopt it, even holdouts like Firefox.

I wonder how many apps actually read the correct XDG environment variables and obey them, versus just hardcoding paths that match their machine’s config paths (typically ~/.config/*) I almost want to set up a VM that sets up XDG_CONFIG_HOME as ~/.foobar and see how many apps actually respect it, and how many still write to ~/.config.

A few years ago I had a Windows box where I pointed XDG_CONFIG_HOME et al to the corresponding-ish Windows paths (AppData subdirectories, mostly) so that the many Linux-derived CLI programs I was using wouldn't clutter up my userdir, and it worked pretty well, though there were a few programs that didn't get the memo. Unfortunately I don't remember which ones they were. Most programs get it right, though!

Re: Why are there both TMP and TEMP environment variables? (2015)

#43
post #20

I'm confused by the CP/M reference. Author says it'll be important later then proceeds to explain how it had nothing to do with CP/M or the 8080 CPU.

Agree, CP/M has nothing to do with the story, nor does the 8080/8086 sidetrack.

The whole story is that Microsoft just never bothered to standardize, despite using it themselves.

Re: Why are there both TMP and TEMP environment variables? (2015)

#44
post #39

Earlier quoted context omitted.

Just a few lines below: "Over time, programs were written with MS-DOS as their primary target, and they started to realize that they could use environment variables as a way to store configuration data. In the ensuing chaos of the marketplace, two environment variables emerged as the front-runners for specifying where temporary files should go: TEMP and TMP." And before that there are a few paragraphs describing the…

I was curious seeing this thread, and I just looked and don't get it either. AFAICT the CP/M references could have been entirely omitted and nothing in the narrative about TMP and TEMP would change.

Except that DOS was made to have its first programs ported from CP/M, so it’s relevant to explain that there were no environment variables to inherit from CP/M and no developer habits or program standards to inherit from CP/M programs.

Re: Why are there both TMP and TEMP environment variables? (2015)

#45
post #7

Earlier quoted context omitted.

Yes, it was definitely a thing. The patching code had to be in Z80/8080 machine code. I wrote higher performance keyboard and display routines for my copy of Wordstar using this feature.

Stuff like that is also cool (reminds me a bit of modding some games), patching machine code to improve performance of a compiled app? Very cool! (My dad might have done that, he has an old ZX81) But I thought specifically patching something to configure it is such a weird concept that I never would have thought of.

The ZX81 didn't have so much software around for it - what there was mostly came on tape, or was typed in¹ on the ghastly membrane keyboard, and what there was was very limited in capability (the default RAM size was one kilobyte (yes, just 1024 bytes, though typically you'd buy a "ram pack" upgrade to 16k). Then it was very rapidly superseded by the more capable ZX Spectrum machine. So odds are your Dad didn't patch software on the ZX81 because it was usually already highly optimised to squeeze it into the tiny space available.

What was very common on those devices was using the "poke" command in BASIC to change a handful of values, but while it was possible to change code in this way it was much more common to be changing the value of variables - things corresponding to "number of lives left" and the like. Not all that different.

Fairly quickly, though, the games were entirely in machine code and used fancy loaders (still from tape mostly) so you didn't get access to BASIC. This created a market for devices that let you get at a monitor program - the "Multiface" series of addons². They had at least three generations of that device, but the company slightly weirdly evolved into a music production company³ after that, which is kind of cool.

Er, ok, I'll stop now while I still can...

Edit: PS - you should ask him about it. Tell him another former ZX81 owner says "Hi" and that my fingers still ache from that keyboard. Although I sneer a bit at its capabilities, it kicked off an interest in computing that's still paying the bills 40 something years later...

----

¹ https://spectrumcomputing.co.uk/entry/2000265/Book/Not_Only_...

² https://en.wikipedia.org/wiki/Multiface

³ https://en.wikipedia.org/wiki/Romantic_Robot

Re: Why are there both TMP and TEMP environment variables? (2015)

#46
post #39

Earlier quoted context omitted.

I was curious seeing this thread, and I just looked and don't get it either. AFAICT the CP/M references could have been entirely omitted and nothing in the narrative about TMP and TEMP would change.

Except that DOS was made to have its first programs ported from CP/M, so it’s relevant to explain that there were no environment variables to inherit from CP/M and no developer habits or program standards to inherit from CP/M programs.

Which is irrelevant to TMP or TEMP.

It could simply be: When envars were added to MSDOS…

Re: Why are there both TMP and TEMP environment variables? (2015)

#47
post #15
post #2

1995-ish. Telstra (Australia Telecom). Probably about 50k desktop computers across the organisation. One day a small file turned up in everyone's network home directory called null. A *nix person had evidently had a go at writing a .bat file. Why do we need to adopt extant standards? (I was going to ask, why standardise? But realised that might confound the North Americans. : )

What text was in there that he tried to discard?

Asking the real questions!

Re: Why are there both TMP and TEMP environment variables? (2015)

#48
post #5

> My recollection is that most CP/M programs were configured via patching. At least that’s how I configured them. I remember my WordStar manual coming with details about which bytes to patch to do what. There was also a few dozen bytes of patch space set aside for you to write your own subroutines, in case you needed to add custom support for your printer. Huh. That is interesting, it was before my time, and I never…

> > My recollection is that most CP/M programs were configured via patching.

> Huh. That is interesting, it was before my time, and I never heard of this :D

Yep, it was a thing, and for /some/ programs that were originally CP/M programs (i.e., WordStar 7.0 for DOS) it continued for a long time. The WordStar 7 documentation included patch locations to use (this time, IIRC, for DOS debug.exe) to change various behaviors of the program.

Re: Why are there both TMP and TEMP environment variables? (2015)

#49
post #28

OK. I love Raymond’s blog but this is crazy. Microcomputers existed only as a prototype in 1973 (things like Intel’s Intellec dev systems) and there were no operating systems for them. Strictly speaking, Kildall did start developing CP/M in 1973, but at that point it ran only on a simulator on a PDP-10 mainframe. 1979, sure. 1973? Way too early…

Wikipedia says it was created in 1974, so something's definitely off with the time line here.

Re: Why are there both TMP and TEMP environment variables? (2015)

#50
Environment variables on *nix are ... strange.

I noticed this first when I assigned TZ to .tar.xz (or .tar.gz) as I was lazy. Then things suddenly no longer worked. Turns out TZ is ... timezone. So you should not define all variables, right? Well ... how to know that? People can perhaps read tons of documentation, but I want to ... minimize time investment here. So I learn mostly by learn-and-doing. And as far as I know there is no trivial way to know about "this can be dangerous". Those shells are fairly simple at all times - and not that sophisticated.

TMP versus TEMP may also be trivial but ... who can remember the differences? And why is it important?

I have come to think that environment variables are useful; I use them all the time. But they are a bit hackish and not super-elegant and may have side effects. This is not a very important side effect per se, as most people will not run into issues such as TZ or having to think which variable to use and which not, but in the moment when you DO get surprising results, and you don't know why, this may become a problem suddenly. I kind of semi-work around by prefixing via:

   MY_
This is even less elegant, to then have e. g.:

   MY_TEMP = /home/x/temp/
or something like that. But with the prefix "MY_" I rarely run into problems. So this then becomes my main pointer, e. g. MY_TEMP_DIRECTORY, and then TEMP and TMP may just be aliases to that. It's a bit stupid but it is also simple and kind of works. Beauty is not to be found here, but it is practical and that is not a bad thing.

In my own ruby code I also have to use ENV[] sometimes, which is a wrapper over environment variables, but I also try to be as independent as possible from that. For instance, all my settings are stored in simple .yml files, and these are then used to autogenerate environment variables or handle things in environments where there are no environment variables available (this is sometimes the case; I had that issue with .cgi files many years ago, where I wanted to access all environment variables but for a reason I don't fully remember, this was not available. Then I transitioned into those .yml files and that problem went away; now of course I need to load those .yml files, if necessary, but this is trivial in ruby, YAML.load_file() works very well for the most part, and I find this is more reliable than depending on reading environment variables output. On some restricted environments this may be unavailable though; I had that on university campus running ancient linux systems, so I have to be flexible in this regard).

Post reply on HN