Switch..Case & Compiler Switch

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Switch..Case & Compiler Switch

Post by Sheeva700 »

Hi,

May i propose 2 additionals features for next version of Hollywood.

First Switch..Case :
actually Switch..Case Work Like This:

Code: Select all

Switch x
 Case 1:
     y = 1
 case 2:
     y = 1
 Case 3:
    y = 2
endswitch
In this example, in cases 1 & 2 y become 1

i propose this compiler interpretation :

Code: Select all

Switch x
 Case 1:
 case 2:
     y = 1
 Case 3:
    y = 2
endswitch
Second:
--NoDebug switch to Hollywood compiler who will bypass all debugprint() keyword in the script at compile time. :P

Thanks.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: Switch..Case & Compiler Switch

Post by Bugala »

that second idea is a good one. You could leave all the debugprints in place and use them only as needed.
I have currently made myself a Debug function which handles that, where first line is:
if debugprinting = false then return


What comes to your first suggestion, it would rather suggest possiblity of using something like:

Code: Select all

switch
case 1 or case 2
x=1
case 3
x=2
endswitch
problem with your suggested:

Code: Select all

case1:
case2:
x=1
case3:
x=2
is both in readability and also in case you wish some case not to do nothing, you might still want it to be listed in code so you can see that this case is not just forgotten, but because it is not doing anything, as example:

Code: Select all

case1:
/*do nothing*/
case 2:
x=1
case 3:
x=2
in case like this comment would be ignored and case 1 and 2 would both become x in your example.

Another porssibility would be to be able to control how switch works.

For sometimes it is useful if case jumps from one case to other, as example:

Code: Select all

case1:
a=a+1
case2:
a=a+1
case3:
a=a+1
At start a = 0

if case is 1, a would become 3 since it goes through all the cases.
If case is 3, then a would become 1, since it would only do case three, not the previous ones.

And then there would also be needed additional command to stop the flow:

Code: Select all

case 1:
a=a+1
case 2:
a=a+1
end case
case 3:
a=a+1
in this case, case 1 would make a become 2, as only case 1 and 2 would be executed.
Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Re: Switch..Case & Compiler Switch

Post by Sheeva700 »

Hi Bugala,

What you are sugesting is the same behavior of what i sugest but, I don't like so much the Or keyword in a switch..case (confusing)
other proposition with endcase is even more confusing.

if first case is empty then we have a sort of implicit Or and btw if you don't want to test first case just not add it . 8-)
can be very powerfull. (and already used in other language)

Of course is just a sugestion.
What comes to your first suggestion, it would rather suggest possiblity of using something like:

Code: Select all

switch
case 1 or case 2
x=1
case 3
x=2
endswitch
The Compiler switch -nodebug must be added. it's a fact ! :D
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Switch..Case & Compiler Switch

Post by airsoftsoftwair »

I agree, NODEBUG is a good idea and I will implement it.

The other idea cannot be implemented in the way suggested by Sheeva700 because this would break old scripts. The only possible compatible way of implementing something like this would be a new "FallThrough" keyword, e.g.

Code: Select all

Switch x
 Case 1:
     FallThrough
 Case 2:
     y = 1
 Case 3:
     y = 2
EndSwitch
But this is quite some work since it requires VM modifications which need to be done really carefully so don't count on this becoming a reality any time soon.
Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Re: Switch..Case & Compiler Switch

Post by Sheeva700 »

Hi,

Thanks for -NODEBUG ;)

I understand your concern regarding backward compatibilty. (very coherent) 8-)
FallThrough is an idea.

regarding old script, Who is doing that seriously ?

Code: Select all

Switch x
   Case 1:
      y = 1
   Case 2:
     y = 1
endswitch
On my point of view, the Old scripts can be quickly updated or even not modified.

PS: i place this post in wrong section (shame). can you move this ?

Dominique.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Switch..Case & Compiler Switch

Post by airsoftsoftwair »

Topic moved.
zylesea
Posts: 227
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: Switch..Case & Compiler Switch

Post by zylesea »

airsoftsoftwair wrote:I agree, NODEBUG is a good idea and I will implement it.
While I also think a nodebug is a good idea why not use simple ifs for that now:

Code: Select all

my_debug$=true
(...)
if my_debug$=true then debugprint ("bla bla bla")
(...)
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Switch..Case & Compiler Switch

Post by airsoftsoftwair »

That's very ugly if you have many debug statements but of course one could encapsulate it in a dedicated function. But NODEBUG will come because it's also meaningful for other commands.

Code: Select all

- New: Added NODEBUG console argument; if this argument is specified, the commands DebugPrint(),
  DebugPrintNR(), Assert(), DebugOutput(), and @WARNING will be ignored; this allows you to globally
  disable debugging functions with just a single call
Post Reply