Remix.run Logo
irjustin 3 hours ago

Late to the party, I really wish everyone would copy Rails + Ruby, but specifically it's Rails additions.

2 things it got right:

1. Like the article a great API - Time.current.in_time_zone('America/Los_Angeles') + 3.days - 4.months + 1.hour

2. Rails overloads Ruby's core library Time. You're in 1 object the whole time no swap/wondering.

In the py world, pendulum is close but just like the article, it's cumbersome as it's still a separate obj (i.e. Temporal vs Date) and so you need to "figure out" what you have to manipulate or need to cast it first.

Overloading the core libs is dangerous for a whole host of reasons but for the end developer it's a pleasure to use.

If we could just do `new Date().add({ days: 1})` it would be so easier.

happytoexplain 2 hours ago | parent | next [-]

>3.days - 4.months + 1.hour

Is this what it looks like? A specific concept like time units being defined as members of more general types like numbers? I.e. if I type `1.` to get auto-complete, am I going to see days, and all the rest, as options?? That API design pattern would be a nightmare!

greiskul 41 minutes ago | parent [-]

In Ruby, I assume this is done by monkey patching, so yes, it would have all the issues you mention and fear.

In more modern languages like Kotlin, there is a notion of extension methods and properties, where you would be able to write a library that allows this syntax, but the .days property would only be accessible in files where you have explicitly imported it (so basically a synthetic sugar for a static function call).

publicdebates 3 hours ago | parent | prev [-]

> 3.days - 4.months + 1.hour

How is that a good thing?

> Rails overloads Ruby's core library Time. You're in 1 object the whole time regardless of what you do.

How is that a good thing?

shermantanktop 2 hours ago | parent [-]

When what you have is a pickaxe, everything looks like a rail...