Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

genuine question - can this be done in python in a production ready manner ?

I'm have been trying to answer this question for quite some time. In Haskell, writing monads or applying category theory is part of the idiomatic language. Not so in js or python.

for example, if you want to apply haskell like concepts in javascript, the closest thing I know is purescript (http://www.purescript.org/) or Bucklescript. So you need to switch over to a different language to achieve the richness of these concepts.

I'm hardpressed to apply these concepts idiomatically to the mainstream languages. Compare this to design patterns or OO, or reactive programming (via rxjs or whatever) - which are so accessible that they are now the reason to learn a particular language!



> genuine question - can this be done in python in a production ready manner ?

It can, but without a type system you lose most of the benefits. You can put monads in there but if you refactor fearlessly the way you would in Haskell (without tests), you'll get production bugs.

> Compare this to design patterns or OO, or reactive programming (via rxjs or whatever) - which are so accessible that they are now the reason to learn a particular language!

Isn't that the same thing? Monads etc. are the reason to learn Haskell.


Wrt your question about production-ready manner: I don't know.

However, there are many libraries which make functional programming in Python seem viable. See eg: https://pypi.python.org/pypi/PyMonad/


Functional programming is just imperative programming with heavy heavy restrictions. So yes this can be done, as long as you fully understand what functional programming really is...

A functional program is simply a program that is made up of a single mathematical expression. Complexity is achieved in functional programming by composing smaller expressions into a single big expression. It should be possible to write your entire functional program as a single expression or statement (not saying you should do it, but it should be possible). That's it. That means all your python functions should be a single expression only (use lambda always instead of def; or if you must use def make sure all your variables remain immuted)

If you want to apply like category theory to it, then just make sure your python functions always stick to specific types. Don't let a function take in either a string or an int and return a list or a iterator or any bullshit like that. Keep the typing consistent... If you define all your functions to behave mathematically like only taking in a string and only returning an int, not an int or a None... then you are following category theory.

So nothing like this:

  def someFunc(value):
     if value == "hello"
        return 1
     elif value == 123:
        return [1,"world"]
or this:

  blah = lambda a: "hello" if a is None else 304
If you wanted automated type checking at run time you can use a decorator to check the types of variables going into the function and coming out.

If you try this style at work, people will complain haha, I don't recommend it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: