Readit News logoReadit News
s4i · 3 years ago
In my last job I encountered my first Ruby/Rails codebase ever (mostly REST APIs but a few server-rendered views as well). Despite the initial chaotic impression of the codebase (it was a startup after all) with all the Rails magic on top, I really fell in love with the framework after a more experienced Rails dev introduced a few key conventions and helpful libraries to the codebase.

Out of those, I’d at least add the RuboCop [1] linter and the BetterSpecs [2] guidelines to this list. Both eliminated bikeshedding in the team and freed up brainpower to solve actual problems: the first one helps you learn intricacies of Ruby bit by bit right in the IDE and the latter one pushes you to write test in a specific style that’s easy to maintain and trust.

[1] https://github.com/rubocop/rubocop

[2] https://www.betterspecs.org/

stouset · 3 years ago
I am blown away by the suggestion to use factories over fixtures.

Factories are almost 100% responsible for excruciatingly slow test runs, since you have to rebuild the world every single test. Fixtures work perfectly fine and only need to be created once at the beginning of your test run.

For that matter, rspec itself is also a thoroughly unnecessary cargo-culted dependency when Ruby and Rails already bundle perfectly-serviceable, simple test frameworks.

knappe · 3 years ago
Good luck with those very brittle specs. I have fixed so very many utterly broken tests due to poor spec maintenance mainly due to really poor fixtures. The problem with fixtures is that they do not complain when things go sideways whereas factories are built on top of actual living objects and thus can be validated.

You're generally trading speed for correctness in my experience. There is a time and place, of course, for this tradeoff, but we know how to parallelize specs and make test, in general, faster. Correctness is a whole different story.

epidemian · 3 years ago
Using factories doesn't mean you need to persist everything to the DB on every test.

If you're using FactoryBot for example, you can use `build(:taco)` to instantiate a Taco without persisting it to the DB. If you use `create(:taco)` instead, then yes, the Taco will be saved to the DB, as well as all its associations (if any). This can of course bloat up your test execution time if you're doing this kind of instantiation + persistence on every test.

FactoryBot docs generally use `build` in their examples, as this should be the default build strategy used for most tests, while `create` should only be used on cases where you actually need to interact with the DB.

michaelcampbell · 3 years ago
I love ruby having used it since before Rails, but it seems weirdly susceptible to the "with great power comes great responsibility" issue. Dynamically typed + the "don't disallow stupid things or you'll disallow clever things" mentality, maybe? Early adopters like _why who could actually handle it having a huge influence? Dunno.

I've worked with some devs who were not old battle-scarred greybeards who jumped on EVERY rspec feature because they were there and in a misguided attempt to DRY their test code well beyond reasonable limits.

So I feel you here.

But FactoryBot does allow fixture-like speeds with in-memory .build()'ing. Too few people use it, and too few have succumbed to a preponderance of tests being full-on integration style.

Ruby (and Rails, and rspec) all IMO require a lot more good guidance and wisdom on what NOT to use than other ecosystems I've used.

pelasaco · 3 years ago
> For that matter, rspec itself is also a thoroughly unnecessary cargo-culted dependency when Ruby and Rails already bundle perfectly-serviceable, simple test frameworks

I think people developing professionally and working with large code bases, reach pretty fast all the limitations of minitest. IMO, Minitest is great to test small libs, but as soon as you need to refactor a lot of specs or use other stuff like Factories, then rspec is the tool. No cargo-culted. It is just the best and more complete option.

strzibny · 3 years ago
I too now prefer fixtures. Such a joy to work with them.
Tronno · 3 years ago
I went all in on Rails a couple of years ago. Although the overall feature set is amazing, code discoverability has been a frustrating stumbling block from day one.

The "magic" (convention over configuration, autoloading, metaprogramming, etc) makes it difficult to know what methods are available to use. I end up over-relying on the official docs, which are of inconsistent quality. One example: api.rubyonrails.org lacks code examples, doesn't usually state what a given method returns, and many entries are outright blank.

