Alias Return to ProcedureReturn in procedures
Posted: Tue Sep 12, 2023 6:46 pm
This may be very contentious, so please feel free to disagree! (or voice your agreement
)
Proposal
When used in the context of a procedure, have keyword Return act as ProcedureReturn rather than being simply an error.
This would make the two pieces of code below equivalent to each other:
The original ProcedureReturn keyword would continue to function as it does currently.
Should this change be introduced, I'd hope Return eventually becomes the popular style over ProcedureReturn, so more code favours conciseness as time goes on. Again, the existing style would continue to function.
Motivation
There are few reasons I believe this would be a good addition:
Downsides
)
Risks
There should be no risks aside from downsides listed above.
Return is already unsupported in procedures at present, so existing code should not break. ProcedureReturn would be retained into the distant future (forever?) for backwards-compatibility (but eventually be hidden from autocomplete so as to favour simplification).
If, in the distant future, ProcedureReturn were to ever be removed, it would be an extremely simple find-replace refactor. Removal of ProcedureReturn at any future point would however break all current procedure-oriented code involving return values (which is to say: loads). I understand if this is reason enough to reject the proposal, as having both ProcedureReturn and Return equivalent eternally may be an undesirable commitment.
The issue of redundant keywords is a very valid criticism. That said, this proposal is made with the hope that benefits are seen to outweigh the cost, where eventually the majority of PB procedure returns follow the simple form (and so legacy details become unimportant in all but niche cases).
Thanks
Thank you for reading/considering this!
I appreciate any feedback, be it negative or positive, so long as it's vaguely civil.
I understand that this is quite the ask, so no feelings of mine will be hurt if it's rejected.

Proposal
When used in the context of a procedure, have keyword Return act as ProcedureReturn rather than being simply an error.
This would make the two pieces of code below equivalent to each other:
Code: Select all
Procedure Add(x, y)
Return x + y
EndProcedure
Code: Select all
Procedure Add(x, y)
ProcedureReturn x + y
EndProcedure
Should this change be introduced, I'd hope Return eventually becomes the popular style over ProcedureReturn, so more code favours conciseness as time goes on. Again, the existing style would continue to function.
Motivation
There are few reasons I believe this would be a good addition:
- Familiarity.
- The majority of programming languages have a simple, short "return" keyword. I don't mean to say "all the other cool kids are doing it, so PB should too!" but I feel there's definitely merit in making the language more approachable when coming from or used together with other languages.
- See an example of Return and ProcedureReturn being conflated in a recent issue report here on the forums. I don't believe this is an isolated incident (and can say for sure I've made this mistake on occasion, especially when going back and forth late-night between PB and JS/C). This prompted a compiler change to now warn when Return is used inside procedures.
- Ergonomics.
- Please hear me out on this. It seems silly, but gotta go fast.
- Having "ProcedureReturn" typed out requires at least 9 key presses in the typical PB IDE:
- 4 letters "proc" to have autocomplete narrowed to:
- Procedure
- ProcedureC
- ProcedureCDLL
- ProcedureDLL
- ProcedureReturn
- 4 down-arrow key presses to reach "ProcedureReturn" in the autocomplete list
- 1 tab key press to accept the autocomplete suggestion
- 4 letters "proc" to have autocomplete narrowed to:
- Having "Return" typed out takes at least 4 key presses and at most 6 in the typical PB IDE:
- 3 letters "ret" to have autocomplete show only "Return"
- 1 tab key press to accept the autocomplete suggestion
- Cutting typing (and reading) of this operation in half feels slicker, even through it's a relatively minimal part of each procedure. For small procedures, it has them feel much less verbose.
- Side note: the input time inefficiency can alternatively be improved by just hiding "Procedure(C)(DLL)" options when showing autocomplete within a procedure, since they can't be nested.
- Consistency.
- Break may be used for control flow in loops without naming the loop type (i.e., no need for ForBreak / BreakFor, WhileBreak / BreakWhile, etc.).
- Continue follows the same rule as Break above.
- Procedures are syntax sugar for subroutines, and both may Return to a caller. Similarly, a For loop is syntax sugar for While value <= limit : do_inner_stuff : value + step : Wend, and both may Continue / Break.
Downsides
- Semantics and usage of Return will vary slightly depending on the context, notably with subroutines not being able to carry a value through it. (Although, subroutines are already lower-level to the point they've no return value syntax, hence we generally use procedures to ease our lives)
- Inconsistency. Multiple ways of doing the same basic operation. Risk of style wars.
- Are you team Return or ProcedureReturn? Or maybe... you use both in your codebase?
- This will always exist to some extent in programming, as few languages totally dictate convention. Some examples:
- Casing: Pascal vs. camel vs. snake vs. etc.
- Variable declarations, these all have the same general effect (and identical ASM generated):
- Define.s name = "Zippy Retton"
- Define name.s = "Zippy Retton"
- Define name$ = "Zippy Retton"
- name.s = "Zippy Retton"
- Implicit/explicit for..next:
- ForEach users() : Next
- ForEach users() : Next users()
- Explicit gadget ID-ing vs. #PB_Any.

Risks
There should be no risks aside from downsides listed above.
Return is already unsupported in procedures at present, so existing code should not break. ProcedureReturn would be retained into the distant future (forever?) for backwards-compatibility (but eventually be hidden from autocomplete so as to favour simplification).
If, in the distant future, ProcedureReturn were to ever be removed, it would be an extremely simple find-replace refactor. Removal of ProcedureReturn at any future point would however break all current procedure-oriented code involving return values (which is to say: loads). I understand if this is reason enough to reject the proposal, as having both ProcedureReturn and Return equivalent eternally may be an undesirable commitment.
The issue of redundant keywords is a very valid criticism. That said, this proposal is made with the hope that benefits are seen to outweigh the cost, where eventually the majority of PB procedure returns follow the simple form (and so legacy details become unimportant in all but niche cases).
Thanks
Thank you for reading/considering this!
I appreciate any feedback, be it negative or positive, so long as it's vaguely civil.
I understand that this is quite the ask, so no feelings of mine will be hurt if it's rejected.