Comment by happytoexplain
2 days ago
>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!
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).
Here is the neat part about Ruby, your autocomplete barely works and your IDE can only guess what you want, instead of relying on a good language service…
I haven't used autocomplete in over 20 years. Why does this even need an autocomplete? The "API" is dead simple.
Why write in this dismissive tone? Regardless of your personal situation, it would be hard to believe you don't share the common knowledge that virtually everybody uses auto-complete to some degree, e.g. to remember, discover, or abbreviate type/instance methods, argument lists, etc. And why is "API" in quotes? It's very normal to refer to interfaces in languages/platforms as APIs (e.g. "JavaScript's Date API").
Regardless, whether or not a person uses autocomplete for this API is irrelevant - in this case it would be anybody using numbers for things outside this API, and maximally it would be the whole platform if this design pattern is not unique to this API. I.e. the simplicity of this one API has no bearing on the question.
> That API design pattern would be a nightmare!
And yet people have been using it for decades without much trouble. I can't remember ever seeing any complaints about API explosion from adding methods to numbers in ruby, and rails does a fair bit of it.
Possibly one reason is with a fluent API that's pretty understandable, you don't need to rely on autocomplete. (And indeed, all this happened before that was a big thing in tooling.)