feat: update code style guide to allow reduce#2225
Open
jkuester wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Our code style guide has long contained instructions discouraging the use of the
Array.reducefunction. The context provided in the docs for whyreduceshould not be used is thatWith the nod from @dianabarsan, I would like to remove this prohibition for these reasons:
Array.map/filterfunctions in our code-base are ubiquitous. From the perspective of readability and code-flow,reducefits well along side these other functions (as intended). Its syntax/behavior is not difficult to understand (especially when used with these other Array functions).reducecould be used (e.g. populating a dictionary from an Array), we instead initialize the target container in one statement and then use a for-loop to populate it. This kind of state-ful imperative approach is unnecessarily verbose for many simple cases.This is not about switching to using
reducefor everything. But I think the same general rule for all our code should apply. Prioritize readability! If usingreduceimproves readability, then use it, otherwise do not use it. 👍License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.