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

An aside on function composition #71

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

sneakers-the-rat
Copy link
Contributor

Continuing: #58

Just a quick aside with some links to some wikipedia pages for further reading. I think this is good to introduce here for reasons that are along the same lines as what i was saying re: "try/except? that's great! so now i'm going to wrap everything in try/except and now no more errors!" - we don't want the students to overgeneralize and pack everything into big functions :)

@@ -189,6 +189,16 @@ def mean_mm_to_in(data_mm, axis_value):

Note that the function could be written to convert the values first and then calculate the mean. However, given that the function will complete both tasks and return the mean values in the desired units, it is more efficient to calculate the mean values first and then convert just those values, rather than converting all of the values in the input array.

````{tip}
Typically functions should have a [single purpose](https://en.wikipedia.org/wiki/Separation_of_concerns), and be [composed](https://en.wikipedia.org/wiki/Function_composition_(computer_science)) to implement higher-order operations. The above function would normally be written without wrapping {func}`numpy.mean` like this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH YES!! functions should do one thing well. i love this!

@lwasser
Copy link
Member

lwasser commented Oct 24, 2024

thank you!! i'll try my best to slow down a bit as well!!

@lwasser lwasser merged commit f8ef05a into pyOpenSci:main Oct 24, 2024
4 checks passed
@sneakers-the-rat
Copy link
Contributor Author

I would never tell you to slow down!

@lwasser
Copy link
Member

lwasser commented Oct 24, 2024

@sneakers-the-rat you are the best. I appreciate you so much!

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.

2 participants