Skip to content

feat: update code style guide to allow reduce#2225

Open
jkuester wants to merge 1 commit into
medic:mainfrom
jkuester:free_reduce
Open

feat: update code style guide to allow reduce#2225
jkuester wants to merge 1 commit into
medic:mainfrom
jkuester:free_reduce

Conversation

@jkuester

@jkuester jkuester commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Our code style guide has long contained instructions discouraging the use of the Array.reduce function. The context provided in the docs for why reduce should not be used is that

Most uses of reduce have more readable alternatives.

With the nod from @dianabarsan, I would like to remove this prohibition for these reasons:

  1. It is standard JS code and for new contributors to the CHT code-base it is surprising that this function (and pretty much only this function) should not be used in our code-base.
  2. Use of the Array.map/filter functions in our code-base are ubiquitous. From the perspective of readability and code-flow, reduce fits well along side these other functions (as intended). Its syntax/behavior is not difficult to understand (especially when used with these other Array functions).
  3. In many cases in our code-base where reduce could 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 reduce for everything. But I think the same general rule for all our code should apply. Prioritize readability! If using reduce improves 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.

@jkuester jkuester requested a review from dianabarsan July 7, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant