Live data from Hacker News

Elixir for Humans Who Know Python

hibox.live

91–100 of 198 posts

Re: Elixir for Humans Who Know Python

#91
post #80
post #77

I love functional programming because it feels natural to me to have functions that always return a value (method chaining or postfix notation FTW!) do not mutate data (and therefore avoid side effects), and use clear naming conventions for any potentially destructive functions. However, Python's popularity, vast library, and strong community make it a more practical choice for solving problems - at least when progra…

As a Python programmer, I truly believe Elixir/Phoenix is the best stack out there from a technical perspective. However the incredible breadth of libs and resources ... and most importantly the mind share (both available devs, but more importantly available jobs for seniors who commit to Elixir) means that it is still just not a competitive choice. Almost all commercial software dev is not about technical excellence…

I guess it really depends on your definition of "make it". :)

Elixir today is used by startups, unicorns, fortune 500, and at least two of the FAANG (for whatever it is worth). It is used for web apps, embedded, distributed systems, data processing, and making inroads on AI and machine learning. It has a vibrant community with events around the world, several dozens books, and more.

It is on the [top quadrant of Redmonk][0] and [top 25 on most GitHub language stats][1] while being the second youngest language there (only older than Swift which was created by Apple).

Considering it is a language standing on the shoulder of giants but started by a 30-person company, I would say we definitely made it (I am obviously biased!). Of course there is _a lot_ to improve, realistically speaking it is unlikely we will cross top 10 (maybe that's your definition of "make it") but I also want to be clear that we will be here for quite a while!

  0: https://redmonk.com/sogrady/2022/10/20/language-rankings-6-22/
  1: https://madnight.github.io/githut/#/pull_requests/2022/4

Re: Elixir for Humans Who Know Python

#92
post #6

What is the productivity advantage of Elixir/Phoenix over other frameworks when using it for implementing more mundane SaaS (some dashboards, some CRUD,...) rather than the game lobby feature mentioned in the post? I am a developer with significant non-web development experience (Although I know pure JS and Erlang quite well), who is interested in learning some full-stack development to implement a SaaS on the side a…

For me it's not just the framework (although that is nice) but really the VM that it runs under (BEAM/OTP). Running an app on the BEAM means removing the need for external servers like redis/memcache for cacheing and whatever queue management system you pick. For a SaaS app this means instead of trying to orchestrate a bunch of services via some complex system (k8s, etc) you run everything under one VM that both scal…

> If I were you I'd wait for 1.7 to fully release and then try it out for a couple of hours and generate some simple app to get a feel for it.

Good news: Phoenix 1.7 final was released yesterday! https://phoenixframework.org/blog/phoenix-1.7-final-released (HN: https://news.ycombinator.com/item?id=34929159)

Although, if I were an absolute beginner, I might still consider waiting a little bit for the various resources to be updated to 1.7. That seems to be happening fast, at least. Or just go for the excellent Phoenix guides, which are already updated: https://hexdocs.pm/phoenix/overview.html

Re: Elixir for Humans Who Know Python

#93
post #77

I love functional programming because it feels natural to me to have functions that always return a value (method chaining or postfix notation FTW!) do not mutate data (and therefore avoid side effects), and use clear naming conventions for any potentially destructive functions. However, Python's popularity, vast library, and strong community make it a more practical choice for solving problems - at least when progra…

I don't think it's nonsensical to use less popular/exotic languages. I prefer to write code in languages that I like to write in, as long as it's a good enough tool for the job.

The real problem with them is that while you and I might be interested in functional languages, our coworkers/managers aren't and we have to stick with the languages we might not find as immediately exciting, like python.

Side node, python has Hy (https://hylang.org), which is essentially a lisp implementation that compiles to Python's AST. The entire python ecosystem and stdlib is available to Hy, so it's as batteries included as python is. It's a blast to use, but similarly I wouldn't expect my job to be excited about it.

Re: Elixir for Humans Who Know Python

#94

LiveView can’t handle spotty connections, I thought? Career python expert, not huge into Django/we dev in general… I thought the whole thing with most HTML over the wire is that its tied to the connection latency? Unless there’s some js component underlying the Elixir code that I don’t know or don’t understand. With the advent of things like flask+html, I find it a little hard to believe that Elixir hackers could whi…

> LiveView can’t handle spotty connections, I thought? LiveView handles it just fine. If the websocket disconnects for some reason it will automatically re-establish itself when the connection is restored. You can also use the built-in JS module to do client-side things when you don't need backend support. I use Alpine.js (PETAL stack) and I like it a lot. If you have a very complex client-side need, it's also pretty…

>> LiveView handles it just fine. If the websocket disconnects for some reason it will automatically re-establish itself when the connection is restored.

What the parent means is that, because state is kept on the server with LiveView, and events that change that state are processed by the server, if your connection is lost, then you may find that even basic things, such as having a dialog open when you click a button, stop working. This means that unstable connections result in very poor UX.

This is in direct contrast to a typical SPA for example, where the browser keeps and handles most front-end state, and talks to the server only when it needs to (e.g. form submission).

Re: Elixir for Humans Who Know Python

#95

Earlier quoted context omitted.

Is your comment based on experience with Elixir? How long did you work with Elixir professionally? I guess you have some fundamental experience with Elixir, as you would not post some comment here if not?

Yes, that's the point. Seriously i will not choose JS today if i have.a very specific requirements for choosing Elixir or Python (or any other stacks here). In reality, people choose the stack they're get used to. But it's their limited ability to see JS strength to solve their issue in first place. It's not informed choice.

At the very end of the day, I think some people just don't like JavaScript.

At the risk of speaking for people other than myself, a lot of people don't want to write code in JS and if they don't have to, they won't. Frameworks/tools like Phoenix and HTMX or the fact that many languages can compile to javascript/wasm mirrors this opinion

Re: Elixir for Humans Who Know Python

#96
post #87

Earlier quoted context omitted.

If you don’t mind, I have some questions as I would like to learn more. Are you aware of a large models.py for reference and learning purposes? Is it expected to define the schema of all my models in a single place but none of the logic? Also, don’t you run into scenarios in Django where the automatic migration is not enough and you need to provide custom commands? In such cases, how do you provide them? And can you…

I don't think this is something that will come down to technical merits. Unfortunately it is a popularity contest, where entrenched network effects are working against Elixir. As a Python programmer, I truly believe Elixir/Phoenix is the best stack out there from a technical perspective. However the incredible breadth of libs and resources ... and most importantly the mind share (both available devs, but more importa…

That does seem like the same arguments that are made prior to just about anything becoming mainstream though. I'm not saying it means nothing that python has so much mindshare, but the same could have been said to pythons predecessors as well. You're right about commercialization not being about technical excellence, in the short term. In the medium and long term, it's the advantages of recent technical excellence that drives a lot of commercialization.

Re: Elixir for Humans Who Know Python

#97

No offense to TFA author, but I don't think this is doing to sell Elixir to Python people. In fact, I have serious doubts as to whether most Python lovers would be willing to set aside their beliefs and practices to learn the Elixir way. Perhaps Phoenix and LiveView will be the gateway drug, but even to reach that point requires a lot of effort to understand functional programming and Elixir. Python has some function…

> Python has some functional capabilities, but in my experiences with Python devs, those are little used and even shunned.

I like to use things like filter, map, reduce or list comprehensions, but I see very few of those in my coworkers' code bases.

When Python introduced pattern matching, it was rather a pattern-aware switch/case, which does not return a value, as such a construct in a functional programming would do.

> I went from Ruby to Elixir, and even with my basic Clojure experience, it was an effort.

I tried out Elixir twice so far, and since the last time, I worked through 300 pages of SICP. I still have to twist my mind when I'd like to process nested maps or the like in Elixir now.

> It was worth it, but I think the apparently similarity of Elixir to Ruby is actually a negative.

However, Ruby provides a lot of higher-order functions, such as group_by and the like. If you're used to functional-style Ruby code, the transition is easier.

Re: Elixir for Humans Who Know Python

#98
Interesting article. Having the built in Redis via ETS is slick.

I currently use Python but don't use Django but instead wrote my own WSGI frameworks based on Flask Restx. I'm not a big believer of ORMs besides their CRUD functionality so there is not much benefit for me using Django and the security burden it carries (like PHP) by being so popular. I can keep my designs light weight, very secure and fast; albeit not nearly as fast as Phoenix.

Note however, I don't build public facing high performance applications so its not critical to have max IO like that which Phoenix can handle.

In a way, I wished I had moved to Elixir but with the technical debt invested in Python its a very big jump. Maybe someday down the road...

Re: Elixir for Humans Who Know Python

#99

Earlier quoted context omitted.

Yep, you do check the migrations into version control. >For example, if you have a large model with 50 fields, defining a subset with 10 fields can be beneficial to performance in several queries. Other than that, I agree with you. Nope, the django ORM has several helpers here. What you do in the most basic case is do something like MyTable.objects.filter(key__gte=12).only("field1","field2","field3") Which will (duri…

Ack on migrations, tks! --- For completeness, you can do the same in Ecto: from t in MyTable, where: t.key >= 12, select: ["field1", "field2", "field3"] However, that will still allocate a "MyTable" struct in Ecto. And if that struct is large (say 50 fields), slots for it are allocated (but none of the actual data on the fields). I am not familiar with Python Object Model enough but, if your Python example still allo…

>I am not familiar with Python Object Model enough but, if your Python example still allocates an object with slots for all 47 other fields besides the three selected, then you may still find yourself under circumstances you would rather have a "slim" version of the model and reduce memory allocation.

Honestly at that point probably don't be using python. ORM objects don't use slots, they use a hashmap to look up everything every time, and probably that hashmap points to a method that points to another hashmap that points to some kind of data structure.

If you're worried about that than django probably is not for you. That being said it scales out very nicely, you probably are not loading dozens of thousands of entries in to memory at once but are instead using a celery distributed task queue. If you did need to load that much in to memory for some reason (presumably some kind of data science?) You can use the `in_bulk("field1","field2","etc")` query option to return raw data as dictionaries/lists instead of ORM objects. You don't get the benefit of ORM methods but you're not instantiating an ORM object for every row and probably for that kind of thing you're better off taking a more functional approach any way.

Basically if you're worried about how much memory your data is going to take up you probably shouldn't be using django, hacking __slots__ or other memory efficient stuff into the django ORM is going to be tricky. In that case ignore the ORM and just construct your own objects directly or use something better suited for that.

Re: Elixir for Humans Who Know Python

#100
post #65

Earlier quoted context omitted.

> Django does not generate anything through scaffolding like Phoenix I was one of the co-authors of Devise, which is an integrated authentication solution for Rails (similar in spirit to Django), and you will easily find people who swear that the code generation solutions are miles better. That’s because eventually they’d want to customize how the framework or library work and then, instead of simply being able to ch…

With Phoenix 1.7 being released, will there be a new edition of "Programming Phoenix"? The latest one covers Phoenix 1.4, which is already slightly outdated. I think having an up-to-date book would be of great value for Phoenix beginners :)

I don’t think 1.7 is officially out yet as it’s sitting at rc-3.
Post reply on HN