Editor integration could help, but feels lackluster. With TypeScript in VS Code, hints come up as I write. I can hover anything to see its type, methods, and source code. With Rails, I can poorly approximate this behavior with a collection of half-functional community extensions, or I can buy and use the slow, bloated RubyMine IDE.

Rails enabled me to build my product, but my experience doesn't match the love I hear from other devs. I wish I knew how to make it click.

q7xvh97o2pDhNrh · 3 years ago
I went all in many years ago and then moved on several years ago (to different parts of the stack that I found more interesting), but here's my 2c FWIW.

The Rails Guides [1] are quite good (and much better than the API docs, even for the same topics). The "Getting Started" guide, in particular, was my first intro to Rails, and it's what convinced me to go all in — I built my entire prototype by just following along the guide, seeing what they were doing with their toy app, and then trying to whatever similar thing I needed in my app.

Coming from Python, the magic was distasteful to me, too. Rails adds a ton more magic on top — so, eventually, when I set aside Rails and just spent time with Ruby (writing scripts or what not), I realized I loved Ruby the language much more than Rails the framework (and all its baggage).

Stripping Rails down to its API-only mode (though it was a bit rough around the edges last I tried) got me closer to the Ruby of it all. Sinatra turned out to be a delightful little framework (though sadly I never got a chance to use it much). And, even though I've now moved on from Rails, I still like Ruby as a go-to scripting language — it makes it fun and easy to throw together a quick shell script or some data analysis, and it's very friendly to a functional programming style.

I guess what I'm saying is: You're not alone. Many people in the Rails community agree that there's a ton of hidden magic, sometimes too much [2]. But underneath it all is a delightful programming language.

[1]: https://guides.rubyonrails.org/

[2]: The docs for the Rails routing layer, Journey, are my favorite example of this: https://github.com/rails/journey#label-SYNOPSIS-3A

tuyenhx · 3 years ago
I had exactly the same problem. Recently, with the help of ChatGPT (just free version). When I didnt know anything, I just asked. The result was pretty good.

I also wrote stupid code first in my own version, and copied + pasted to chatGPT, asked it to improve it, or rewrite in ruby on rails style. And wow!! The rewrote version even went with explanation.

Beside that, you can use Rails console to test.

tmm84 · 3 years ago
This was my experience and I have commented it before. The magic/convention approach is the inferred part of Rails/Ruby culture. Where is the class definition? Well, where are you invoking initialization? This question leads to a question which hopefully leads to answer is hard to play by if you’re new or just trying to squash a simple request.

The whole just fire up an interactive session or rails console is probably the last thing I want to do but probably the only way to diagnose or figure out how things are truly working. What monkey patches are in the mix, what libs override methods I set, etc.

For me, Ruby is one of those programming languages that obviously takes a different programming approach and mindset that I don’t have. I don’t think Ruby is bad but I know it isn’t the tool that fits my skill set.

ajmurmann · 3 years ago
A good way to explore is getting an interactive session with something like pry and exploring what methods and attributes are available that way. It sounds clunky, but it's quite effective as you frequently get to play through the entire implementation once and it pairs extremely well with TDD.
cortesoft · 3 years ago
I love ruby, and find it great to use pry and irb to explore and figure stuff out.

However, many times ruby libraries will use dynamic programming and method_missing to define methods on the fly… this makes it really hard to figure out what methods are actually available.

For that reason, I try to never use method missing to define core functionality in ruby, and hate when other gems do it.

subarctic · 3 years ago
I second this, when I was in Ruby land I used to regularly drop a binding.pry (later binding.irb) in the middle of some code i wanted to understand, and call things like `method` to see where an unrecognized method came from.
drusepth · 3 years ago
Pry is amazing for understanding code. IMO the most useful method is absolutely `some_object.methods`, but you can also improve the output a ton by always doing:

    some_object.methods - {}.methods # or some other "parent" class/object
