HNHacker News
TopNewBestAskShowJobs

chris12321

134 karma · joined October 16, 2022

submissionscomments
chris12321··on Mastering Ruby Code Navigation: Ruby LSP Enhancements in the First Half of 2024
ActiveRecord doesn't generate models based on database tables, it uses conventions on table and attribute names along with Ruby's metaprogramming capabilities to define behaviour on models automatically. From my understanding, Cayenne requires manual mapping of the database to your models, which is done via XML files that are either handwritten or generated by their GUI application and have to be regenerated on every database change. That's a far cry from the ease of use of ActiveRecord. How you value that ease of use versus your desire for static typing is up to you, but they’re not comparable from a functionality point of view.

And like I said above while you might be able to recreate some of Rails' functionality in other languages, you wouldn't be able to replicate all of it with the same fluidity and readability that you have in Rails

chris12321··on Mastering Ruby Code Navigation: Ruby LSP Enhancements in the First Half of 2024
In terms of convention over configuration, Ruby's metaprogramming is crucial for the name-based class conventions that make Rails so convenient. For instance, if you have a class User with the attribute name, at runtime Rails dynamically adds methods to the User class, allowing you to do things like User.find_by_name("Alice"). Rails uses Ruby's metaprogramming capabilities to accomplish this.

The same is true for defining associations between models. Consider the following model:

   class User < ApplicationRecord
     belongs_to :organization
     scope :active, -> { where(active: true) }
   end
You mentioned that DSLs aren't important, but the DSL for defining associations is extremely convenient. Adding the belongs_to line defines numerous methods on the User class, allowing you to do things like User.last.organization. The scope line dynamically defines the active method, allowing you to call User.active, which executes the code in the provided block. There are also DSLs for defining routes and migrations, which are extremely important when using Rails.

Ruby's metaprogramming is also utilized in Rails controllers to load the correct code. For example, the index method in the UsersController knows to look for the views/users/index.html file because it can reflect on the method and the class to determine where to load the correct code using Rails' autoloader, Zeitwerk.

Ruby's open classes and monkey patching (something that should be done with extreme caution) allow ActiveSupport to add extremely useful methods to Ruby's base classes. This enables conveniences such as Date.today - 10.days or DateTime.now.beginning_of_day.

These are just a few examples that I can think of off the top of my head, but nearly every major convenience in Rails relies on the flexibility provided by Ruby. While it might be possible to reproduce many aspects of Rails in JavaScript, I don't believe you could replicate all of it with the same readability and intuitiveness that Rails offers.

chris12321··on Mastering Ruby Code Navigation: Ruby LSP Enhancements in the First Half of 2024
It's really the other way around, Ruby is the superpower that makes Rails what it is. There are very few (if any) web frameworks comparable to Rails because Rails is only possible due to the dynamism and expressiveness provided by Ruby.
chris12321··on Async Ruby on Rails
Ruby methods can have both positional and keyword arguments, so, in this case, the `has_many` method takes the symbol `:players` as an argument and takes a keyword argument called `dependent:` which is being passed the symbol `:destroy_async`. Where a symbol in Ruby is an immutable identifier.

So a method like this would be defined as something like:

  def has_many(model_name, dependent:)
    puts model_name.to_s
    puts dependent.to_s
  end
Which you could then call as:

  has_many(:players, dependent: :destroy_async)
or

  has_many :players, dependent: :destroy_async
Since you don't need to put parenthesis around method arguments in ruby.
chris12321··on Analysing the Twitter User Exodus to Mastodon, Bluesky, and Threads
As a Rails developer, I am quietly rooting for Mastodon, but I don't see it gaining the mass adoption necessary for a social network.
chris12321··on I Love Ruby
Most code doesn't follow SOLID principles.
chris12321··on I Love Ruby
Those things are all just Objects in Ruby, just with some syntactic sugar, not built in data types. `/a?/` is just syntactic sugar for `Regexp.new('a?')`, ['a','b','c'] is just `Array.[]( 'a', 'b', 'c')` everything is an object being sent messages.
chris12321··on Django 5.0
Well it's trivial in ActiveRecord to avoid n+1s by preloading associations. As with any technology, if you use it wrong and inefficently then things will be incorrect and slow.
chris12321··on Shopify Ruby on Rails distributed monolith runs 19M queries per second on MySQL
For some reason, some people with discount any example of Rails scalability as not counting.
chris12321··on "Useless Ruby sugar": Argument forwarding
No, it's a question, "does array x include object y?" `x.include?(y)`
chris12321··on The Beatles: 'final' song Now and Then to be released thanks to AI technology
No it's not a deep fake, the AI was just used to isolate John's vocals from a demo tape.
chris12321··on How Airbnb Scaled by Moving Away from a Rails Monolith
They've just posted the recording

https://www.youtube.com/watch?v=wV1Yva-Dp4Y

chris12321··on How Airbnb Scaled by Moving Away from a Rails Monolith
Intercom gave a talk at the recent Rails world conference about how they moved to a micro service based architecture, but all it ended up doing was increase operational complexity. They're now in the process of porting their microservices into their monolith.

All the talks are being released in the next week or so, you should take a look when it's out, it was very interesting.

chris12321··on How Airbnb Scaled by Moving Away from a Rails Monolith
DDH made a funny comment about this in his keynote for the Rails World conference that just happened:

"Twitter moved off rails and I was always really curious about that story. Here's a testimony from someone who actually worked at Twitter when they moved off. Yeah they moved off because they had a badly designed Rails app, that happens. Okay and then they moved into what they thought was better a constellation of java microservices and then nothing fucking happened for 10 years. They poured concrete over the application and hired thousands of people to make no progress at all."

You can watch the whole talk here, the quote starts around the 15 min mark:

https://www.youtube.com/watch?v=iqXjGiQ_D-A

chris12321··on How Airbnb Scaled by Moving Away from a Rails Monolith
I recently saw a talk from lead engineer at Intercom who talked about how they're moving away from micro services and porting them over into their rails monolith. Their reasoning was that that managing all these services creates a huge amount of operational overhead and siloing of knowledge while providing no actual benefit when it came to scalability.
chris12321··on Why is it so hard to measure productivity?
> in an ephemeral way, yes.

So no. Or why not measure productivity in an ephemeral way.

chris12321··on UK: No-fault evictions to be banned in reform of rental sector
They've only just abandoned their manifesto commitment to leasehold reform last week.

https://www.theguardian.com/money/2023/may/10/plans-abolish-...

chris12321··on UK: No-fault evictions to be banned in reform of rental sector
The Tories have been dangling rental reform in front of the electorate for a decade now. Considering the number of MP's who are landlords and where the Tories get there money from, I'll believe this when it's actually through parliament.
chris12321··on UK: No-fault evictions to be banned in reform of rental sector
Land ownership here in the UK has hardly progressed past the feudal system. Have a look into leaseholds if you want to see how bad it is.
chris12321··on Crystal for Rubyists
Just because Rails is untyped doesn't mean you can add type definitions to your own code within a rails application.
chris12321··on Ruby adds a core class called Data to represent simple immutable value objects
Sharp knives and all that
chris12321··on Moving from React to htmx
With bundler, Ruby dependency management is excellent. I don't think I've ever had a problem setting up an app where the Ruby dependencies are the issue. I certainly can't say the same for JavaScript apps.
← PreviousPage 2 of 2