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

Code should be split into functions/methods that are pure and ones that have side effects #193

Closed
BernhardPosselt opened this issue Jun 15, 2017 · 1 comment

Comments

@BernhardPosselt
Copy link
Member

BernhardPosselt commented Jun 15, 2017

For terminology: https://vimeo.com/160326750

The basic idea is:

  • pure functions are very easy and fast to unit test
  • functions with side effects need slower integration tests and are harder to setup

Classic use case for this is converting data (e.g. https://github.com/nextcloud/news/blob/master/lib/Service/FeedService.php#L317) which means: when converting data, split it out into a separate, one method class and inject them in the constructor (thats fine because functions suck in php)

Other usecases usually include calculating a result, validation or grouping structural things (e.g. Functors (e.g. map for lists), Monads (e.g. Promises, Optionals, Streams, etc)


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@stale
Copy link

stale bot commented Jul 31, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants