r/ruby • • Sep 30 '21

ActiveAdmin, I'm looking at you

Post image
238 Upvotes

58 comments sorted by

9

u/jibbist Sep 30 '21

Motor admin is a much much better alternative https://github.com/motor-admin/motor-admin-rails. Have been using it production for a few months now, and it's awesome

3

u/UsAndRufus Sep 30 '21

Interesting! Seems very WYSIWYG focus, though. Part of our issue with ActiveAdmin is we need to run some custom code on controllers/forms and AA makes that difficult. Is Motor good for that? Although that said, the custom code we run may be less relevant if Motor supports better datatypes, validations, etc

3

u/jibbist Sep 30 '21

You have access to ‘forms’ which are basically POST requests to an endpoint of your liking. We have a dedicated super admin controller full of actions that we can separately test & means there actually basically no custom ‘motor_admin DSL’ code like there is with active admin. All of it is reusable if you, say, just removed motor_admin and just had rails views pointing to the same controller actions.

Mainly though, it’s that the interface is customisable & configurable all through the database and config files

2

u/UsAndRufus Sep 30 '21

Ah interesting. We have some administrate for a different part of our app, which I think works in a similar way.

4

u/tinyOnion Sep 30 '21

something worth looking into is a "spinoff" of administrate called madmin. still somewhat early gem but it's made by one of the rails video series sites and is going to be the basis of their paid jumpstart rails template things so I imagine it will be actively maintained for a good bit. (not sure where it's at now thought)

45

u/campbellm Sep 30 '21

I know this is often an unpopular opinion, but I've grown to hate DSL's. They are almost NEVER good, solve the wrong problem, and generally badly. So I feel the author of this meme 100%.

25

u/jrochkind Sep 30 '21 edited Sep 30 '21

I realized, especially in ruby, I don't understand the difference between a "DSL" and any other API. (I'm talking about code-level API's, methods and such, not http/network). Because what we call "DSLs" in ruby are usually just calling ruby methods after all, we're not actually talking about writing a parser for another language or anything.

Obviously API's are unavoidable.

And yet, I am sympathetic to what you are saying too. But it kind of turns into questions of: What makes some API's better than others? What makes some kind of API's the kind of thing we want to call "DSL", is it a continuum or a sharp binary division? What makes those aspects of an API that make us want to call them "DSL" seem to correlate with bad abstraction? (If "bad abstraction" can be used as a category covering "solving the wrong problem, badly").

And some (non-final) thoughts about (just some areas of) some answers: "DSL" is often (probably not always) trying to make a declarative solution. Which is an understandable thing to do because a good declarative API is an amazingly efficient and useful thing. But it's hard to do well, and requires you have a really good understanding of the domain. And when you fail to succeed at it, which you often can't know until you are in it, the consequences can be disastrous.

13

u/UsAndRufus Sep 30 '21

I recently heard about Greenspun's Tenth Rule. It humorously answers what you are trying to ask

13

u/WikiSummarizerBot Sep 30 '21

Greenspun's tenth rule

Greenspun's tenth rule of programming is an aphorism in computer programming and especially programming language circles that states: Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

21

u/[deleted] Sep 30 '21

Pretty sure a DSL is just when you don’t use parentheses on method calls 🤷

22

u/nom_nom_nom_nom_lol Sep 30 '21

There are some gems with decent DSLs. Take factory_bot, for example. Its DSL is based off of your Ruby classes. If you know your class, you know how to create a factory for it.

Most of the time, though, if I see a gem with a DSL, I try to find something else and only use the DSL based gem when its absolutely necessary. It's the main reason I use MiniTest instead of RSpec. With MiniTest you just write your test methods. Whenever I've used RSpec, I have to have the browser open to its documentation pretty much the entire time I'm writing my tests.

1

u/disclosure5 Oct 04 '21

if I see a gem with a DSL, I try to find something else and only use the DSL based gem when its absolutely necessary. It's the main reason I use MiniTest instead of RSpec.

Wait until someone sends you a PR to rewrite your entire test suite from Minitest to RSpec...

4

u/mattgrave Sep 30 '21

After 7 years of working in Rails projects, this is the first time I have landed into a project where ActiveAdmin was extensively used: in-house plugins, redefining views with Arbre Components, customizing pretty much the whole page.

The cost of that is the leaky abstraction this has, you end up not giving a fuck about the DSL and reading their code to learn how it works behind the scenes.

Either way, I have found it a great tool to satisfy simple use cases. In other projects when the use cases got too complex we built this views manually (without AA in the middle). It becomes a sort of Frankestein, but we found this approach simpler that extending or hacking the gem to make it work for us.

2

u/UsAndRufus Sep 30 '21

Yeah, there are so many weird curveballs in AA that I end up reading the RDocs to work out how the hell the internal implementations work.

I'd say AA tries to be like Rails: good defaults, easily get going. The difference is that in Rails, you can easily overwrite stuff and do your own thing. "It just works" only works until it doesn't, at which point you need to be able to access the raw power underneath.

2

u/LePootPootJames Oct 01 '21

I think was just meant to be used as a simple admin tool than can be quickly deployed. If the project has more complex requirements, it's probably best to use another tool.

1

u/UsAndRufus Oct 01 '21

This is the thing though, it started out as a simple admin tool, but over time those requirements have grown.

3

u/LePootPootJames Oct 01 '21

Yep. Been there many times. "Let's just add this small thing here..." Before you know it, you're knee deep in AA source code at 1am in the morning.

43

u/wufufufu Sep 30 '21

I spend a lot of time reverse engineering some 34-GitHub-star gem’s meta programming

3

u/[deleted] Oct 01 '21

Hey wow a funny programming meme not in programmerhumor

Well done friendo

2

u/UsAndRufus Oct 01 '21

I may have reposetd this in programmerhumor as well lol

20

u/honeyryderchuck Sep 30 '21

With great DSL power, comes great DSL maintenance.

7

u/TODO_getLife Sep 30 '21

So glad I don't have to deal with ActiveAdmin anymore.

4

u/mys31f_cs Sep 30 '21

life using gems

4

u/jaypeejay Sep 30 '21

What’s DSL?

6

u/WalterPecky Sep 30 '21

Domain Specific Language

3

u/jaypeejay Sep 30 '21

That’s what I was thinking after Google. How can a gem be a DSL? Won’t the gem be written in Ruby as well?

9

u/[deleted] Sep 30 '21

You can have a dsl written in Ruby.

Take rspec for example: you

describe 'Numbers' do
  it 'is equal to itself' do
    expect(1).to eq 1
  end
end

9

u/jaypeejay Sep 30 '21

Ah okay, great example. So the idea is by extending the general language we can develop a new “language” (basically new methods and syntax) to fit a specific need.

3

u/UsAndRufus Sep 30 '21

Yeah it's not a true DSL really. But because of Ruby's blocks and parameterless functions, you can write it in a very declarative style. Unfortunately, I find that you really don't want a lot of code to be declarative. Rspec is a good example of it done well, though.

2

u/[deleted] Sep 30 '21

I find that the issue isn't declarative style, but the amount of hidden state that lurks beneath the layers of abstractions.

7

u/jrochkind Sep 30 '21

It's a good question, because what people call "DSL" in ruby really is just a Ruby API.

In other languages/contexts what you call a "DSL" might actually be something you write a PARSER for, and then parse in the "main" language, parse a thing that wasn't the main language at all.

That's what "DSL" sometimes means, but that's not how people use it in ruby. What we call "DSL"s are still... just ruby. If we're "extending" the language with a DSL, we're doing it simply by... definining classes and methods, the same way we write ruby when it's not a "DSL". It's not actually new syntax at all, everything in ruby DSLs is the usual ruby syntax parsed by the usual ruby interpreter in the usual way.

So what actually makes it a "DSL"? As I commented earlier, I think it is worth thinking about, and not straightforward. But basically I think people in ruby use the term when people define classes and methods to provide... more "unusual" API's, especially declarative ones.

4

u/bluexavi Sep 30 '21

Building a string and using #send, so that you can see a method but can't find anywhere in the code base where it is actually called.

10

u/flanger001 Sep 30 '21

Fuck ActiveAdmin and fuck the Inherited Resources from whence it came

23

u/flanger001 Sep 30 '21

RSpec is a jewel though and I will die on this hill

3

u/[deleted] Sep 30 '21

Inherited Resources can be good used wisely. Arbre though. Fuuuuck arbre

2

u/flanger001 Sep 30 '21

Inherited Resources solved a problem that no longer exists IMO. I absolutely hate it.

2

u/jrochkind Oct 01 '21

what problem was that?

2

u/flanger001 Oct 01 '21

The primary thing is that IR was made around the time that the "Fat Model Skinny Controller" thing was being worked out. IR attempts to solve this by doing everything in its power to make the controllers as skinny as possible, by design. Admittedly it doesn't do much for the models. FMSC is not really a design paradigm people are going for anymore in Rails, at least in my personal observations after about 8 years of developing in it.

5

u/ksh-code Sep 30 '21

If well-documented DSL, it is good like RoR.

but no documentation and complicated DSL are a disaster.

1

u/stanislavb Oct 04 '21

What's better than ActiveAdmin? I'm looking at you all hating ActiveAdmin :).

Seriously, I've also experienced some confusions with ActiveAdmin; however, I haven't found a better alternative ¯_(ツ)_/¯.

1

u/stanislavb Oct 04 '21

e.g. do you think that Administrate or RailsAdmin are better? https://www.libhunt.com/activeadmin/activeadmin

1

u/UsAndRufus Oct 04 '21

We have some Administrate in a different part of the app. I haven't used it much but it seems better. It's a lot less plug-and-play, but underneath it all it is just normal Rails controllers etc, that you can write and modify in the normal way. Rather than AA's weird model which is just Rails controllers, but they are difficult to access. A lot of people in the thread have been recommending Motor Admin, but I haven't used that so can't comment.

5

u/jasonswett Sep 30 '21

I think ActiveAdmin is bad but I think it's a mistake to conclude that DSLs are the reason ActiveAdmin is bad.

ActiveAdmin is hard to work with because of the way it's architected. They made it really easy to meet really common needs but really hard to add custom behavior. (At least this is the way I remember it. It's been many years since I've used ActiveAdmin.)

There are other places where I think DSLs work out great, including in Rails itself. I think people forget that a lot of Rails code is DSL code because Rails' DSL code is actually good.

2

u/ether_joe Oct 01 '21

I use Ruby and DSLs a lot and for me, it's fukin awesome.

2

u/paracycle Oct 01 '21

Haha, I gave a talk at this year's RubyKaigi about a month ago on DSLs: https://youtu.be/Ms7_PrryvMM

TL;DW: One of the primary problems of DSLs is that they make the cognitive barrier too high and end up looking like magic. Static analysis allows us to tease them apart a little bit.

2

u/omohockoj Oct 01 '21

You should try https://github.com/motor-admin/motor-admin-rails
This admin panel gem doesn't use DSL or configuration files and can be customized directly via the UI. More complex things like custom forms and actions can be added via regular rails API controllers.

2

u/postmodern Oct 02 '21

DSLs don't have to be horrible, just document them with YARD. Document the methods and what they take, yield, and return. Provide @example tags and put top-level examples for how to use classes/modules, and copy/paste the best examples into the README.

1

u/LePootPootJames Oct 01 '21

Probably the worst offender is rspec.

I love using rspec though.

1

u/LePootPootJames Oct 01 '21

People still use ActiveAdmin? Just build the back end and slap a React front end. Pretty sure by now there's some kind of React admin package out there.

3

u/[deleted] Oct 01 '21

Hmmm splashing React just for an admin sounds excessive actually. How is React better than Rails forms ? Its not like you need crazy reactivity in an admin... But I guess if your project is already using React (not all of them do!) Maybe its an ok tradeoff

1

u/LePootPootJames Oct 01 '21

I said in another comment if you need simple admin features, then AA is probably sufficient. It's when you need to customize things that you run into trouble. A little bit of customization here and there and before you know it, you're pouring over AA's source code.