(no title)
oleksandr_dem | 7 months ago
> I don't get this part. What special characters?
For example let's look at this code:
```
class ProductsController < ApplicationController before_action :set_product, only: %i[ show edit update destroy ]
def index
@products = Product.all
end
...```
You can see a bunch of special characters: < : , % [] @
For example, if I wanted to write the same code in Typescript, based on my setup I might just need do something like this:
```
instance.get("/products", () => ProductsRepository.find());
```
Where instance is my router instance (fastify, express, whatever) and ProductsRepository is a TypeORM repository. My before_action might just be a middleware I pass to the callbacks chain or register as global middleware
Lio|7 months ago
You don't say what set_product should do but with any Rack application like Roda or Rails you can also set middleware as you suggest for Express.
With regard for special characters vs reserved keywords, that seems to be mostly about personal preference and familiarity.
e.g. I know that in a class declarion in Ruby < means the same thing as extends in JavaScript. I don't really notice the difference day to day.
Same for @products vs this.products. This doesn't seem like a conceptually big differnce to me.
As for %i[] to define an array of symbols, the typescript equivalent would be:
Personally I always use [:show, :edit, :update, :destroy], it's more obvious IMHO. I use Rubocop to autoconvert that in any code I inherit.What makes me love Rails is all the little trivial methods like one to quickly format arrays into gramatically correct sentences. Or the Array() wrap method when dealing with APIs.
Or the way Rails handles dates and times like 1.business_day.from_now
Or any number of other little utilities that are easy enough to write yourself but add friction when they're missing.
Rails gives me a well supported fullstack of what I need and I know that it and Ruby are constanly improving because its backed by some massive companies.
I don't think there's any need for you to adopt it though. That podcast is just about why DHH loves Ruby and Rails that doesn't invalidate what you're already happy with.
There is more than one way to do things.