FANDOM


Forums: Index Help desk Is one template with a large Switch better than many templates with small switches?

TL;DR: Is it bad to have giant switch statements with hundreds of cases?  Up to maybe a couple thousand?  Should I split that template up into multiple templates or is there no benefit from doing that?



Longer explanation:

I manage the X-Wing Second Edition Wiki, and I'm using templates to return the cost for a given card in the game, so we can display it in infoboxes, data tables, etc.  These costs will be changing often, so instead of simply baking them into the pages themselves, I put them into templates so that we have a central location for all the costs.  When Fantasy Flight Games changes a bunch of costs, we can go to the templates to edit them (one place to make all the changes instead of having to scour the whole wiki), and all pages should update with that information.

Here's my question: We have literally hundreds of cards we're costing through these templates, and over time this will enter into a thousand or thousands.  Is there an efficiency disadvantage if I put everything in a single template, in one giant switch statement?  Or is it better to split by card type (ship type and upgrade type, in this case) so I have around ~60 templates listing costs, and a couple of main templates that switch on the type and call into those child templates?

In other words, I could make one template with hundreds/thousands of entries in one switch statement, or I could split that into lots of templates that break up the work into switch statements of a couple dozen cases at most.  Is there any advantage to either method?



I don't know how clear I'm being, so perhaps an example would help.  We have 45 ship types right now, like the X-Wing, B-wing, TIE Interceptor, Aggressor, etc.  Each of those ships has ~3 to 12 pilots.  I could create one template that lists all pilots (excuse the sloppy pseudo-code; I don't want to put real code in here, and I just want to get the idea across):

Template:Pilot Cost (pilot_name)

switch(param 1)

-Luke Skywalker|Luke=50

-Biggs Darklighter=44

-Ten Numb=50

-Sigma Squadron Pilot=22

(and so on, for hundreds of pilots)



Or I could have one main template that switches on ship type (taking params ship_type and pilot_name), and calls into another template for that specific ship:

Template: Ship Cost (ship_type, pilot_name)

switch(ship_type)

-X-Wing=call template pilot_cost_x-wing(param 2)

-TIE Interceptor=call template pilot_cost_TIE_Interceptor(param 2)

...etc for all 45 ships



And I create ~45 child templates, one for each ship type, e.g.

Template: pilot_cost_x-wing (pilot_name)

switch(pilot_name)

-Luke Skywalker|Luke=50

-Biggs Darklighter=44



Summary: Is there any efficiency advantage to either method?  Or should I simply do whatever's more useful for us admins when we need to update data when the game's point costs change?

Thank you!

Wazat (talk) 18:14, July 30, 2018 (UTC)

What ever combination uses the least number of switch calls on a page. I think with caching, the size of the switch is not as important as how many times you use a switch. -- Fandyllic (talk · contr) 22 Aug 2018 3:18 PM Pacific