About cutting corners

Original author: Rob Pike
  • Transfer
Long ago, when developed Unix filesystem, it appeared "pseudo-files" .and ..to make it easier to move between directories. It seems to have ..been added in Version 2 when the file system became hierarchical (in the first version it was organized in a completely different way). But these "pseudo-files" littered the output ls, and either Ken or Dennis added a lssimple check to the code :
if (name [0] == '.') continue;
In fact, the programs were then written in assembler, but the essence of the check was exactly that.
It would be more correct to implement this check more extensively:
if (strcmp (name, ".") == 0 || strcmp (name, "..") == 0) continue;
- but what's the difference, the main thing is that everything worked.

This had two far-reaching consequences.

Firstly, a precedent was created for such “sloppy optimizations” in Unix, and a lot of other lazy programmers put bugs into their programs in a similar way: in particular, files starting with a point are often ignored where they should be processed.

Secondly, and this is much worse, “hidden files” starting with a period were perceived as a “feature”. A lot of lazy programmers began to create such files in the home directory of each user. Not many programs are installed on my machine, but there are about a hundred hidden files in my home directory, and about most of them I don’t even know why they are needed, or whether they are needed at all. Each search for files in my home directory slows down many times because of all this invisible garbage.

I am sure that “hidden files” appeared on Unix by mistake , as an unforeseen result of that “optimization” in ls.

How many bugs, how much wasted CPU cycles, how much human annoyance can only be explained by the fact that 40 years ago Unix authors saved half a line of code?

Remember this case every time you want to “cut a corner” in your own code.

(Many argue that files with a dot in the system are necessary. Yes, the files themselves are necessary, but the dot in their names is not. They would be much more convenient to store in $HOME/cfgor in $HOME/lib; and this is exactly what we did in Plan 9, in which “hidden files "No. We can learn from our mistakes.)

Also popular now: