Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Meta

Comments on Decomposing compound questions

Post

Decomposing compound questions

+3
−1

The basis of the Unix philosophy is to decompose complex tasks into simple sub-tasks, so that one can easily choose a combination of simple Unix tools to solve the problem in an intuitive way.

Often I see newbies ask questions along the lines of "how do I X complicated and specific thing". The greybeards then oblige with an even more complicated and impenetrable one liner. The newbie is left with a renewed conviction that the Unix command line is magic, and only a wizened old shell-master, who has spent his life memorizing every man page, can hope to use its powers.

The Unix command line is not a magician's riddle. You're not supposed to "just know" exactly the right obscure incantation for every situation, and if you don't then it's your punishment to do things by hand. It's supposed to be a powerful, intuitive toolkit that works together with the natural problem solving and analysis abilities of your brain.

Whenever someone asks how to do X in the shell, it should be a valid and preferred answer to explain that:

  • X is actually a combination of tasks Y and Z
  • Link to questions about doing Y, and questions about doing Z
  • Explain how to combine them together (eg. with pipes)

The alternative is that for N types of problems, we will end up answering N + N*N + N*N*N + ... questions for every combination of them. That is silly, clogs up the site with tedious junk, and does a great pedagogical disservice to new Unix users. Instead we should simply have N questions explaining each simple task, and a handful more to explain how to compose them together.

As an example, imagine questions like:

  • How do I delete every file that meets X condition
  • How do run a conversion program on every file of type Y
  • How do I get the file counts of every file in these directories
  • Infinitely many variations

These all come down to the same thing:

  • How can I obtain a list of paths? (refer to find, fd, ls...)
  • How do I filter a list of paths based on criteria? (find arguments, shell if, many others)
  • How can I run a program on every file? (refer to pipes, xargs, Shell expansion, GNU parallel, Shell for...)
  • How can I do X task on Y file? (obvious, but refer to rm, etc)

The only real answer that needs to be given to such questions is to explain how to decompose the task into more obvious sub-tasks, how to pick appropriate Unix tools for those sub-tasks and how to combine them.

As a FOSS advocate, I find it frankly shameful and reprehensible that a community for helping Unix users would keep the wonderful concept of the Unix philosophy a secret from newbies, for the sole reason that the newbies did not think to explicitly ask about it without knowing its existence. Maybe on codidact we can do better?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Also relevant to programming (1 comment)
This does sound reasonable but how would we do that? Are you suggesting building a collection of cano... (2 comments)
This does sound reasonable but how would we do that? Are you suggesting building a collection of cano...
terdon‭ wrote over 1 year ago

This does sound reasonable but how would we do that? Are you suggesting building a collection of canonical reference posts that can be referred to in answers? Over at Unix & Linux SE, I would try (but not always succeed) to break down any one liners into their constituent parts, explaining each of them. That is quite labor intensive though and still doesn't necessarily remove the "OMG that's magic" feel. Do you have a better idea?

matthewsnyder‭ wrote over 1 year ago

break down any one liners into their constituent parts, explaining each of them

This is what I tend to do as well, and yes it is laborious. Instead I suggest that just breaking down the steps and linking to the question explaining each step should be considered a sufficient answer. And if the question explaining a basic step does not exist, you should create and self answer it first.

I don't think this is labor-intensive. For example, if you think of all the "how do I do X on a list of files" questions (eg. https://software.codidact.com/posts/288255), instead of explaining xargs over and over every time, we can just have one general question about xargs (eg. https://linux.codidact.com/posts/288310) that we can link to from answers (as I did in https://software.codidact.com/posts/288255/288257#answer-288257). That way we're actually saving work, and also teaching people the unix philosophy.