Open jayunit100 opened 3 years ago
In general, the ability to write guard clauses can make it easier to reason over a function (lowercase 'f'). 👍🏻 It's effectively a kind of precondition which alleviates the reader from being concerned about that condition for the rest of the execution.
Turning towards implementation concerns...
More context:
return
is only allowed within a functioncontinue
and break
are only allowed within a loopOptions:
stop
or interrupt
@ytt:assert
module?!Concerns:
return is only allowed within a function
that's still one of the options. we can rewrite ast to support return at top level. question is it a good idea?
I'm on the fence, ATM.
On the one hand — as I noted above — guard clauses can made a larger script much more easier to reason about.
On the other hand, this mechanism can be used to terminate execution anywhere in the script. Imagine there's a return
in the middle of the example Jay gave... ugh.
im also on the conservative side for such change, since it may come with its own set of sharp edges.
possible workaround, from conv w dimitry, using a
.lib.yaml
.... Describe the problem/challenge you haveRight now, we have to sometimes nest 1000s of lines of yaml in a
block, which can be hard to reason about (i.e. what is this
#@end
referring to?)...https://github.com/vmware-tanzu/tanzu-framework/blob/main/pkg/v1/providers/infrastructure-vsphere/v0.7.10/ytt/overlay.yaml
Describe the solution you'd like
Something like
so that we can short circuit (or not) the processing of a file in some way.