This does set subtraction to remove all the "core" object methods from your some_object methods, so you can see just what's unique about that object. For example, comparing one of my services with a parent Service class it inherits from:

    irb(main):017:0> PaypalService.methods - Service.methods
    => [:capture_invoice_funds, :months_price, :client, :create_prepay_invoice, :order_info]
instead of listing out the 187 methods that PaypalService has that it inherits from Service and every other parent object up the line, which is usually a surprisingly long ancestor list in any Ruby on Rails class (even POROs!).

There are a TON of useful methods like this that I'd recommend getting familiar with, which makes exploration and discovery of code incredibly fast and efficient. You can find them all with the same trick: by using `methods` on any method. :)

    irb(main):043:0> PaypalService.method(:months_price).methods - {}.methods
    => 
    [:<<,                                                                                             
    :>>,                                                                                             
    :arity,                                                                                          
    :curry,                                                                                          
    :source_location,                                                                                
    :call,                                                                                           
    :parameters,                                                                                     
    :original_name,                                                                                  
    :owner,                                                                                          
    :receiver,                                                                                       
    :super_method,                                                                                   
    :name,                                                                                           
    :unbind,                                                                                         
    :comment,                                                                                        
    :source]
Some of the more relevant ones:

    irb(main):037:0> PaypalService.method(:months_price).arity
    => 1

    irb(main):038:0> puts PaypalService.method(:months_price).parameters
    req
    n_months                                                                                  

    irb(main):039:0> puts PaypalService.method(:months_price).source
      def self.months_price(n_months)
        case n_months                                                                         
        when 1                                                                                
          9.00                                                                                
        when 3                                                                                
          24.00
        when 6
          48.00
        when 12
          84.00
        else
          raise "Invalid month prepay: #{n_months}"
        end
      end

heartbreak · 3 years ago
> slow, bloated RubyMine IDE

If you haven’t tried it in a while, it’s quite good on Apple’s arm chips. Doesn’t feel slow at all, and the battery hit is negligible.

web3-is-a-scam · 3 years ago
Using Rubymine on my M1 Ultra Mac Studio is a wonderful experience. Would not trade it for any other environment.
blitz_skull · 3 years ago
I’ll second this. Using RubyMine on an M2 Pro, feels faster than Vim… y’know… the vanilla non-bloated one. :P
Tronno · 3 years ago
Maybe when I can afford one. It's slow on my machine.
Bergrebell · 3 years ago
Thats a good point and nice to see that the rails community is starting to work to consider new engineers more. The whole JS and also PHP/Laravel ecosystem is doing this already since quite some time. Rails is still the best option imo when you want to be productive as a small team - but the learning resource don’t keep up with other frameworks/languages.
kirso · 3 years ago
This is my biggest gripe. I am learning programmning as a hobby, I don't have much time in a day but like to allocate at least 1-2 hours to practice.

When deciding on the language to learn, I really really wanted to go with Ruby and then transition to Rails. But it seems like educational materials are currently lacking, most of the tutorials on YouTube are outdated.

When investing in eco-system, I never looked at the availability of jobs. But when comparing say JS/TS vs Ruby, there is clearly a viable route to learn it as a beginner.

The downside is that there is a lot of trash and low quality materials as well as inhibited complexity - but after some time its not such a problem to sift through the noise.

lylo · 3 years ago
Expect this to change dramatically in the coming months with The Rails Foundation initiatives. Details here:

https://rubyonrails.org/foundation

avg_dev · 3 years ago
i find this critique interesting, because i believe the initial momentum behind rails was sparked by a video about how to create a blog using rails without any setup in just a few minutes.

https://www.youtube.com/watch?v=Gzj723LkRJY

