-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Gentler introduction to recursion #1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Explain the concept in simple words when first introduced - Remind learners of the in-context meaning throughout
🆗 Pre-flight checks passed 😃This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits. It should be safe to Approve and Run the workflows that need maintainer approval. |
Co-authored-by: Benson Muite <bkmgit@users.noreply.github.com>
| The `-R` option to the `ls` command will list all nested subdirectories within a directory. | ||
| `R` in `-R` stands for "Recursive" which refers to the idea that the output of a process | ||
| becomes the input of another iteration of that same process. | ||
| So in this case, `ls -R` lists the contents of a directory, and for every directory | ||
| it finds, it lists the contents of that directory, | ||
| and for every directory inside those subdirectories, | ||
| it lists the contents, and so on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Recursion" should be in the glossary? This might allow simplifying the paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it should be added. I'll add that to this PR. I still think a short inline explanation would be helpful. The instructor will need to verbally explain -R/-r somehow so I think coming up with some nice concise and approachable wording will be helpful.
| : A recursive precudure is one where one step of the procedure is to apply the procedure itself | ||
| (usually to a different input). | ||
| In the context of shell, it often refers to applying a command to a directory and to all directories | ||
| contained within that directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| : A recursive precudure is one where one step of the procedure is to apply the procedure itself | |
| (usually to a different input). | |
| In the context of shell, it often refers to applying a command to a directory and to all directories | |
| contained within that directory. | |
| : A recursive procedure is one where the output of an iteration | |
| is the input of another iteration of that procedure. |
Is context of the shell lesson helpful? Maybe should be added to
other terms if it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this because for all except ls, the command itself is not recursive. Really the only "recursive" part is finding files that we apply the command to. e.g. in grep, we are not applying some kind of recursive algo to search ie feeding the output of the search back into the search algo multiple times (not sure what that would even mean, maybe something akin to a recursive regex 😬 ). We are recursively crawling the filesystem to identify files to search, and then searching them (once each).
For this reason, I think the main thing learners need to know is that -r/-R means "apply this to the entire directory tree within the specified directory". They don't need to fully understand recursion as a general concept. In fact, imo, trying to dig into that would be distracting/confusing. I think it's enough to cover that recursion is a more general concept that has something to do with applying a process in a tree-like manner and in this context when applied to a directory means applying to everything inside as well.
This "apply to everything inside" is probably novices default way of thinking of commands and the fact that it's not the default for shell commands and -r/-R needs to be added is something to actively learn. Meaning, when you copy a folder in a GUI, typically the contents are also copied. When you search a folder in a GUI, typically that means searching all the contents and subfolder contents etc.
| The `-R` option to the `ls` command will list all nested subdirectories within a directory. | ||
| `R` in `-R` stands for "Recursive" which refers to the idea that the output of a process | ||
| becomes the input of another iteration of that same process. | ||
| So in this case, `ls -R` lists the contents of a directory, and for every directory | ||
| it finds, it lists the contents of that directory, | ||
| and for every directory inside those subdirectories, | ||
| it lists the contents, and so on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps if
The `-R` option to the `ls` command will list all nested subdirectories within a directory.
is changed to
The `-R` or `--recursive` option to the `ls` command will make `ls` a [recursive] procedure
which lists all nested sub-directories within a directory.
to ensure recursive links to the glossary add
just before the Keypoints section, see #1510
Then the above can be shortened to
| The `-R` option to the `ls` command will list all nested subdirectories within a directory. | |
| `R` in `-R` stands for "Recursive" which refers to the idea that the output of a process | |
| becomes the input of another iteration of that same process. | |
| So in this case, `ls -R` lists the contents of a directory, and for every directory | |
| it finds, it lists the contents of that directory, | |
| and for every directory inside those subdirectories, | |
| it lists the contents, and so on. | |
| The command `ls -R` lists the contents of a directory, and for every directory | |
| it finds, it lists the contents of that directory, | |
| and for every directory inside those subdirectories, | |
| it lists the contents, and so on. |
Co-authored-by: Benson Muite <bkmgit@users.noreply.github.com>
Co-authored-by: Benson Muite <bkmgit@users.noreply.github.com>
This is an unsolicited PR so feel free to close without merging you don't think this needs fixing. Goal is to actually explain what learners need to know about recursion rather than linking out to wikipedia.
Changes:
This is unfortunately a net add of content. I think it is possible to make the explanation(s) more concise, but likely will still be a net add since it adds an explanation that wasn't there before. I think overall it makes the lesson more clear to a learner who is not already familiar with the concept of recursion.