Live data from Hacker News

Elixir for Humans Who Know Python

hibox.live

121–130 of 198 posts

Re: Elixir for Humans Who Know Python

#121
post #112
post #106

Earlier quoted context omitted.

The Phoenix docs don't look like they even hold a candle to Django. I spent 5mins in it and still don't know how to define a model. I eventually figured out a doc section called "Ecto" - so i had to know what ecto was to find it. Then, in those docs I still don't know how to define models. Do they expect me to manage my database and schemas separately and generate the models from that? That's completely opposite what…

I'm not really familiar with Phoenix, but skimming through the section linked below, it seems to cover what you're looking for? Basically, you use a tool to generate your model + migration code and then run the migrations. https://hexdocs.pm/phoenix/ecto.html#using-the-schema-and-mi... As for the comparison to Django, I don't really expect any web framework to have docs at that level. They are simply huge and have be…

Yes, I skimmed through that and was surprised to see it be compared to Django. It's different.

Django is for building CRUD apps quickly. That's it. It's not for the long haul of super complicated apps, which many projects don't ever reach before they fail/get abandoned.

Re: Elixir for Humans Who Know Python

#122
post #106

Earlier quoted context omitted.

The Phoenix docs don't look like they even hold a candle to Django. I spent 5mins in it and still don't know how to define a model. I eventually figured out a doc section called "Ecto" - so i had to know what ecto was to find it. Then, in those docs I still don't know how to define models. Do they expect me to manage my database and schemas separately and generate the models from that? That's completely opposite what…

Phoenix doesn't have the concept of a "model". The functionality of what Rails (and I guess also Django? Idk) calls a "model" is split between a few different places: schemas, changesets, queries, the repo. It felt weird at first, coming from Rails, but after getting used to it I don't miss "models" at all. ActiveRecord models in Rails are a vastly overloaded concept anyway and pretty much always degenerate fast into…

Yeah, for a big complicated system, I don't think defining everything in models is great. I don't do that, and it's also not how fastcomments is built.

But for simple stuff it's amazingly productive!

Re: Elixir for Humans Who Know Python

#123

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…

Please notice that nothing stops you from defining a non managed (ie Django migrations won't mess with it) model pointing to the same table and having declared only three of the fields of the original model.

Re: Elixir for Humans Who Know Python

#124
post #82

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…

> For a long time I didn't realize why people were so down on ORMs until I tried using a non-django ORM, it really does set the bar. This. Very much this. I have given up on one finding such. The closest and nicest one that comes to mind is SQLAlchemy. The rest of languages or frameworks have indeed nothing compared to Django ORM and SQLAlchemy. It's not even fair to compare them.

My experience is also exactly like this. I have a project in java/spring and it uses hibernate as an ORM. I can't think of how much better is the Django ORM than hibernate. When people express hate for ORMs I understand where this hates comes from.

If I ever need to do another Java project I prefer to use raw jdbc sql than using hibernate.

Re: Elixir for Humans Who Know Python

#125

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…

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

This isn't really true. Although having a built in redis may be possible, the fact is that production elixir projects do use redis on a lot of cases (for example as a task queue). ETS is rarely used because of its complexity.

Re: Elixir for Humans Who Know Python

#126

Earlier quoted context omitted.

>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? Django models are normal python classes. Depends on exactly the logic you're dealing with, but generally you can make logic be a method on that class. Try to avoid logic that spans multiple tables in general, and if you have logic that does span multipl…

Thanks for the insights, I appreciate it! I will take some time to go through the docs and learn more. One last question for now (I hope): after the migrations are auto-generated, do you check them into version control? > Models are for developers and generally developers have all the permissions any way To clarify, the reason why you would want to have read-only models is rather in complex data model cases or for pe…

You can use `managed = False` and `db_table` to have another model pointing to the same table. `managed = False` will stop Django automatically creating schema migrations.

eg.

```

class ReadOnlyUser(models.Model):

    email = models.CharField(max_length=255)

    class Meta:
        db_table = "users"
        managed = False
```

Re: Elixir for Humans Who Know Python

#127

Earlier quoted context omitted.

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 Redm…

I could be wrong and I really hope I am ... I really think it's the best stack out there, at least until you need the sort of extreme performance that dictates Rust (and even there Rustler looks good ... particularly as Rust extensions shouldn't jeopardise the extreme stability of the BEAM). But right now it looks on course to go the way of Clojure or Scala ... hanging in there for sure, but never becoming a major pl…

Why does it have to be a "major player"? :) Going the way of Scala, Clojure, etc is fine. If you have a community where people are innovating and/or enjoying the journey, companies feel productive but invest and understand the pros and cons of the ecosystem, then to me it is all good.

They estimate there are more than 20 million developers worldwide and, if a technology can reach 1% of that, I personally find that amazing (in the "super made it" kind of way).

I am not saying this in a self-congratulatory way (especially cause we haven't reached it) but just generally. Anyone who worked on any sort of moderately used open source project has likely have gone through several rounds of "who is using it? anyone big?" and I wish people can appreciate the small victories rather than aiming to the highest of goals, which most projects will realistically (and understandably) not reach.

If you or your company needs to reassure the accountant, then those languages are not for you, and there is nothing wrong with that. Other than that, your perspective of companies hiring for Elixir is drastically different than mine. :)

Re: Elixir for Humans Who Know Python

#128
post #48

I have been working on a library for Django that allows you to build reusable template components, and it is heavily inspired by Phoenix's Components. I just released it today, so if you are a Django user and find the way that Phoenix Components work interesting, give it a try! https://github.com/Xzya/django-web-components

This project is very similar to django components https://pypi.org/project/django-components/

Re: Elixir for Humans Who Know Python

#129

Earlier quoted context omitted.

It is totally fine to get spoiled if you consider it is better :D Your case about structure.sql is interesting. It would be nice if we could automate it somehow but, if we simply tried to re-run a changed migration, then the migration would likely fail because the other operations in it (such as adding fields), you already exist, no? Do you have any suggestions/ideas on how to tackle this? We could have a "mix ecto.m…

Django’s approach is to run all the migrations, from the migration files, if the database gets wiped clean. In other words, if you’re developing on your local machine, you can just drop the DB and start new (or if using SQLite, just delete a file), and after running migrations, you never have to worry about whether all the necessary files are in sync with the database. As Neo might say:“there is no spoon…” seriously,…

Thanks! FWIW, structure.sql is not needed in Ecto either. You must do that when:

1. You want to start discarding migrations (because you have too many) 2. You had an existing database

Are those never a "trigger" on Django side? I appreciate the opportunity to learn!

Re: Elixir for Humans Who Know Python

#130

Earlier quoted context omitted.

>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? Django models are normal python classes. Depends on exactly the logic you're dealing with, but generally you can make logic be a method on that class. Try to avoid logic that spans multiple tables in general, and if you have logic that does span multipl…

Thanks for the insights, I appreciate it! I will take some time to go through the docs and learn more. One last question for now (I hope): after the migrations are auto-generated, do you check them into version control? > Models are for developers and generally developers have all the permissions any way To clarify, the reason why you would want to have read-only models is rather in complex data model cases or for pe…

Just wanted to say thank you for all the great work you've been doing. I'm a recent Elixir/Phoenix convert coming from a couple of years of full time Django and it makes me so happy to see you being interested in the way Django handles models. Imo it's one of the last things I'm struggling leaving behind (together with its tight integration of the Django admin, which you get for free).

I haven't looked close into Ash but to me it seems their approach is interesting and offers a solution, not the way Django does it but it is a solution, although a bit hard to wrap your head around at first. Django models are more simple and straightforward.

Post reply on HN