bdcravens · 3 years ago
An almost 20 year old demo from the creator really doesn't address the issue of community resources. Any application of minimal complexity needs to solve problems that demo doesn't begin to address, and beginners need access to resources to guide them in solving those problems.
seattle_spring · 3 years ago
Not to mention that Rails was the language-de-jour for most bootcamps between 2012 and 2017 or so. The problem was running into developers who only knew Rails, not finding ones that didn’t know it at all.
lobstrosity420 · 3 years ago
Also Railscasts.
bongobingo1 · 3 years ago
Some how nostalgic for those plain invert-colours buttons that rails used to have. Also DHH's iconic "whuups!" every 2 minutes is pretty funny to relive.
trilbyglens · 3 years ago
I think one of the things that sort of stopped rails from becoming mainstream was that when WebApps really took off everything switched to SPA apps. Now that's shifting back a bit (a good thing imo) as many people are starting to recognize the downsides of frontend apps. Next.js is basically one giant workaround for the shortcomings of spa apps.
faitswulff · 3 years ago
Rails isn't mainstream? I'm of the opposite opinion - it's definitely in the Boring Technology† Club. It's well known that it's hard to find a more productive tech stack for building server side web apps.

https://boringtechnology.club/

kirso · 3 years ago
This, IMO everyone considers Rails as a solid & production ready framework that stood the test of time.

Unfortunately they slept on front-end for too long but seeing a resurgence with a few startups.

I think Mastodon is actually using it.

Deleted Comment

just3ws · 3 years ago
Rails made Microsoft change its entire web strategy. It influenced so much. Rails is so mainstream that it doesn't get talked about like a hot new tech anymore. If you were a web developer in 2006~2016 it was still hot tech but kind of lost the plot IMO when they really started futzing around with the asset pipeline.
faitswulff · 3 years ago
Rewriting the entire asset pipeline like 3 times since Rails 3.x has really killed my enthusiasm for using Rails for server side rendering.
steve_taylor · 3 years ago
Next.js isn’t one giant workaround for anything. People were building isomorphic SPAs using React long before Next was created. All Next.js did is to put it all together in a simple framework.
CTmystery · 3 years ago
Some googling tells me that isomorphic SPA means the same page can be rendered server side or client side. Is that what it means to you? It's my first time encountering the term. If so ... people were doing that in react??
ransom1538 · 3 years ago
For anyone else out there confused: Next.js != Nest.js.
gymbeaux · 3 years ago
I always hear good things about Ruby on Rails, yet it remains relatively niche. I first heard about Ruby + Rails in 2013, and ten years later it seems to be just as niche. Loved by those who use it, but niche. Why does it continue to struggle in this way when more recent languages like Go are booming?
joshmn · 3 years ago
> Why does it continue to struggle in this way when more recent languages like Go are booming?

It doesn't struggle. It's just not the hot new kid on the block anymore. It's a 2013 Toyota when the rest of the world is all about EVs.

Rails is, as an ecosystem, not lacking much. There's not much room for innovation. It's mature, it's stable, it's scaleable.

Personally, I value my sanity, so I stick with an older Toyota. I don't need panel gaps and batteries exploding. I just wanna build stuff.

pelasaco · 3 years ago
To write web app in golang and write mostly SQL by hand isn't that cool. Yes sometimes it is important, sometimes you should. But ActiveRecord is just a dream, that quite often people even forget how hard was the life before it.

Deleted Comment

zamalek · 3 years ago
> it's scaleable.

That is debatable. Both GitHub and Hackyderm are large-scale Rails deployments, and both share a DevOps engineer (Nóva) who I've heard complaining about Ruby DevOps at least once. Twitter was forced to abandon Rails (being the poster child for Rails at the time).

whichdan · 3 years ago
I think Rails is a victim of its own success: many of the hot new Rails codebases from that time are now 10 year old monoliths. And those monoliths need incredible amounts of tests to compensate for the lack of compile-time type checking, Rails version upgrades are multi-month nightmares, and the object-oriented statefulness of the language means that complex load-bearing code can be extremely tricky to untangle.

