I'd really love to have `return` in `init`
# language-proposals
e
I'd really love to have
return
in
init
l
Use case?
e
relative big
init
for an helloOpenVR app
l
Also, what about properties declared below, and other init blocks? Better do an if
Or call methods from your init block
e
uhm, yeah, also
the calls from the block doesnt play nice with `val`s expecting to be set
l
Organizing your code is important.
You can assign `val`s from something computed in a method
even in init block as long as you don't call something initialized after it's supposed to run
e
last time I checked, I couldnt
I'll check again, thanks
b
return null
would be nice for failable convenience initializers
2
a
if you are doing alot of initializiation inside
init
, you should think about putting this code into a factory method
b
@Andreas Sinz I don't see why. To me, the syntax is less clear; not all initializers are called the same way and the caller isn't guaranteed a clear reason why. If a future version of the library is updated such that the factory method doesn't do "a lot of initialization", should it be removed in favor of a common constructor? When is the amount is initialization "a lot", causing it to be moved to a factory method? Etc
e
@Andreas Sinz the nice thing about
init
is
val
values
a
@elect can you give me an example where you have to use a
var
because you are using a factory method?
e
uhm, I'd need to think about
maybe you are right
a
i'm just genuinely asking, I've never come across an instance where a factory method forced me to have a
var
instead of a
val
e
I'll keep it in mind if I will ever cross it
👍 1
because at the moment I cant afford to dedicate time to that
a
@benleggiero if you do the initialization of properties inside the class you are violating the Single Responsibility Principle. I usually don't use
init { }
at all, only when its necessary because of some library/framework I'm using
b
@Andreas Sinz same here. I just don't want to compromise my API because the library I'm using has, for instance, a constructor that throws an exception like URL