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


there is plenty

I'm working a little bit, and only a few people support Started by these initially, and then a switch statement did not seem like a bad idea. But as much as I support more, the switch statement is getting more and it seems that it is out of control. One issue is that I have placed low level IRC handling code in a file so that it can be reused. I would like to put everything in a file. Another issue is that code blocks in the switch statements currently consider part of this IRC class and this statement is often used. Changing now will be a lot of work and start regression. The only problem is actually my rudeness for a long switch statement, otherwise you know that it works, and it is easy to read, but it is not really making it difficult to maintain but it is such a long switch statement. And this ceremony includes a switch statement, obviously, it is too long. : //

Once I make a switch for a switch, I define the actions that have been named after the value of the switch evaluation. Instead of switch:

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

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

  obj.alert = function () { Alert ("yo"); } If (obj & amp; vjana (obj [val])) [obj [val] (); }  

But again in this case I have felt that there is a high risk in regressions and I am not sure that it is worth the effort to avoid getting a statement of statement that you have a hash (A javascript is not {}

object) As with work? Then, you can use an anonymous function for a small piece of code, and for larger pieces of code, you may have a reference to previously written work. I do not know anything about IRC, but here is a small example:
  var codehash = {001: function () {/ * something ... *}, 002: Big Imperent Object Some Functions}  

Like a bad example, but you get this idea.


Edit: If you think that you keep this long switch statement easily and without problems, then I think That it is ridiculous to rewrite your code, so remove switch But I know that I, personally, expect to maintain a hash table as above from a huge switch statement for several reasons. It is up to you. It seems like a ridiculous question that if you continue to insist that you have the only reason to rewrite your code then get rid of the switch statement.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -