Summary
The language only offers an if
statement which often times not enough and still can lead to pyramids of doom (nested if
statements). In non-decides
context there can be times where one wants to extract an value through optional unwrapping or via a decides call and in case of absence of a result value return from the entire function.
some_class := class {
var SomeProperty: ?some_type = false
SomeMethod(): some_return_type = {
# guarded property
GSomeProperty := if (USomeProperty := SomeProperty?) {
USomeProperty
} else {
return SomeReturnTypeFallback
}
...
}
}
This if
statement dance is very inconvenient and requires multiple similarly named properties just to obtain a value into the current context or exit from it.
Sometimes there’s an alternative way by defaulting to a value, but it’s not always an option: GSomeProperty := SomeProperty? or SomeDefaultValue
.
A proper guard
statement would be much more pleasant to use.
# pseudocode
SomeMethod(): some_return_type = {
# guarded property
guard GSomeProperty := SomeProperty? else {
return SomeReturnTypeFallback
}
# use `GSomeProperty` here
...
}
The showcased if
statement dance is very common in my own code base, especially where I need to perform typed error handling for example.
Please select what you are reporting on:
Verse
What Type of Bug are you experiencing?
Other
Steps to Reproduce
N/A
Expected Result
N/A
Observed Result
The language feature does not exist yet.
Platform(s)
UEFN