Live data from Hacker News

Building GitHub with Ruby on Rails

github.blog

271–280 of 332 posts

Re: Building GitHub with Ruby on Rails

#271

GitHub running off the main branch is fascinating, and initially sounds mad, but makes so much sense. Assuming they have very high test coverage, running against mainline Rails isn't really any different to having the fork they had before, but they have more influence on future development. It must also be a massive boon for the Rails ecosystem to have such a large property running off the head. Doesn't anyone know o…

You MUST have an insane amount of test coverage to trust something like this to Ruby. I'm new to Ruby, with 13 yoe as a SW engineer. Personally, I find it a very hard language to master. Writing tests often feels like I'm settings variables left and right without seeing them being used in the current context. But that then happens to be part of the let() way in rspec. Now you might say: why use rspec? I inherited thi…

> I do really miss my compiler. I am not a fan of writing a block somewhere that can be invoked 2 weeks later for the first time and then fail, because someone passed in a number where a string was expected.

Problem solved by using Sorbet in your codebase. I know at least Stripe and Shopify do. Also forces you to keep magic at the minimum (which any sane dev would do anyway).

https://shopify.engineering/adopting-sorbet

Re: Building GitHub with Ruby on Rails

#272

Earlier quoted context omitted.

I’m a long time Ruby and Rails developer. I know how the magic works from reading source code. A lot of stuff uses method_missing and define_method. There’s also instance_eval, which is used to create DSLs like rspec. Once you know what they do, stuff makes a lot more sense.

define_method is so weird. Breaks searching through source code.

Ruby tells you where methods are defined - it is worth your time to learn how explore ruby code from the REPL - this is the ruby way. For example (I have pry installed, but you can do it without pry)

    [5] pry(main)> $ user.first_name

    From: /Users/.../.asdf/installs/ruby/2.7.7/lib/ruby/gems/2.7.0/gems/activerecord- 
    6.0.6/lib/active_record/attribute_methods/read.rb:15:
    Owner: User::GeneratedAttributeMethods
    Visibility: public
    Signature: first_name()
    Number of lines: 4

    def #{temp_method_name}
      name = #{attr_name_expr}
      _read_attribute(name) { |n| missing_attribute(n, caller) }
    end
Tells me exactly where this "magic" method is defined, and I can pop open that file and read all the source.

Re: Building GitHub with Ruby on Rails

#273
post #241

Earlier quoted context omitted.

You MUST have an insane amount of test coverage to trust something like this to Ruby. I'm new to Ruby, with 13 yoe as a SW engineer. Personally, I find it a very hard language to master. Writing tests often feels like I'm settings variables left and right without seeing them being used in the current context. But that then happens to be part of the let() way in rspec. Now you might say: why use rspec? I inherited thi…

You don't have to use `let` in specs. I prefer setting instance variables inside a `before :each` block.

`let` has a performance benefit, which is why they are encouraged. They are only executed if called - but if you setup all the ivars in a `before` block, and all those ivars aren't used in every test they waste time - it can be significant if you are using factories for example.

Re: Building GitHub with Ruby on Rails

#274

Earlier quoted context omitted.

define_method is so weird. Breaks searching through source code.

Ruby tells you where methods are defined - it is worth your time to learn how explore ruby code from the REPL - this is the ruby way. For example (I have pry installed, but you can do it without pry) [5] pry(main)> $ user.first_name From: /Users/.../.asdf/installs/ruby/2.7.7/lib/ruby/gems/2.7.0/gems/activerecord- 6.0.6/lib/active_record/attribute_methods/read.rb:15: Owner: User::GeneratedAttributeMethods Visibility:…

Can you point to where this is documented? Thanks for sharing!

Re: Building GitHub with Ruby on Rails

#275
post #4

Is that two millions LOC for a single Rails application or across various Rails applications?