There are certainly new compelling projects like Sorbet to add type checking, and the ecosystem itself is very mature, it's just that the average codebase is not going to live up the experience you might have with a brand new one.

berkes · 3 years ago
That ecosystem is crumbling too, unfortunately.

Where, for example, in 2015 any SaaS or API would provide a gem (lib) to interact with it, today it's no longer the case. Modern PSPs, storage, search engines, etc almost all lack an official gem. Often lack even a third party one.

And where back in 2015 there were popular systems in Ruby outside of rails, all those are crumbling and/or gone. Jekyll is no longer the go-to static site manager, Chef and Puppet no longer the obvious devops tools. And Ruby is completely absent from emerging technology (AI, blockchain, WASM, data science, etc).

I'm afraid Ruby is becoming a legacy language and Rails' will be a legacy framework soon. Where the bulk of the Ruby jobs are to keep old stuff running and maintained. Afraid, because I'm still primarily Ruby developer.

buzz27 · 3 years ago
> need incredible amounts of tests to compensate for the lack of compile-time type checking

can you explain this a bit more? it seems to me that test coverage and typing solve different problems.

berkes · 3 years ago
I've been doing fulltime Rails dev for some 15+ years.

Rails (and Ruby) make tradeoffs, or just inherently have downsides that many newer frameworks, libraries and languages solve, or solve differently.

For me, the most prominent are Rubys' dynamic typing and Rails' black magic. But my biggest gripe is how Rails lacks a space for business logic. Sure, you can bolt something on yourself. Or just throw it all throughout the http, storage and rendering layer willi-nilli.

This has caused so many of the codebases i worked on, to be unmaintainable, untestable and therefore legacy that I can certainly blame it on the framework.

I've worked on many go, rust, typescript, php and ruby-no-rails systems to be ever more certain about this. Many frameworks lack this area, and almost all quickly degrade into spaghettis. I've come to like DDD, hexagonal and clean architecture for solving this. Most are perpendicular to Rails.

So, i'm certain that contributor to the lack of popularity of Rails is how hard it is to build maintainable, testable, clean projects in it.

gls2ro · 3 years ago
What is an example of a framework that offers a space for business logic?
Toutouxc · 3 years ago
> But my biggest gripe is how Rails lacks a space for business logic.

You can literally create a directory called app/my_actual_app and put all your business logic in there, Rails will even autoload it for you.

IMO it’s the sudden change from the “we’ll hold your hand every step of the way and offer tools and workflows for everything” web part (controllers, routing, ORM) to the “go and build your goddamn app” dealing with business logic. So many (especially new) devs try to stay in the cozy zone of having a nice name for everything at all costs, so they try to cram everything into “services” and “decorators” and “interactors” (yuck) and they’ll build business logic out of callbacks on ActiveRecord models and overload the poor things with dozens of “concerns” instead of, you know, going and building a goddamn Ruby app.

lylo · 3 years ago
Re: DDD and business logic, I’d recommend reading https://dev.37signals.com/vanilla-rails-is-plenty/
madeofpalk · 3 years ago
I think that the things that Ruby optimises for - mainly that code should be beautiful english prose - just aren't things that developers widely ended valuing.

I think that it's syntax, or what "beautiful ruby code" looks like, is significantly different from most other languages, making it more off putting to pick up or switch between.

nullstyle · 3 years ago
You've got the wrong impression of what ruby optimizes for. It's not "mainly that code should be beautiful English prose" -- which I would venture the closest you'll get for that goal is AppleScript -- but rather, quoting Matz "Instead of emphasizing the what, I want to emphasize the how part: how we feel while programming. That's Ruby's main difference from other language designs. I emphasize the feeling, in particular, how I feel using Ruby."

More here: https://www.artima.com/articles/the-philosophy-of-ruby

