Discuss Scratch

blablablahello
Scratcher
1000+ posts

Case statements

Basically the case statements in like java,, where the cases follow a specific order, such as a b c d, 1 2 3 4, or something of similar status. Basically, it saves computing power, all the while makes it simpler to code.
I am unsure how this could be implemented, however, how this could be coded should be able to be done by having a list of functions, and you find the (number)th function from the list. or if its a b c d, then you find the (number converted from letters, such as a=1)th function from the list. This way, instead of having to do if else statements and check through each statement, the code would be capable of cecking only the specific list index, which could then be used to access a function. (coulde just be a “case (number)” block, which adds on to the case list)

Only downside would be it being confusing to newer users, however, lists, custom blocks, and many other things are also very confusing, so I dont think this would be that much worse.

I guess it would be confusing to implement tho
RL1123
Scratcher
1000+ posts

Case statements

Seems like a cool idea, but for now, using if-else conditions repeatedly seems to get the trick done just fine. A few extra if-else blocks shouldn't use much computing power that the effects should become noticeable. Also, Scratch is a language for younger programmers, so I think the case block may not be easily used as the if-else condition.
blablablahello
Scratcher
1000+ posts

Case statements

I do agree, however, this feature solves 2 problems, as I have seen people complaining about extended if else and ifelse statements, and this would also fix the problem of code being extremely messy with tens of if else statements looped together, making it especially hard to read of newer programmers as you would have to take extra time to figure out which else this if statement leads to, especially with the new, cleaner block design (which makes it harder to see the differentiating line between 2 blocks)
mybearworld
Scratcher
1000+ posts

Case statements

I never really understood the point of case statements…

What does this have:

(Pseudo code)
caseStatement a {
case 1 { function1() }
case 2 { function2() }
case 3 { function3() }
case 4 { function4() }
]
case statement (a) {
case 1 {
function 1 :: custom
} :: control
case 2 {
function 2 :: custom
} :: control
case 3 {
function 3 :: custom
} :: control
case 4 {
function 4 :: custom
} :: control
} :: control

What this doesn't:
if ( a == 1 ) { function1() }
elif ( a == 2 ) { function2() }
elif ( a == 3 ) { function3() }
elif ( a == 4 ) { function4() }
if <(a) = (1)> then
function 1 :: custom
else
if <(a) = (2)> then
function 2 :: custom
else
if <(a) = (3)> then
function 3 :: custom
else
if <(a) = (4)> then
function 4 :: custom
end
end
end
end
blablablahello
Scratcher
1000+ posts

Case statements

mybearworld wrote:

I never really understood the point of case statements…

What does this have:

(Pseudo code)
caseStatement a {
case 1 { function1() }
case 2 { function2() }
case 3 { function3() }
case 4 { function4() }
]
case statement (a) {
case 1 {
function 1 :: custom
} :: control
case 2 {
function 2 :: custom
} :: control
case 3 {
function 3 :: custom
} :: control
case 4 {
function 4 :: custom
} :: control
} :: control

What this doesn't:
if ( a == 1 ) { function1() }
elif ( a == 2 ) { function2() }
elif ( a == 3 ) { function3() }
elif ( a == 4 ) { function4() }
if <(a) = (1)> then
function 1 :: custom
else
if <(a) = (2)> then
function 2 :: custom
else
if <(a) = (3)> then
function 3 :: custom
else
if <(a) = (4)> then
function 4 :: custom
end
end
end
end
The point is that case statements are 1. cleaner, and 2. takes way less computing power, however they cannot be used in some cases.
In normal programming, people tend to use case statements to make their project cleaner and take less computing power, and thats with normal programming, which already has a lot of computing power and is way more clean then scratch. This would also make scratch projects cleaner, and depending on the amount of if-else you have, way less laggy.
for example, this would help in a situation like this:
if <(a) = [1]> then 
something


else
if <(a) = [2]> then
something


else
if <(a) = 3]> then
something


else
if <(a) = [4]> then
something


else
if <(a) = [5]> then
something


else
if <(a) = [6]> then
something


else
if <(a) = [7]> then
something


else
if <(a) = [8]> then
something


else
if <(a) = [9]> then
something


else
if <(a) = [10]> then
something


else

end
end
end
end
end
end
end
end
end
end
and those big long code pieces are very common in bigger projects
mybearworld
Scratcher
1000+ posts

Case statements

Scratch doesn't work like that though. That wouldn't make it faster.
Basically, what you're suggesting is a faster elif block… wouldn't that be a duplicate
blablablahello
Scratcher
1000+ posts

Case statements

mybearworld wrote:

Scratch doesn't work like that though. That wouldn't make it faster.
Basically, what you're suggesting is a faster elif block… wouldn't that be a duplicate
hmm, I guess
Harakou
Scratcher
1000+ posts

Case statements

mybearworld wrote:

Scratch doesn't work like that though. That wouldn't make it faster.
Basically, what you're suggesting is a faster elif block… wouldn't that be a duplicate
Case and elif are pretty similar, but not really the same IMO. While it's true that Scratch probably wouldn't make use of the potential performance improvements from a case switch, I can see why someone might prefer one over the other. Personally I think it's much more likely that we'd add an elif-type block, so I do think supporters of this should probably look there for discussion unless they have a specific reason to prefer case, but I'm not sure it's a duplicate.

Powered by DjangoBB