Skip to content
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

slices: misc improvements to godoc #30

Merged
merged 17 commits into from
Nov 14, 2023

Conversation

dwurf
Copy link
Contributor

@dwurf dwurf commented Nov 14, 2023

This is my attempt to improve the godoc for the slices package. I have been pretty heavy-handed in some places so I've tried to split the PR up into useful commits.

The general thrust of it is to try to improve spelling, grammar, consistency and readability. It started as just a fix to the spelling in SortBy, then I noticed an inconsistent use of arr, items and the given slice to refer to the (primary) slice for each function.

  • arr clearly does not match any of the argument names, and may mislead the user into thinking they are modifying the backing array.
  • the given slice only makes sense when there is one input slice, and is a bit more wordy than the other two options.
  • items is the correct parameter name and is unambiguous when there are multiple slices, but it reads strangely in some places.

I ended up settling for using items almost everywhere, although for me it was a bit of a coin toss which way was better.

Some other consistency changes:

  • always finish godoc with a period
  • code blocks in paragraphs do not get rendered as godoc e.g. see here, and this was inconsistently sprinkled into some function docs. I opted to remove this, although it might be clearer to lean into this even if it isn't rendered as it would help with clarity in some cases where the items grammar is ambiguous.
  • I have added or tweaked the grammar where I think it could be improved (in particular, use of the, a, in, of, ...). In most cases these are minor changes to help with readability.
  • Consistent use of f rather than F to describe function arguments.

For a couple of functions I've taken a stab at rewriting the godoc entirely to make it clearer. I think this helps a lot in cases like Reject where you had to go and look at the docs for Filter to get a complete picture of what the function was doing, and even more so for Scan where the docs were explaining only how it is different from Reduce, which is itself a difficult to explain operation.

In many cases the godoc for slices was referencing "arr", but all functions use "items" as the slice name.
"arr" is also misleading since users could assume this refers to the backing array.
- Add full stops to sentences.
- Remove the occasional inconsistent use of `code formatting`, which is not typically rendered in godoc.
- Add particles to sentences where appropriate to improve readability.
- Add full stops to sentences.
- Add particles to sentences where appropriate to improve readability.
- Always describe the primary slice as `items` to match the argument names.
- Reword some godoc to improve grammar or clarify behaviour.
I haven't convinced myself that these are actually cartesian product implementations,
but my math brain hasn't been used in a while so I have focused on the godoc.
Zip can be a little confusing without an example, so I have tried to add a concise explanation and
example to the godoc.
The `ExampleZip()` contains excellent examples so perhaps the docs should refer people to that instead?
@dwurf dwurf changed the title Godoc pass on slices package slices: misc improvements to godoc Nov 14, 2023
@orsinium
Copy link
Member

Thank you!

@orsinium orsinium merged commit a795688 into life4:master Nov 14, 2023
6 of 7 checks passed
@dwurf dwurf deleted the spelling-grammar-pass branch November 16, 2023 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants