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

[Question] Functional Programming Patterns #244

Open
fkromer opened this issue Sep 29, 2018 · 9 comments
Open

[Question] Functional Programming Patterns #244

fkromer opened this issue Sep 29, 2018 · 9 comments
Labels

Comments

@fkromer
Copy link
Contributor

fkromer commented Sep 29, 2018

Would you accept PRs about functional programming patterns @faif ? Would probably imply some project restructuring (e.g. putting dirs "behavioral" and "structural" into "oop").

@faif
Copy link
Owner

faif commented Sep 29, 2018

I'm a big fan of fp but although you can do it in Python, it is not always considered idiomatic. It's not a bad idea but I'm not sure if it's good to put it in this repo. I'd like to hear some thoughts from the rest of the community.

@fkromer
Copy link
Contributor Author

fkromer commented Sep 29, 2018

(...) although you can do it in Python, it is not always considered idiomatic.

As far as I know/learned until now some functional programming in Python is very pythonic. However these kind of patterns are more idioms than higher level patterns and not really suitable for the repo (due to low level).

@faif faif added the question label Oct 5, 2018
@gyermolenko
Copy link
Contributor

+1 for functional patterns here.

@fkromer had you something particular in mind?
We should probably make a list to briefly discuss it before actually implementing(or copying).

I'll start proposing "pipeline" candidate

@fkromer
Copy link
Contributor Author

fkromer commented Feb 7, 2019

I had the patterns addressed in S. Lott's "Functional Python Programming" in mind. In case you want to look into the book pay attention before doing so: There is a section about patterns and some references in the index but the majority of examples is spread over the whole book. It makes sense to depend on some Python package(s) which implement boilerplate required to implement the actual patterns. As @faif already said: I am not sure if it's a good idea to put this into here.

Recently I started a small project called 30 seconds of functional python programming. Right now it's a collection of Python package API examples running in an interactive Python environment on Binder. Python packages for functional programming have been hardly addresses in the books I've looked into so far. The packages provide lowest level building blocks to adapt a FP style beyond what you can do with Pythons builtin and standard lib stuff. I think it's way more effective to learn new programming language features via exploratory experimentation. I've not pushed everything I've prepared so far but I will do so that you get a better understanding of what the project is aiming for. E.g. I'd like to port the JavaScript examples from Functional Programming Jargon to Python as well. And it would be reasonable to put pattern examples/implementations into specific Python package specific sections as well. Feel free to contribute there as well.

@fkromer
Copy link
Contributor Author

fkromer commented Feb 10, 2019

I'll start proposing "pipeline" candidate

Another higher level candidate: Parallel Functional Pipeline Pattern

@mpkocher
Copy link

mpkocher commented Jul 4, 2020

Perhaps this repo would be a better place to centralize functional programming pattens and concepts in Python.

https://github.com/sfermigier/awesome-functional-python

@SakigamiYang
Copy link

In my opinion, Python is not a good language for FP (many use cases are not covered), although it has some of the ideas of FP.
So I think FP Pattern should not be included in this repository because this feature is not complete.

[From this page: https://intellipaat.com/community/12542/why-isnt-python-very-good-for-functional-programming]
Below is a list of some functional things which you will miss in Python:

  • Pattern matching
  • Tail recursion
  • Large library of list functions
  • Functional dictionary class
  • Automatic currying
  • A concise way to compose functions
  • Lazy lists
  • The meaning of no pattern matching and no tail recursion in Python is your basic algorithms have to be written imperatively.Recursion is ugly and slow in Python.
  • There is no syntax for currying or composition means that point-free style is about as full of punctuation as explicitly passing arguments.
  • Iterators instead of lazy lists mean that you have to know whether you want efficiency or persistence and to scatter calls to list around if you want persistence. (Iterators are use-once)

@ESE-Wahaj
Copy link

A project accepts PRs on functional programming patterns would depend on the project's goals and the maintainers' preferences. If the project's focus is on object-oriented programming, the maintainers may not be interested in adding functional programming patterns or restructuring the project in that way. However, if the maintainers are open to adding functional programming patterns, restructuring the project may make sense, and PRs related to functional programming could be considered. Ultimately, the best course of action would be to reach out to the maintainers and ask for their thoughts on the matter.

Repository owner deleted a comment from ESE-Wahaj Apr 9, 2023
@faif
Copy link
Owner

faif commented Apr 9, 2023

I believe that functional programming idioms in any language are good, as long as they are not implemented in an obscure way. Especially the fundamentals such as immutability and pure functions can be very beneficial to Python programmers. So if people are willing to showcase them here, maybe it's a good idea to include them.

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

No branches or pull requests

6 participants