Would it be ridiculous to use a switch statement to handle irc server codes?

There are quite [a few of IRC server codes][1] I am working on a small [IRC client for Adobe AIR][2], 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]: http://www.mirc.net/raws/#001 [2]: http://www.apphackers.com

以上就是Would it be ridiculous to use a switch statement to handle irc server codes?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