xiphias2 · 3 years ago
For me it's quite the opposite. It was the best way to build applications in the past when client side js was hard to use.

Many startups took advantage in creating apps fast with RoR.

Now that (especially with TypeScript) JS is good enough, browsers and JS engines improved a lot, I start to see less advantages in not using js/ts both for client and server.

davnicwil · 3 years ago
I think it might be the proverbial fast boat in a narrow stream, the narrow stream being ruby the language.

It's not a mainstream one, and frankly the main reason to learn it in practice is rails. There's a big cold start problem there.

You have to convince people to like both the language and the framework at the same moment of decision, in addition to committing to learning both at once.

That's just always going to be more difficult than selling only a framework to people who either already know, or see more value in learning, a more mainstream language like JS, Python or Java.

I think this is the biggest reason it's remained niche.

bdcravens · 3 years ago
Rails is very opinionated. Weakening these opinions in the interest of growth has always been strongly rejected.
nahname · 3 years ago
It's a great tool for those that want to build CRUD apps quickly and get 99% of the things right. That speed comes from code re-use (mostly gems). Once you get experienced in rails, you primarily glue things together. It's fast, but does not feel rewarding.
Toutouxc · 3 years ago
> speed comes from code re-use (mostly gems)

> Once you get experienced in rails, you primarily glue things together

Both of these are equally true for most other languages with mature ecosystems. IMO the speed of Rails development reflects the speed of Ruby development in general. The standard library has everything, all kinds of little methods for all kinds of little things. Combine that with ActiveSupport extensions and you can do everything.

  Date.today + 3.years + 2.days
  234.in?(2..235)
  [1,2,3].all?(&:odd?)

4pkjai · 3 years ago
I think they lost a lot of growth because of the bad PR from Twitter.

Twitter started with rails and constantly went down. Rails was blamed for the downtime, perhaps unfairly.

CTmystery · 3 years ago
That's interesting. I remember having to defend my using ruby to other programmers around that time. I always loved it, and all the hate seemed to be centered around "it's too slow". No one ever brought up twitter being down, explicitly, that I can recall. Perhaps that's what they had in the back of their mind though? It's been a bit of a mystery to me why people passionately hate on ruby and IMO dismiss it out of hand. It's so nice to program with.

Deleted Comment

bdcravens · 3 years ago
"The Railscasts Pro videos were recently made free by the author because the videos are dated."

Six years ago (2017), not recently.

http://railscasts.com/announcements/13

aigoochamna · 3 years ago
Feels like I read this announcement yesterday. Time flies!
xyztimm · 3 years ago
My impression (from years past) is that Ruby is what developers loved. It was my first “real” programming language and the reason I fell in love with coding. These days I’m mostly writing in JS and Node for work. Rails is the money-maker, but the philosophy of convention over configuration is why it really off IMO, and something that is both underrated and missing in the JS world.
theflyinghorse · 3 years ago
Rails made me more confused than Spring did. The amount of magic makes it really hard to reason about what's going on.
alex_lav · 3 years ago
IME you’re either a Rails Person or you’re not, and it’s hard to make either group understand why the other likes it. I also couldn’t understand why people would be okay with so much being hidden from them, or made in a way that removed the ability to reason about it externally, but my Rails colleagues just liked it and didn’t understand why I’d care.

Different strokes I guess.

shortcake27 · 3 years ago
If you know what Rails is doing then it isn’t hard to reason about. This comes with time/experience & reading Rails source.

Magic is a beautiful term for what Rails does, because just like a magician’s tricks, it’s possible to have a full understanding of what’s going on. It’s not as if Rails acts randomly.

bigtunacan · 3 years ago
Rails has always been fully open source. If you didn't understand something you simply looked at the Rails source code. At the time it came out most people were using .NET or Java which were largely closed source and PHP which was open source, but there were no real frameworks at that time. CodeIgniter and Cake came out in the couple of years following and were both immature in comparison.