9 ms·
Best Practices for Using Functional Programming in Python
- jo-wol 8y agoNo thanks https://news.ycombinator.com/item?id=14902630 https://news.ycombinator.com/item?id=14902630
- bryanrasmussen 8y agois it no thanks I don't want to go to kite.com because they spy or no thanks I don't want programming suggestions from people who spy?
- agumonkey 8y agoHere, just use an archive https://archive.fo/ixt4n https://archive.fo/ixt4n .. damn.
- hasperdi 8y agoIs this not the company that put on spyware in a package for Sublime text?
- tempodox 8y ago> Kite is a plugin for your code editor that uses machine learning to provide you with code completions in real time sorted by relevance. The whole article seems to be nothing but a transport vehicle for that ad. Spyware for even more editors.
- xte 8y agoWell... In my case it keep saying Huh... that's weird Something unexpected occurred. We'll investigate what happened Refresh the page Anyway, Python actually support limited functional programming so I only get it for that topic :-)
- h8hawk 8y agoBeside python has pretty awful support for functional programming, I don't get what is purpose of this. Is it just a Facebook for developers? Why anyone should use autocomplete sever in others computer? What is advantage of this over other autocomplete API's such Jedi, Pycharm, Microsoft python server, that doesn't run in other computer? I hope these sort of thing's won't become popular.
- optimuspaul 8y ago> Beside python has pretty awful support for functional programming That seems counter to my experience and understanding of things. Python has adequate support for functional programming. And bonus you can mix in some object oriented things as well.
- sevensor 8y agoWhat Python has, is really good support for procedural programming. You can write pure functions when it makes sense, and you can write side-effecting procedures wherever you want. You have a bag full of useful data structures, and an extensive standard library to hand. Python's biggest drawback for me is that it's what I'd call a "surprisingly typed" language. Values in Python are strongly typed, but we pretend they're not. Until, surprise! AttributeError! That thing isn't what you thought it was. Optional typing has started to help with that.
- pmoriarty 8y ago"Values in Python are strongly typed, but we pretend they're not. Until, surprise! AttributeError! That thing isn't what you thought it was." Strongly typed? Maybe you mean statically typed? From "What To Know Before Debating Type Systems"[1]: "Probably the most common way type systems are classified is "strong" or "weak." This is unfortunate, since these words have nearly no meaning at all..." [1] - http://blog.steveklabnik.com/posts/2010-07-17-what-to-know-before-debating-type-systems http://blog.steveklabnik.com/posts/2010-07-17-what-to-know-b...
- 8y ago
- sireat 8y agoHow is Kite still in business after telemetry abuse? Sadly I would not be shocked if they managed to gather additional funding.
- depressedpanda 8y agotl;dr - Use pure functions - Avoid mutability - Limit use of classes - Strive for idempotency - Use lambdas and higher order functions sparingly, only when they actually simplify the code - Use generators where applicable All in all, it's good advice which shouldn't be ignored just because she works at kite. She should probably go back and proof read the article and fix the code and terminology errors, though.
- JustSomeNobody 8y agoHere's another article on FP in Python for those who'd rather an alternate than go to kite.com. https://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming https://maryrosecook.com/blog/post/a-practical-introduction-... Edit: After scanning the kite.com article for a second time, I see the author actually links to Mary Rose Cook's article.
- macintux 8y agoAdding FP features to an otherwise-mutable language has always seemed a mixed bag to me. Obviously it’s nice to have those features, but you don’t get the immutability constraint that makes development so much more predictable.
- jolmg 8y agoExactly this. In Haskell, I can look at a function signature or definition and be guaranteed a lot of what that function is or is not able to do without needing to look at the code it's calling. That's never going to be the case with Python. I can only, at most, trust the conventions the writer seems to be following.
- sevensor 8y agoPython offers immutable data structures in addition to the mutable ones. Tuples are immutable, we've had namedtuple for a while, and now it's possible to write immutable data classes as well. As time goes by, I find myself using less and less mutability in Python. At this point I default to immutable structures, and I bring in mutable ones only if I need them for performance or there's no reasonable immutable alternative.
- macintux 8y agoTangentially, I was extremely annoyed to discover that tuple unpacking in function headers was removed with Python 3. Coming from Erlang, tuples were quite appealing, but that was frustrating.
- ssfak 8y agoIndeed, "Mostly functional" programming does not work: https://queue.acm.org/detail.cfm?id=2611829 https://queue.acm.org/detail.cfm?id=2611829
- nikofeyn 8y agoi understand who the author of that article is, but i feel that's an overly hardline approach. f# and racket are perfectly fine and productive mostly functional languages.
- wybiral 8y agoPython doesn't even have tail call recursion optimization (you'll hit a RecursionError exception if you go too deep). Using first-class functions is great but I hesitate to call any serious use of Python "functional programming".
- bunderbunder 8y agoMany Common Lisp implementations also lack TCO. That said, I do agree that you probably shouldn't go crazy with FP in Python. At its core, it's a procedural language. It has some useful things from OO and FP, but you'll be more comfortable if you keep procedural techniques in the top tray of your toolbox. Which isn't all that bad a thing. IMO, well-done modern procedural programming looks a lot like functional programming with more loops and less recursion.
- wybiral 8y agoCommon Lisp is one of the least "functional" of the major lisp dialects too. Without TCO you generally need state for iteration. That being said, I agree, there's nothing wrong with taking aspects that you like (first-class functions mainly) without having to be a purist. In fact, imo purely functional languages are tedious compared to procedural languages like Python.
- bunderbunder 8y agoThat said, the ML/Haskell-like functional languages do have one thing that most procedural languages do not, which is that they help you keep side effects under control. I'd like to find a procedural language that allows for side effects (it is still procedural programming, after all), but encourages keeping them under control. I've been toying with Nim lately, and it's been a good experience. I think that it's possible to do even better, but it's already way ahead of anything else I've tried.
- karanlyons 8y agoYou can hack that in with a decorator if you’d like, at some cost to performance.
- xte 8y agoWell... If I'm looking for functional programming in python... I'll choose hy (hylang) witch is actually Cython with a lisp-y syntax. Otherwise if I'm accustomed to Python but feel the need of something functional and scheme/lisp are too hard well... I go for Nim... Python is FANTASTIC as a simple language to tech programming these days and to glue stuff together, with the benefit of a respectful standard library but frankly if we go beyond we have other options perhaps with some sharp corners (less easy to code, less complete standard library, less documented etc).