News for hackers. Stuff that matters.
Re:Learning Ruby: Things I Like, Things I Miss from Python by mparramon on Tuesday February 16, 2021 @04:11AM (#26152246)
I would love to find an MVC framework with the extense library support of Rails but for Javascript. Being able to simply `gem 'devise'` and have full authentication at your hands (including views, email templates, etc) is a godsend.

At many places where I've worked at this paradigm is exactly what is needed, but people know and want to use JS. If we choose to go that way then, we need to write a lot of glue code and think about setting up architecture standards, folder and naming conventions, ORM support, authentication, job queues, etc; all of this comes by default with Rails and makes life so much easier.

Lately some options seem to be gaining steam:

* RedwoodJS [1]: by Tom Preston-Werner (founder of Github), comes with React and GraphQL baked in, pretty new project though

* Next.js [2]: brings a lot of nice conventions to the frontend, but still some things missing on the backend side

* SailsJS [3]: similar to Rails, but small community

* Strapi [4], hapi [5] et al: plenty of backend functionality, but frontend agnostic.

Has anybody had experience with any of these (or others) and can report back?

[1] - https://redwoodjs.com/

[2] - https://nextjs.org/

[3] - https://sailsjs.com/

[4] - https://strapi.io/

[5] - https://hapi.dev/

Re:Learning Ruby: Things I Like, Things I Miss from Python by nickjj on Tuesday February 16, 2021 @07:17AM (#26153190)
I think this is a very uphill battle because JS and most other languages are missing a key ingredient that Rails has had for 10+ years. It's having a long running large real world SAAS app that Rails is extracted from.

That means every feature of Rails is derived from a practical use case, and then it's well tested in that app before it's pushed out to the community. That's tested from an API and functionality point of view. By the time end users start to use it, the feature has likely been running in production for 6+ months. Maybe even serving billions of page views through it if you factor in Shopify and GitHub also running off Rails master.

It's all constantly in use, kept up to date and iterated on as a whole.

Creating a starter kit / boiler plate of libraries and opinions in another language / web framework is not the same. I think this is why even after 10+ years there's only a handful of popular Rails alternatives in other languages.

Re:Learning Ruby: Things I Like, Things I Miss from Python by ivanhoe on Tuesday February 16, 2021 @07:49AM (#26153375)
There's plenty of JS code written out of the real needs and by teams running huge projects, take just Facebook as an example. Problem is that there are thousands of solutions for everything, and that saturation and bad signal to noise ratio makes it hard sometimes to pick the right lib (or even hear about it in the first place). Rails have a huge benefit of having a single team behind it, so you always have a recommended way of doing things, and the whole community is smaller, less libs to test, less rubbish to avoid, making the experience much more linear...
Re:Learning Ruby: Things I Like, Things I Miss from Python by gls2ro on Tuesday February 16, 2021 @05:25AM (#26152651)
I don't have a recommendation, but here is a quick test I use when looking for a replacement for Rails:

How quick can I create a minimum simple SaaS like application that has the following functionalities:

- User management (Signup/Login/Reset password/Confirmation...)

- Simple payment processing (like have on single plan, one time fee, and after paying the user will see some other default page then not paying)

- Sending emails in HTML and plain text (for user management and after payment is processed)

- Use slugged/permalink like URLs

- Processing some task in async queue

And so far there are a lot of alternatives out there but for me Rails provides the easiest experience to have this up and running quickly as there are already battle-tested gems for almost all these functionalities.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @05:58AM (#26152807)
Just wondering: is rails transactional? What I mean how are race conditions avoided if e. g. two requests are processed at the same time.
Re:Learning Ruby: Things I Like, Things I Miss from Python by brightball on Tuesday February 16, 2021 @09:34AM (#26154176)
It's got a very helpful transaction block wrapper structure that allows you to do some really interesting things with database transactions.

To be perfectly honest, one of the things that I always love about Rails is exactly how good the database layer is with ActiveRecord. I like using the advanced features of my database, especially PostgreSQL, and I've found that it's really easy to do with Rails.

The "Scopes" feature of active record that let's you save small snippets of a query and chain them together is fantastic. I've used it to create complex filter functions that combine full text search and coordinate distance as simple methods that can be attached to any query.

Being able to add a `.search("fender").distance_from(location, 5, :miles)` onto any query made my life so much easier.

It's been a few years, but I wrote about some of my favorites.

https://www.brightball.com/articles/rails-gems-to-unlock-adv...

Re:Learning Ruby: Things I Like, Things I Miss from Python by ryanbrunner on Tuesday February 16, 2021 @07:39AM (#26153312)
Rails has support for database transactions, but depending on what you want to do, things won't be magically transactional all by themselves (that said, it's really just a matter of wrapping transactional code in a block).

There are a couple of footguns in Rails involving transactions - by default, validating uniqueness of a column in Rails will be done at the app layer which is prone to race conditions, and with a typical CRUD model for an application, there's nothing in particular preventing overwrites of model data if say, a field was present on a form and two people were editing it, even if the "later" editor made no changes to that particular field.

When multiple systems and things other than databases (or multiple databases) are involved, you're generally on your own as well.

Re:Learning Ruby: Things I Like, Things I Miss from Python by pbowyer on Tuesday February 16, 2021 @08:53AM (#26153852)
It's important to say that these footguns are not exclusive to Rails. I don't know a single web framework which avoids them - if it exists I'd like to know so I can learn how they do it.
Re:Learning Ruby: Things I Like, Things I Miss from Python by RickSullivan on Tuesday February 16, 2021 @05:32PM (#26159606)
Elixir's Ecto has the best solution to this problem in my experience--it doesn't do database validations on things like uniqueness, but provides easy error handling when constraints are hit.

It encourages you to write validations for things that don't need to hit the DB, but actually uses the DB for handling constraints, since it's the real source of truth for data consistency.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @10:06AM (#26154492)
Thanks. So typical CRUD applications usually run on luck? (or on not beeing unlucky if the average number of request per hour is not so high).
Re:Learning Ruby: Things I Like, Things I Miss from Python by msbarnett on Tuesday February 16, 2021 @11:58AM (#26155979)
Not really?

Most CRUD applications go the one extra step of putting a uniqueness constraint on the column instead of just relying on the app layer validation, and comparing hidden time stamps on the form if multiple people might edit the same row simultaneously. It’s exceedingly straightforward.

Did you really think thousands of web apps up to and including GitHub and shopify were squeaking by on blind luck? If basic database transactions and integrity weren’t doable in Rails, that’d have had to have been fixed years ago.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @12:02PM (#26156024)
Any reference how this is best done with rails?
Re:Learning Ruby: Things I Like, Things I Miss from Python by msbarnett on Tuesday February 16, 2021 @12:28PM (#26156343)
Depends on what you mean by “this”, I suppose.

Most of your basic questions are covered by the starter Rails Guide for ActiveRecord, eg) transactions, validations, how to add a uniqueness constraint to the DB in a migration

https://guides.rubyonrails.org/active_record_basics.html

The ActiveRecord Queries guide also covers some mechanisms for handling row-level write contention

https://guides.rubyonrails.org/active_record_querying.html#l...

Re:Learning Ruby: Things I Like, Things I Miss from Python by gls2ro on Tuesday February 16, 2021 @06:25AM (#26152933)
In case of DB:

I think ActiveRecord has #lock (see https://api.rubyonrails.org/classes/ActiveRecord/Locking/Opt...) and that together with #transaction (https://api.rubyonrails.org/classes/ActiveRecord/Transaction...) are enough for my use cases.

In case of file uploads to cloud providers: there I don't know for specific method to help with race conditions when transforming the resources.

Re:Learning Ruby: Things I Like, Things I Miss from Python by AlphaWeaver on Tuesday February 16, 2021 @11:54AM (#26155932)
I've used 1, 2, and 4.

Strapi [4] is much less stable than it looks. It's pretty buggy, isn't designed very well, and is just all around messy. I used it in production once and never will again.

Next.js [2] is well designed and well maintained, but is totally a frontend framework. It's not just "missing a few things" on the backend side, there is no backend side. Works great if you already have an API (JAMStack) but can't stand alone in the way that Rails or Laravel might be able to.

Despite being the youngest, RedwoodJS [1] is the best option here. I was actually involved pretty early on as a contributor on the project before I had to step away (unrelated, personal reasons) and was seriously impressed by their progress. TPW runs a tight ship, and all of the devs that work on the project are smart and amazing. They ship very quickly and it's rapidly growing into the closest thing to a Rails competitor in Javascript. I wouldn't be surprised if it takes the JS world by storm in a year or two.

Re:Learning Ruby: Things I Like, Things I Miss from Python by berkes on Tuesday February 16, 2021 @11:49AM (#26155871)
> Being able to simply `gem 'devise'` and have full authentication at your hands (including views, email templates, etc) is a godsend.

I'm on the other end of the spectrum.

I mean, I see the benefit of such "roll X quick by adding a gem" for a proof of concept, a demo or even an MVC.

But even for the latter, it breaks down rapidly. Such gems bring their own libraries. They force you to "do it their way". A gem like devise comes with its own addons (omniauth) that paint you even quicker into a corner.

I've consulted and developed at many Rails codebase where most of the problems were caused by years of development on top of such gems. A weak, wobbly base, and the entire castle built on top of that. Where 90% of the devise features were unused or worked around. Where more code was present to customise and work around devise-isms, AASM-weirdness, CanCan-troubles, than a complete "roll your own from scratch" would have ever caused.

So, my "devise advise" always is: sure, use it to get your product to market rapidly. But be sure to pull it out and replace it with a focused, fitting architecture, sooner rather than later.

Such gems fit very well in the problematic development-workflow where one "searches for an existing gem which offers some version of Foo" rather than "figuring out how we want to do Foo, then look for a gem that does it our way".

Re:Learning Ruby: Things I Like, Things I Miss from Python by mparramon on Tuesday February 16, 2021 @10:51PM (#26162440)
I think this is due to the extent of the maintenance efforts by the team that develops the app, not due to the gems themselves. A monolithic app means that no code is legacy code: a conscious, gardening-like effort needs to be continuously done to keep interfaces standardised, modules documented, code clean, and critical components (like user management) top-notch with focused testing and code quality metrics. I've worked in different teams on 5+ year codebases that hold up to this day by being disciplined on this terms and never buckling down on complexity.

What I've also seen is that a team with plenty of churn or no time for maintenance will have exactly the problems you describe. As knowledgeable people leave the team, the old code becomes "legacy", new people come and partially refactor it, maybe adding some new gem and planning to migrate the entire codebase later on to it (which is very hard to make it happen). Stakeholders' pressure will force the team to focus on delivering features and only tackling debt when it gets to an unattainable state, and then is when consultants are called. I think this is why many freelancers suffer the worst of Rails (or any other framework) if they don't usually work with greenfield projects.

Re:Learning Ruby: Things I Like, Things I Miss from Python by berkes on Wednesday February 17, 2021 @09:04AM (#26166358)
To continue the "gardening" analogy: sure. Continuous pruning, weeding (refactoring) and fertilizing (keeping up to date) is needed.

But this is easier and more rewarding in a garden that is well layed out and allows flexibility to move things around.

An old, crumbling shed, in the middle of that garden limits what you can do with it. It is always in the way, always visible and often defines the entire garden, when you really don't find it that important.

A gem, like devise, defines what your users are (it limits your freedom to define the Domain model), how your onboarding flow works (which is probably your most important money-maker) and what features you can implement and what not.

When you started with the garden, it was handy to have a quick and ready place to store your tools. So the first cheap, off-the-shelve shed, is the best solution. But once your garden is defined, you probably want to move it aside, nicely integrated in your garden and well maintained and exactly large enough for your tools, so it leaves as much space for your flowers and trees -the stuff that matters-.

Re:Learning Ruby: Things I Like, Things I Miss from Python by twic on Tuesday February 16, 2021 @07:38AM (#26153311)
It's crazy to me that every other language doesn't have a Rails, literally just a clone. It has been so obviously valuable, and is now so well understood.
Re:Learning Ruby: Things I Like, Things I Miss from Python by pjmlp on Tuesday February 16, 2021 @11:46AM (#26155838)
We were using AOLServer and its clones, Vignette, Zope before Rails was invented.

Most of the Java and .NET world eventually moved into full blown CMS, with component frameworks, graphical layout editors, user management and third party connectors to distributed platforms.

For me, Rails just feels too little, with a quite slow language.

Re:Learning Ruby: Things I Like, Things I Miss from Python by cjohnson318 on Tuesday February 16, 2021 @12:18PM (#26156211)
I like using Django [0] with django-rest-framework [1] and dj-rest-auth [2]. This gets you Rails-inspired organization, with a nice abstraction for REST endpoints in general, and a login/logout/registration/email verification/social auth in particular. Everything is built on the very well maintained allauth [3] module. Here's a good quickstart [4]. I've used Ruby in production, but I like Python's "one way of doing things" approach.

[0] - https://www.djangoproject.com/ [1] - https://www.django-rest-framework.org/ [2] - https://dj-rest-auth.readthedocs.io/en/latest/index.html [3] - https://django-allauth.readthedocs.io/en/latest/overview.htm... [4] - https://www.rootstrap.com/blog/registration-and-authenticati...

Re:Learning Ruby: Things I Like, Things I Miss from Python by illiriath on Tuesday February 16, 2021 @05:42AM (#26152725)
I've had good experience using Nest.JS [1] for the backend and next.js for the frontend. Nest has defaults for ORM, validation, task scheduling, authentication, etc, I find it a lot easier to work with when compared to plain express projects with tons of glue.

Disclaimer: I have never tried Rails

[1] https://nestjs.com/

Re:Learning Ruby: Things I Like, Things I Miss from Python by patates on Tuesday February 16, 2021 @05:17AM (#26152615)
https://nestjs.com/ is nice, although I'm not sure about your front-end expectations.
Re:Learning Ruby: Things I Like, Things I Miss from Python by busk07 on Tuesday February 16, 2021 @06:35AM (#26152980)
https://adonisjs.com <- feels the closest to rails but with nodejs instead
Re:Learning Ruby: Things I Like, Things I Miss from Python by alejandro_del on Tuesday February 16, 2021 @07:39AM (#26153318)
Re:Learning Ruby: Things I Like, Things I Miss from Python by claudiojulio on Tuesday February 16, 2021 @06:37AM (#26152996)