One thing I just cannot wrap my head around is Ruby/Rails metaprogramming and attribution of things (as in "where this method/class/macro comes from?"), especially with so many authors trying to do something to the pre-existing stuff, including the standard library bits. Like, a lot of times I see some baz.foobarify() I have really hard time understanding where the heck that comes from. RubyMine makes wonders and con…

https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debugger... is ruby gold for this kind of stuff. As a Ruby developer, probably one of the most impactful "quick tips" I've ever picked up is this:

  foo.method(:bar).source_location 
That is wildly useful when debugging/figuring out where the actual code for some method is at runtime.

Re: Building GitHub with Ruby on Rails

#277
post #118

I dunno. I lived through Internet Explorer, SCO and Linux patent lawsuit days so I reckon it's only a matter of time before Github goes ASP.Net.

A friend at GH was already writing mostly C# and Go before he moved to engineer manager 2+ years ago, so I believe it's already ongoing. Also he absolutely hated having to jump into components in RoR before Codespaces was available internally.

C# is used for Actions: https://github.com/actions/runner, and Go is used a lot for internal services. There is no traction rewriting our monolith in C#.

Re: Building GitHub with Ruby on Rails

#278

Earlier quoted context omitted.

I started my professional career with Rails 8 years ago and deeply miss aspects of it. It uses lines of code so efficiently, letting you go from zero to product with outrageous speed. Everything is a solved problem. Ruby as a language is so expressive, so beautifully ergonomic, so easy to read. It's such a joy. But the view layer has not aged well. After years of working with a focus on React and TypeScript, I can't…

Have you use the whole Hotwire suite? It's much better than just Stimulus. Componentizing your views will also make it more modern.

I have not, no. When you say “componentizing”, what does that entail? Is it the ViewComponents gem?

If someone reading this has experience with both TS+React and modern Hotwire apps, you’d do the world a service by writing a blog about modern Rails views for the experienced React developer.

Re: Building GitHub with Ruby on Rails

#279

Earlier quoted context omitted.

Have you use the whole Hotwire suite? It's much better than just Stimulus. Componentizing your views will also make it more modern.

I have not, no. When you say “componentizing”, what does that entail? Is it the ViewComponents gem? If someone reading this has experience with both TS+React and modern Hotwire apps, you’d do the world a service by writing a blog about modern Rails views for the experienced React developer.

Yeah what I'm suggesting is a React-y modular view codebase. You can use ViewComponents but I quickly found it was too limited for me and I didn't like to have many files for a single component. I just use Rails partials, the performance hit for my app is none. I also wrote a local VSCode plugin for snippets autocomplete so I can go faster.

Also sprinkle some (rare) Stimulus and Turbo streams/frames.

The one thing you're gonna be missing is typing, Sorbet does not work in views.

Re: Building GitHub with Ruby on Rails

#280

Earlier quoted context omitted.

You MUST have an insane amount of test coverage to trust something like this to Ruby. I'm new to Ruby, with 13 yoe as a SW engineer. Personally, I find it a very hard language to master. Writing tests often feels like I'm settings variables left and right without seeing them being used in the current context. But that then happens to be part of the let() way in rspec. Now you might say: why use rspec? I inherited thi…

Metaprogramming in ruby is not magic. It is fairly simple, but if you come from a language where metaprogramming is difficult or not possible it can seem like magic. Good metaprogramming levels up a language's power in the same way going from a hammer to a nail gun levels up your building power. Creating a DSL in ruby is mostly just creating well named class methods, often that take blocks, and calling them without p…

I've created many DSLs in Ruby. The issue is later debugging said "magic" methods, when said method is throwing an error and you can't find said method in your codebase.

Metaprogramming is pretty amazing for gems and DSLs in a limited domain. When I see business logic that has metaprogramming in it, I kinda freak. I know in the future that business logic will change and debugging the very clever code in that business logic may become a nightmare.

I say this a person who adores Ruby.

Post reply on HN