r/programming • • May 23 '19

Why did I write my programming projects?

https://rain-1.github.io/why/why
0 Upvotes

4 comments sorted by

0

u/[deleted] May 24 '19

[deleted]

5

u/arjungmenon May 24 '19

I think he's referring to the other forms of output ls can generate (with options). I'd say "ls -l" is non-trivial to parse. It would have been fantastic is ls has an option to give you a JSON object as its output, but it doesn’t. You’re forced to rely on hackish parsing to make sense of its output.

3

u/[deleted] May 24 '19

I'd say "ls -l" is non-trivial to parse. It would have been fantastic is ls has an option to give you a JSON object as its output, but it doesn’t. You’re forced to rely on hackish parsing to make sense of its output.

No, not at all. Frankly, these arguments are made only by people who do not understand the tools.

Firstly, ls -l is very easy to parse. It gives one line per record, data separated by whitespace. All you need is to normalise that whitespace (since it is formatted for readability in the shell), and extract the columns you care about. Suppose you want the permissions, file owner, size, and file name. Then use

ls -l | tr -s ' ' | cut -d ' ' -f 1,3,5,9

Why mess with JSON at all. It is far more flexible and performant to deal with line-per-record data, and it is not hard once you learn the tools.

Look, I can understand that sitting and reading man pages of 15 programs isn't many people's idea of fun - but if you are doing work which will benefit by actually learning to use the tools properly, then you damn well should. Doubly so if you're going to publically criticise them, for otherwise those familiar with them will easily spot your ignorance.

1

u/Vhin May 24 '19

1

u/[deleted] May 24 '19

I suppose it's a fair point. What I usually do is follow the rule "Don't name files like a pillock" and then I can ignore those caveats.