Hi, I d like to ask what is in your eyes the bigge...
# gradle
k
Hi, I d like to ask what is in your eyes the biggest benefit of using the delegated properties in the kotlin DSL, like:
Copy code
val myTask by tasks.getting
vs
val myTask = tasks.getByName("myTask")
or
Copy code
val myProp: String by project
vs
val myProp = project.property("myProp")
v
Besides that the last line is not valid and should probably be
val myProp = project.property("myProp")
? You don't have to duplicate the name and you get type safety for example for
myProp
which is
String
in the first case and
Any?
in the second
k
Sure, correcting that mistake, I've just typed it by hand now. well, you have to repeat the name in the second case once you want to pass it or assign it somewhere etc.
Copy code
someFn(project.property("myProp") as String)
vs
val myProp: String by project
someFn(myProp)
v
If you don't need it multiple times but only this one time, it is probably mainly a question of personal taste
e
Also, not having the name encoded in a string allows to use IDE refactorings if you want to rename it
👍 4
k
This is actually good point
v
Which is void if you only use it in one place as you then don't need a refactoring, just an edit. 😄
k
That is right 🙂 but still if you read for instance an evironment var or project property and you decide to rename it, it is maybe a little bit smaller chance that you miss it if it is an identifier versus when it is a string literal if you do some search.. but yeh, you are right
v
possible