3 ms·
This is one of the places that "do one thing" principle breaks down. Or a bad habit became a bad definition for the use case of a command and it stuck for newbi
by okanat 3y ago
This is one of the places that "do one thing" principle breaks down. Or a bad habit became a bad definition for the use case of a command and it stuck for newbies.
`cat` usually does one thing: concatenate the contents of the inputs you give in the order you give them. Of course, if the user gives only one input, it will only print that.
It is not a text viewer even though many *nix users use it that way because they learned it that way, because a series of tutorials taught the wrong thing to generations. The very first one probably came from a very limited and very bad Unix environment like a server that is hostile to active development. So the tutorial used whatever core utility that's available: cat, beginning the multi-generational bad habit.
- probably_wrong 3y agoI would like to counter-argue that it's the author's fault for doing things the wrong way. While I'm sure the actual code looked different, the "spirit" of the code builds a CSV file by concatenating strings and specifying raw ASCII codes. Building a CSV file like this on 2023 is guaranteed to cause bugs down the line. Had the code used the Python CSV primitives, or at least had the author let Python convert the "\n" character to the OS-dependent representation, the bug would have been avoided entirely. The author just happened to run into it with `cat` instead of, say, a CSV parser confused about the unusual choice.
- kevin_thibedeau 3y agoIt's ColdFusion, not Python. A language that forces you to program like it's the 60s because character escapes are too advanced a concept to implement.
- kevincox 3y agoThe author says it was a simplified example. They may will have implement a fully features CSV emitter but got the liver separator wrong. Either way whether or not their CSV was valid is irrelevant to the story. The point is that some characters in a file may obscure the contents of that file in surprising ways.
- Qwertious 3y agoThe "do one thing" is failed by text itself - text encodes backspacing and such. It even has a bell character. This has no reason to be built into our text format. Saying "cat is not a text viewer" is absurd, though - the history of Unix is that the "print" command was removed when the Unix devs realized that cat did the same thing already, and so told their users to just use cat with a single argument. I'm not saying it was good design, but it was intended design.
- fsckboy 3y ago> It even has a bell character. This has no reason to be built into our text format. it's not built into our text format (our being us,-unix-before-unicode). It's built into the terminal. The file format is 8-bit clean as it should be, any other values are going to have to be out-of-band. The unix stream format follows the file format, with the exception of the terminal format (and the comms format) is 7-bit ascii with varying amounts of ANSI control, but that's on you, you bought the terminal...
- SuchAnonMuchWow 3y agoI'm not sure what you mean: ASCII text encoding is full of controls characters, most of them being only historical and not used by anything, including terminals.
- fsckboy 3y agoASCII, an ANSI code, includes the concept "information interchange" in the name, i.e. it is also a communication protocol, and also a terminal device control, inasmuch as it is also a character set. That's why OP was making a mistake claiming that "BEL" doesn't belong in there. ANSI's escape sequences came later to control more functions for glass teletypes.
- hnlmorg 3y agoASCII characters roughly below 20 are largely control character. Backspace is a control character. Carriage return is technically a control character. There are CSV like form field characters. Escape is another non-printable ASCII character. ANSI escape sequences do also include control codes but there’s plenty in ASCII too. Frankly, you only need to spend 30 seconds looking at an ASCII table to see this. Source: I’m an author of an alt $SHELL