Combining Code

This is a big one. For me, at least.

I have several different drawing methods that each perform similarly, to the point that the code is nearly redundant. The problem is that they have enough differences that combining them into one big honking draw method would either require lots of counter-productive if/else statements or a bajillion parameters. I tried the bajillion parameters way and stuff broke and I chickened out and restored everything from backups.

So my questions are:

1. Is combining the methods into one even necessary/advantageous? Will it be faster to keep them separate, especially if they're called simultaneously?

2. I tried using a table to store the values of the parameters of each object that could be drawn so that each method call would look like

 draw(table)

instead of

 draw(x, y, rotation, scale, label, list, index, ...)

That didn't work. What is the proper way to pass a table in as a series of parameters?

3. Is there a better way to do this that I just completely missed the bus on? If so, tell me, oh wise one.

Why just not create you own "draw" function which use table/object elementh as param???

Could you kindly elaborate?

Lets look at this logically:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function a()
    do
    a
    bunch
    of
    stuff
    unique for a
    do 
    a 
    bunch
    of
    repeat
    code
end
 
function b()
    do
    a
    bunch
    of
    stuff
    unique for b
    do 
    a 
    bunch
    of
    repeat
    code
end
 
if some condition then
    a()
else
    b()
end

That makes sense.

Now let's say the unique elements are such that I still require the use of a long string of parameters to facilitate a combined draw function.

How do I pass a long-donkey stream of parameters without naming them every time I call the method?

Also, that technically didn't answer my question. I asked if it was faster, not more efficient. From what I could tell with my earlier attempts at combining, calling the same function with different parameters four times sequentially is slower than calling four different methods simultaneously.

views:1318 update:2011/10/26 17:27:57
corona forums © 2003-2011