https://kotlinlang.org logo
#spring
Title
h

Hullaballoonatic

11/07/2019, 6:55 PM
I feel like if spring was written using kotlin originally, it would just use objects a lot instead of injection, but that's because i'm under the impression that beans are just singletons
s

Shawn A

11/07/2019, 7:00 PM
Injection is fine and kotlin allows you to do it declaratively without a proxies, annotations processors or byte code manipulation.
f

fred.deschenes

11/07/2019, 7:14 PM
Plus you can let users modify/extend the injected stuff, whereas objects are final
x

xenoterracide

11/07/2019, 7:32 PM
objects aren’t final by default… actually making them final by default (which kotlin does) is a violation of SOLID (the O for open/closed (open for extension, closed for modificaton) and extension methods violate the closed for modification.
also you can do injection just fine in spring without proxies, or byte code manipulation, or annotation processors
sure you need some of that for super advanced features… but you would need them in kotlin too
like transaction handling
there’s no way to add that code around your code without doing one of the above
s

Shawn A

11/07/2019, 8:08 PM
Most of the AOP features in spring are doing that sort of thing. You can use other approaches like delegation or wrapping code in lambdas and kotlin supports that nicely.
x

xenoterracide

11/07/2019, 8:10 PM
proxies are basically delegation/wrapping 😉
s

Shawn A

11/07/2019, 8:13 PM
agree with you there.
q

Quy D X Nguyen

11/07/2019, 8:48 PM
Extension methods violate SOLID no more than static methods or functions as some languages call them.
x

xenoterracide

11/07/2019, 9:22 PM
eh, that’s a bit like arguing that since it’s all machine code in the end… imho, or whether or not
myMethod( foo: Foo )
and
myMethod( bar: Bar)
represents a form of polymorphism (the latter is considered polymorphic), I would use the latter to argue that since in the language it “looks” like you’re calling the same method, that if in kotlin it looks like you’re calling a method on object, but that method doesn’t really exist on object, then you’ve essentially modified the object and/or changed its behavior, it doesn’t matter that it doesn’t compile to that. but that’s, like, just my opinion, man
q

Quy D X Nguyen

11/07/2019, 11:24 PM
I mean extension methods don't give you anything normal methods don't. You may be mistaking these for c++ friend functions which can access internals.
4 Views