Started by
Nwago
on
Topic category: Feature requests and ideas for MCreator
return; is extremely useful for making procedure code more readable and run better in the blockly editor (avoid huge if nesting), and from experience works flawlessly using it in custom code format, but having it built in would save a bit of time and encourage more people to use it!
+1 I made a plugin partly because this wasn't a block yet
Premature returns break code flow and are generally advised not to be used
Guard clauses are bad?
We avoid early returns. They are similar practices to goto
Wdym? MCreator's own generated code uses them,
How's it like goto?
It breaks the code flow. We try to avoid them, especially if deely nested, as one can quickly miss them. Here (your screenshot) is an early check, where it is ok.
But we could add it, however, it is very hard to validate edge cases where it could cause build errors. Even current return value blocks can cause build errors in some cases and we currently don't have reliable validation for those cases invented yet
Guard clauses themselves not, but returning in e.g. nested code is bad as it is hard to read.
Oh, I have never used deeply nested guard clauses so I didn't even think of that possibility. I always just use them like MCreator does there.
You could always just put the return block in the advanced tab.
Bit of a bandaid, but you could add a little warning at the bottom of the page (similar to the nbt one) saying that MCreator isn't able to fully validate these blocks and to use them only if you know what you are doing