3 ms·
> The infix is weird and footgun-y. If it's a foot gun, then I'm not seeing how the gun is loaded? > Extension methods on int/double serving as constructors s
by Clamchop 2y ago
> The infix is weird and footgun-y.
If it's a foot gun, then I'm not seeing how the gun is loaded?
> Extension methods on int/double serving as constructors smells funny.
It doesn't feel meaningfully different from the static factory pattern in traditional Java, where 10.percent() would be something like MoneyUtils.createPercent() or Percent.create() with several overloads. Under the hood, that is essentially what is happening. Only downside I can see is that it muddies what truly belongs to the class, but that's true of any extension function and Kotlin is intended to be used with IDEA's introspection anyway.
The Kotlin standard library has lots of extension functions that construct new objects.
It also reminds me of Ruby, which perhaps you're also not a fan of and that's OK.