|
 |
|

November 6th, 2009, 06:26 PM
|
 |
.
|
|
Join Date: May 2009
Posts: 1,311
|
|
|
Adding switch(){} statement to jasshelper (good/bad idea)?
I had the idea, while doing c++, to suggest adding the switch statement to jasshelper. (For those who don't know what the switch statement is: Switch statement)
Exemple
Jass:
function Test takes nothing returns nothing
local integer value=15
switch(value)
case 5 {
call DoSomething(5)
break
}
case 10 {
call DoSomething(10)
break
}
case 15 {
call DoSomething(15)
break
}
default {
call DoNothing()
break
}
endswitch
endfunction
Good idea? Opinions please  .
|

November 6th, 2009, 06:32 PM
|
|
Veteran Member (Done that)
|
|
Join Date: Oct 2009
Posts: 466
|
|
Well, your example looks like it could be rewritten to:
Jass:
function Test takes nothing returns nothing
local integer value=15
if (value != 0)
call DoSomething(value)
endif
endfunction
But if it is what I think it is, then it's goodies 
But it can already be made with if statements?
|

November 6th, 2009, 06:36 PM
|
 |
Junior Regular (Got the T-shirt)
|
|
Join Date: Aug 2006
Posts: 560
|
|
|
If statements yes, but this is more organized. I like it. Plus shorter to write if you have many conditions you avoid long statements ... or or or and or or and and or....
|

November 6th, 2009, 06:38 PM
|
 |
.
|
|
Join Date: May 2009
Posts: 1,311
|
|
|
Basicly, it would be rewriten with if statements but the main idea is that it's shorter to write and looks neater, Imo..
|

November 6th, 2009, 07:06 PM
|
 |
Visitor (Welcome to the Jungle, Baby!)
|
|
Join Date: Feb 2009
Posts: 2,775
|
|
|
Suggest to cJass, it uses c style. vJass is fine, if you want to use shortcut, use Zinc.
|

November 6th, 2009, 07:43 PM
|
|
Hai.
|
|
Join Date: May 2009
Posts: 1,882
|
|
|
Switch could be useful.
|

November 6th, 2009, 08:55 PM
|
 |
.
|
|
Join Date: May 2009
Posts: 1,311
|
|
|
|

November 7th, 2009, 12:38 AM
|
 |
blog -- http://syncjournal.blogspot.com
|
|
Join Date: Feb 2007
Location: www.jump08.co.nr
Posts: 1,399
|
|
|
switch is useful.. I mostly use it if I have a lot of if statements..
|

November 7th, 2009, 01:32 AM
|
|
Hai.
|
|
Join Date: May 2009
Posts: 1,882
|
|
|
Yeah.
I'd remove the endswitch keyword though.
|

November 7th, 2009, 05:22 AM
|
|
Good Idea™
|
|
Join Date: Jul 2007
Location: Australia
Posts: 3,857
|
|
It is all crap. It is more efficient (and perhaps even readable) if you have enough cases to do:
Jass:
function Test takes nothing returns nothing
local integer value=15
call MySwitchCases[value].evaluate()
endfunction
And fill "MySwitchCases" with function pointers on init.
Heck, you can make MySwitchCases a trigger array directly and add triggers with conditions and just do call TriggerEvaluate(MySwitchCases[value]).
(Switch is just an O(n) complexity way of doing this, so to speak.)
|

November 7th, 2009, 03:44 PM
|
 |
o-o
|
|
Join Date: Aug 2006
Posts: 1,223
|
|
In JASS, it really wouldn't matter whether you were using a switch statement or a set of ifs. In compiled programming, the switch statement immediately goes to the set case. In compiled programming, switch statements are faster than ifs -.-, but this isn't compiled programming is it? It's interpretive, so it really doesn't matter which way or the other  .
Jesus4Lyf's a good idea for maintainability and for speed if you end up having a million else ifs.
I don't believe a switch statement would merit any benefit whatsoever to the JASS language ;D.
|

November 7th, 2009, 03:58 PM
|
 |
Junior Regular (Got the T-shirt)
|
|
Join Date: Aug 2006
Posts: 560
|
|
|
It's user friendly. To me, anyway.
|

November 7th, 2009, 05:23 PM
|
 |
I'd love to elaborate about discussions...........
|
|
Join Date: Sep 2006
Location: Amsterdam
Posts: 650
|
|
This would not be really possible in Jass, because if 1 case returns true it should execute every case below as well.
Meaning this can only be done with a lot of preset booleans for a case.
So your example should be converted to this:
Jass:
function Test takes nothing returns nothing
local integer value=15
local boolean a = false
local boolean b = false
local boolean break = false
if( value == 5 ) then
set a = true
set break = true
call DoSomething(value)
elseif (value == 10) or ((break == false) and (a == true)) then
set b = true
set break = true
call DoSomething(value)
elseif (value == 15) or ((break == false) and (b == true)) then
call DoSomething(value)
elseif (true) and ( (break == false) and (a == false) and (b == false)) then
call DoNothing()
endif
endfunction
Perhaps this code is not fully accurate in the way switch really works but you should get the idea. This causes a lot of technical difficulties and a lot of more compute time as well.
If-then-else works good, if you don't like the syntax use zinc, otherwise don't complain.
Last edited by Xorifelse; November 7th, 2009 at 05:29 PM.
|

November 7th, 2009, 05:33 PM
|
 |
Follow me down, to the valley below...
|
|
Join Date: Jan 2008
Location: Norway.
Posts: 1,108
|
|
|
I really don't see what the point of this is.
|

November 7th, 2009, 05:39 PM
|
 |
o-o
|
|
Join Date: Aug 2006
Posts: 1,223
|
|
You and me both
Quote:
In JASS, it really wouldn't matter whether you were using a switch statement or a set of ifs. In compiled programming, the switch statement immediately goes to the set case. In compiled programming, switch statements are faster than ifs -.-, but this isn't compiled programming is it? It's interpretive, so it really doesn't matter which way or the other .
Jesus4Lyf's a good idea for maintainability and for speed if you end up having a million else ifs.
I don't believe a switch statement would merit any benefit whatsoever to the JASS language ;D.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|