Re: [Q] big function vs many small functions



On Tue, 25 Sep 2007 15:34:38 +0100
Steve O'Hara-Smith <steveo@xxxxxxxxxx> wrote:

On Tue, 25 Sep 2007 12:30:06 GMT
tekenen@xxxxxxxxxxx (t.j.) wrote:



Let's say that one has a function with a large switch statement with
many case statements.

One way of writing the function is to just place all of the code for
each case inside of the function containing the switch statement.

Another would be to have an individual function for each case statement.

Which way is better in terms of maintainability and frequency of bugs?

If you can get the switch down to readable size using an
individual function for each case that will help. OTOH if you cannot then
it is probab

ye gods what happened to that :(

I was about to say that it is probably better to redesign the
program to avoid the big switch.

--
C:>WIN | Directable Mirror Arrays
The computer obeys and wins. | A better way to focus the sun
You lose and Bill collects. | licences available see
| http://www.sohara.org/
.



Relevant Pages

  • Re: [Q] big function vs many small functions
    ... each case inside of the function containing the switch statement. ... Another would be to have an individual function for each case statement. ... I recall reading something where someone actually studied this situation ... and determined there was no meaningful difference between the two. ...
    (comp.programming)
  • Re: Roles question
    ... account for that, and a switch statement won't handle that. ... >I am writing an application using the ASP.NET Configuration Roles and ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: overloading methods
    ... I don't know how you can avoid ... at least one switch statement that looks up the message number and ... selects the appropriate parser for that message type. ... number/string and gives you a .class object from which you can do a ...
    (comp.lang.java.programmer)
  • Re: Which of switch statement and if-else statement takes less time to execute?
    ... > Which of switch statement and if-else statement takes less time to ... thing, the performance difference, if any, will not be consistent from ... use an if-else chain for everything else. ... For example, writing ...
    (comp.lang.c)
  • Re: Sort of Gray code to binary converter
    ... Binary tree, table, hash, etc. ... If a large enough switch statement where an 8 bit switch argument ... Writing it in if/else form, ... cleverness, if any, has to come from the compiler if you depend on the ...
    (sci.electronics.design)