r/functionalprogramming • u/Lubbadubdub • Sep 06 '17
Python Using Python... Struggling with inconsistency...
I'm mainly working with Python at the moment. Most people in my company are using oop, which is kinda "natural" given the choice of the language. In general, I don't like oop. I prefer simple solutions to complex ones when they can solve the same thing and oop adds one layer of abstraction to functions. I value consistency and explicity. I hate it that in Python sometimes you call by reference and sometimes by value and there's no apparent model behind it. Most people are using oop coz they dont care as much about which paradigm to use and it's always easier to argue for oop since "everything is an object anyway" (which is not entirely true and how is that a valid argument..). Is there a way to be more "functional" with Python? Are there good argument against using oop? Or maybe I should just give up and go with the flow...
View all comments
Show parent comment
3
u/ws-ilazki Sep 07 '17 edited Sep 07 '17
Well, there's a little bit of hope here, since you've given some extra info. Since you're doing Tensorflow your work's probably practically married to Python; I know there are other options, but it seems like everything ultimately goes back to TF+Python in the end. Anyhow, maybe look into using Hy, which is a vaguely Clojure-inspired lisp that runs on top of Python the same way Clojure sort of piggybacks onto the JVM or JavaScript. No link right now since I'm on mobile, but if there's no friction against you doing
pip install hy, you can still stay somewhat in the familiar Python ecosystem, but with some extra FP niceties that might make things more comfortable for you.I didn't suggest it initially because it's sort of getting into niche languages, but your environment might be one that's amenable to it if you can get it treated as basically another Python depedency. It's not something you could integrate into an existing codebase easily, but if you have to do some new project, it might hit that sweet spot of "close enough to Python" without looking like Python, so that there's less expectation that the code read the same way (OOP), but still some familiarity in libraries and function calls etc. that others won't feel completely lost.
Of course, that won't help you with some underlying issues, like with libraries such as numpy, but it could at least make some of it more comfortble, since it gives you niceties like macros, plus wrappers for operators like
+, that make a lot of FP stuff more concise than trying to do the same in real Python.Edit: Oh, and there's also another language, called Coconut, that's basically a superset of Python that compiles into Python like Hy does. Valid Python is valid Coconut, but it also adds a bunch of FP stuff on top. I believe it has some ML inspiration to it, rather than Hy's lisp roots. Might also be worth looking at.