Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 272249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:17:12+00:00 2026-05-12T00:17:12+00:00

There are quite a few of IRC server codes I am working on a

  • 0

There are quite a few of IRC server codes

I am working on a small IRC client for Adobe AIR, and I started out by supporting only a few of these initially, and then a switch statement didn’t seem like a bad idea. But as I support more and more, the switch statement is getting longer and it feels like it’s a little out of control. One issue is that I’ve kept the low level IRC handling code in a file on its own so that it can be reused. I would like to keep everything in one file. Another issue is that code blocks in the switch statements currently assume to be part of this IRC class and there’s frequent use of the this statement. Making changes now would be a lot of work and introduce regressions. The only problem really is my distaste for a long switch statement, otherwise you know it works, and it’s kind of easy to read, but not really making it more difficult to maintain. But it’s such a long switch statement. And the function that contains the switch statement is obviously long too. ://

One thing I sometimes do in lieu of a switch is that I define functions that are named after the value the switch evaluates. Instead of a switch:

switch ( val ) {
  case: "alert":
    alert( "yo" );
    break;
}

I check to see if a method exists in scope and execute it:

obj.alert = function ( ) {
  alert( "yo" );
}

if ( val in obj && isFunction( obj[ val ] ) ) { 
  obj[ val ]( );
}

But again in this case I’ve feel like there’s a high risk in regressions and I’m not sure it’s worth the effort only to avoid having a long switch statement, for the sake of its length.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:17:13+00:00Added an answer on May 12, 2026 at 12:17 am

    Why don’t you keep a hash (a JavaScript {} object) with the code as the key and the function as the value? Then, for small pieces of code you could use an anonymous function, and for bigger pieces of code you could just have a reference to an already written function. I don’t know anything about IRC, but here’s a small example:

    var CodeHash = {
        001: function() { /* Do something... */ },
        002: BigImportantObject.someFunction
    }
    

    Kind of a bad example, but you get the idea.


    Edit: If you believe that you can maintain such a long switch statement easily and without problems, then I think it’s ridiculous to rewrite your program just to remove the switch. But I know that I, personally, would much rather maintain a hash table like above than a huge switch statement, for many reasons. So it’s up to you. Seems like a rhetorical question if you keep insisting that the only reason you’d rewrite your code is to get rid of the switch statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are quite a few tools out there to debug JavaScript and CSS. Firebug,
I know that there are quite a few different topics out there but I
Disclaimer: I know there are quite a few questions out there with this topic
We’re working on a large project using Git and there’s quite a few development
Currently there are quite a few DI/IoC-frameworks for .NET out there ( http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx ).
I know there are quite a few text-to-array questions out there, but I am
I know there are quite a few postings out there concerning this very issue,
I'm monitoring some server logs and there are quite a few NullPointerExceptions . The
There's quite a few solid tutorials out there, and I haven't had too much
I know there are quite a few libraries out there that that allow Twitter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.