News for hackers. Stuff that matters.
Re:From Node to Ruby on Rails by saila on Thursday December 16, 2021 @12:18PM (#29580724)
Python has optional static typing, which I think is getting better with each new release, e.g. allowing `T | U` for union types in 3.10.

Types can be checked with mypy: http://www.mypy-lang.org/

For Django, there are these two typing packages:

- https://pypi.org/project/django-stubs

- https://pypi.org/project/django-types

I can't vouch for them, but it looks like they're being actively developed.

I like the idea of full-stack JavaScript (or TypeScript), but last time I tried to use Node for a back end, I couldn't find anything that compared to libraries/frameworks like Django, Rails, SQLAlchemy, etc.

Re:From Node to Ruby on Rails by BasilPH on Thursday December 16, 2021 @05:07PM (#29584659)
We're using django-stubs and we've been pretty happy with it. We've started the project with it, which was fairly simple. There's one or two model field types that are not supported but those can be skipped. We're using pre-commit to run mypy, this makes sure that we never commit a state that isn't type-checked.
Re:From Node to Ruby on Rails by bingohbangoh on Thursday December 16, 2021 @02:16PM (#29582511)
Idk if its just me but I find the testing frameworks for expressJS to be _awful_ -- chai and mocha work great but throw in sinon and its like pulling teeth.

The lack of good documentation is painful and often treats me like I don't already know the concepts involve.

Sequelize isn't as intuitive as Django's ORM either imo.

Re:From Node to Ruby on Rails by crucialfelix on Friday December 17, 2021 @01:09AM (#29588493)
I recently set up a good old Django backend with REST framework. Frontend in Next.js

Turned out to be painfully slow to iterate. The ORM needs constant attention to join or prefetch queries.

Switched to Prisma and it's an utter joy. If the typescript has no errors then there won't be runtime errors.

Sequelize is a multi generational mess. It's a huge time waster.

Re:From Node to Ruby on Rails by ranguna on Friday December 17, 2021 @02:53AM (#29589174)
> Sequelize is a multi generational mess. It's a huge time waster.

Could you elaborate on that ?

I personally like the functional aspect of sequelize.

Re:From Node to Ruby on Rails by crucialfelix on Friday December 17, 2021 @11:42AM (#29594609)
Just that there are several generations of API. This makes TypeScript pretty much useless / impossible.

Working with Prisma: if it compiles (and you don't have a business logic error), then you usually won't get any runtime sql errors.

You don't have type safety with sequelize.

Re:From Node to Ruby on Rails by ranguna on Sunday December 19, 2021 @04:51AM (#29612663)
Ah yes, that's definitely true, automatically generated getters and setters are a pain with sequelize. It's not impassive to have type safety though, it's just complicated.

I had to write my own types around the existing ones to get getters and setters to work.

Re:From Node to Ruby on Rails by saila on Saturday December 18, 2021 @12:40AM (#29602012)
prefetch_related and select_related are pretty straightforward, but for more complex stuff the Django ORM can be a hindrance.

I haven’t checked out Prisma. Thanks for the tip.

Re:From Node to Ruby on Rails by crucialfelix on Saturday December 18, 2021 @02:14PM (#29607569)
Sure, I always have to spend time checking logs and tuning the queries like that. By default, Django selects everything. I used to discover that joins and prefetches were hauling in large text fields when I only wanted an id or a slug.

Prisma has a great API for this, and it's easy to tune. By default is prefetches and selects related even several levels of joins deep.