Re: How to redesign big switch case?
From: Jeff Schwab (jeffplus_at_comcast.net)
Date: 03/22/04
- Next message: Jeff Schwab: "Re: Multiple Inheritance. What good is it?"
- Previous message: Pete: "Re: mem_fun doesn't work for virtual members?"
- In reply to: Siemel Naran: "How to redesign big switch case?"
- Next in thread: Razvan Popovici: "Re: How to redesign big switch case?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Mar 2004 09:04:13 -0500
Siemel Naran wrote:
> How to redesign big switch case?
>
> I wrote an editor that reads chars, and does a switch (char) to process the
> character. For example, if char is HOME then go to the beginning of the
> line, and if char is CTRL-RIGHT then go to the start of the next word. As I
> added more cases and support for reverse incremental history mode, the code
> grew longer and longer. It is now 562 lines, or 58% of the entire file.
> This seems a bit clumsy. Fortunately the code does not have any goto
> statements and seems pretty structured and clear to me, so it's not exactly
> sphaghetti code. Is it worthwhile to change the code? If yes, then how?
> Finally, it would be nice to allow users to derive their own editor class
> from my one and add support for more special keys.
How about an array with 256 elements, each of which points to the
appropriate behavior for the given value of the char?
- Next message: Jeff Schwab: "Re: Multiple Inheritance. What good is it?"
- Previous message: Pete: "Re: mem_fun doesn't work for virtual members?"
- In reply to: Siemel Naran: "How to redesign big switch case?"
- Next in thread: Razvan Popovici: "Re: How to redesign big switch case?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|