[Suggestion] Returning stops function

Discussion and feedback on Construct 2

Post » Sun Aug 11, 2013 10:18 pm

In all programming languages to my knowledge, a return statement stops the function and returns the value to the caller.

In Construct 2, setting a return value does not stop the function. If this was intended behavior, arguing that it makes more sense to beginners, then offer an option in an action like "Stop Function" or something.

I feel like I have to vouch for all programming languages trying to explain why this is beneficial. For brevity, it allows for [at times far] more optimized code and it prevents tricky logic situations that would otherwise muddle code with needless variables and events.
B
11
S
2
Posts: 54
Reputation: 805

Post » Sun Aug 11, 2013 11:46 pm

I agree with this.

@Ashley
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

Post » Mon Aug 12, 2013 7:46 am

Just for reference, there are actually quite a few programming languages which allow multiple return points.

Different languages have different idioms, and it really depends on the language and programmers involved whether or not multiple return points are considered a good idea.
B
32
S
8
G
2
Posts: 110
Reputation: 3,648

Post » Mon Aug 12, 2013 5:37 pm

@jbadams I've never encountered a language that continued executing statements beyond a return statement. Can you provide an example?
B
17
S
6
G
6
Posts: 113
Reputation: 4,161

Post » Mon Aug 12, 2013 5:48 pm

@Trevor10 @jbadams
I think jbadams is just misunderstanding the OP.

Yes, every programming language (to my knowledge) allows multiple "return points", heck there wouldn't be much of a reason for one to execute "early" if that weren't the case.

However, no programming language continues executing statements within a function past the return statement (but Construct 2 does, *ahem...).
B
11
S
2
Posts: 54
Reputation: 805

Post » Mon Aug 12, 2013 6:46 pm

Pascal has no return. It becomes an issue of design if you don't have a return statement. Though a return would be handy.
B
12
S
3
G
4
Posts: 57
Reputation: 3,186

Post » Tue Aug 13, 2013 3:15 am

@CannedEssence:

Ah yes, I see what you mean now! Hadn't actually tried to use multiple returns in Construct 2 (I consider it a bit messy in the majority of cases) and realised that execution continues after a return.

Plenty of programming languages allow you to have multiple return points from functions, but you're correct that it would be extremely unusual -- i.e. I can't think of any examples -- where this doesn't also jump back out of the function.

Apologies for the misunderstanding!
B
32
S
8
G
2
Posts: 110
Reputation: 3,648


Return to Construct 2 General

Who is online

Users browsing this forum: Domino3057 and 16 guests