re: Django to Phoenix - Part 0: Background VIEW POST

FULL DISCUSSION
 

"combination sounds kind of great" ?? Can you explain more why you moving your python web app to functional programming? I also hearing more about functional programming. And how phoenix will help and Python-Django not.

 

Hey, thanks for asking. I'm not an expert in this stuff but I'll try to explain a few relevant points.

  • The project doesn't really require changes from Django. Python & Django are perfectly good so this isn't motivated by any hard requirements.
  • It is a side project so I can use it to explore new technology and learn new languages. This isn't a high pressure production environment where there are real consequences to my choice.
  • I would like to change to functional programming as I have been writing a lot of Elm code at work and really enjoy the functional approach. I find it to be clearer to understand and easier to maintain. This is mostly due to pure functions and immutable data structures. These make the code easier to reason about and remove some potential bugs. Elm also benefits from a fantastic type system which also catches lots of errors.
  • Python is not great for functional programming. It doesn't have built in support for immutable data structures and it limits anonymous/lambda functions to single expressions so they are not very powerful. It is a great programming language but functional programming is not a core goal for it so they have made different choices.
  • Django has quite an object oriented approach to programming. Particularly in the view layer. They have function views but it feels like a lot of their attention is on the class based views. I written quite a few of those now and I struggle to look at the class hierarchies that result and understand everything that is going on.
  • I have attempted to write my own functional pipeline-based views framework for Django and it is promising in some small ways but I always end up unhappy with what Python will let me do.
  • I think it is quite logical to think of a webserver as a function program. It is almost one big function that takes a request and returns a response. Object-oriented programming makes a huge amount sense in some situations like simulations & games but in my mind it doesn't apply so well to web servers. In this respect the Phoenix approach of modelling a pipeline of functions to handle a request feels like a very natural fit.
  • Even if there are parts of the system that are well modelled by stateful 'objects', Elixir & Erlang provide mechanisms for achieving that in a functional manner.
  • There are also reasons to be very excited about the Elixir ecosystem. Mostly that it is built on the Erlang Virtual Machine which is specifically designed to tackle some interesting and relevant problems like being distributed and reliable (fault tolerant.) I have been watching talks and reading articles about Erlang & Elixir for a while and I am keen to gain experience in the ecosystem. The Zen of Erlang is a particularly interesting description of it. There are also some talks from Greg Young where he describes working in the Erlang ecosystem and some of the benefits.
  • I'm also excited by the fact that Phoenix works with Cowboy which is the standard Erlang webserver and can handle HTTP requests & websockets from the same stack. I'm currently running Django with Gunicorn which is fine but feels like less of an integrated solution and then websocket support also feels like a second class citizen. Though I completely acknowledge that I have not used websockets in Django yet.

I hope some of that shows my state of mind and understanding of the situation. As I said, Django is still a great choice for my project but for reasons of personal interest and growth I'd like to try something else and Elixir seems like an exciting alternative.

 

This is neat !! Got a lot on the functional side. It's amazing to read the comment. Thankx for responding is such positive way. Looking forward to read more from you.

code of conduct - report abuse